20x2 - Is there a faster way of setting an output high in response to a high input

smeagol

Member
I've been doing some timings on a 20X2 running at 64MHz

I want to get the fastest, reliable, response to a high input setting an output high.

I've been testing using a switch as an input and timing how quickly the Output will go high in response to a switch press. All timings done using a DPScopeII

So Far I've tried a Do, Loop, While:

Code:
[color=Blue]let [/color][color=Purple]dirsb [/color][color=DarkCyan]= [/color][color=Navy]%11111111               [/color][color=Green];Set Input or Output on B (All Outputs)[/color]
[color=Blue]let [/color][color=Purple]dirsc [/color][color=DarkCyan]= [/color][color=Navy]%10100001[/color]
[color=Blue]symbol Output1 [/color][color=DarkCyan]= [/color][color=Blue]b.3
symbol [/color][color=Purple]ButtonUp [/color][color=DarkCyan]= [/color][color=Purple]pinc.4[/color]
[color=Blue]symbol Output1On [/color][color=DarkCyan]= [/color][color=Navy]%00001000        [/color][color=Green];Output 1 on[/color]
[color=Blue]symbol AllOff [/color][color=DarkCyan]= [/color][color=Navy]%00000000           [/color][color=Green];All Outputs Off[/color]
[color=Blue]setfreq m64[/color]

[color=Black]main:
      [/color][color=Blue]do
            loop while [/color][color=Purple]Buttonup [/color][color=DarkCyan]<> [/color][color=Navy]1
      [/color][color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Blue]output1on
      let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Blue]alloff
goto [/color][color=Black]main[/color]
And an interrupt during a Pause:

Code:
[color=Blue]let [/color][color=Purple]dirsb [/color][color=DarkCyan]= [/color][color=Navy]%11111111               [/color][color=Green];Set Input or Output on B (All Outputs)[/color]
[color=Blue]let [/color][color=Purple]dirsc [/color][color=DarkCyan]= [/color][color=Navy]%10100001[/color]
[color=Blue]symbol Output1 [/color][color=DarkCyan]= [/color][color=Blue]b.3
symbol [/color][color=Purple]ButtonUp [/color][color=DarkCyan]= [/color][color=Purple]pinc.4[/color]
[color=Blue]symbol Output1On [/color][color=DarkCyan]= [/color][color=Navy]%00001000        [/color][color=Green];Output 1 on[/color]
[color=Blue]symbol AllOff [/color][color=DarkCyan]= [/color][color=Navy]%00000000           [/color][color=Green];All Outputs Off[/color]
[color=Blue]setfreq m64[/color]

[color=Black]main:
      [/color][color=Blue]setint [/color][color=Navy]%00010000[/color][color=Black], [/color][color=Navy]%00010000
      [/color][color=Blue]Pause [/color][color=Navy]2000
      [/color][color=Blue]goto [/color][color=Black]main[/color]

[color=Blue]interrupt:
      let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Blue]output1on
      let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Blue]alloff
return[/color]
The Do-Loop can respond in 70 microSeconds, but it is variable and can take upto 127 microSeconds. I am assuming that it depends where in the loop the program is when the contacts close that results in the variable response.

With the interrupt the timing is consistently 101 microSeconds. So consistent results but slightly slower.

I've run out of ideas for other ways to try so do the brains of the forum have any ideas of a faster way to set the output high? The Picaxe will not be doing any other tasks while waiting for the input. I know I can probably improve the response with a purely hardware solution but would like to incorporate multifunctions into a single unit.

I am also assuming that none of the other Picaxe will perform any faster, please correct me if I'm wrong.
 

premelec

Senior Member
Silly suggestion....[?!] OR the output with a diode connected input to the output [through another diode] - then the output will be set high immediately and held by the programmed setting 'eventually'.
 

Goeytex

Senior Member
Consider using the the SRLATCH and and Comparator(s).

If programmed correctly, the SRQ pin should go high < 1 us after the Comparator+ pin goes High. Suggest setting the Comparator reference to FVR 1.024 or 2,048.

See COMPSETUP, FVRSETUP and SRLATCH Commands
 

smeagol

Member
Consider using the the SRLATCH and and Comparator(s).

If programmed correctly, the SRQ pin should go high < 1 us after the Comparator+ pin goes High. Suggest setting the Comparator reference to FVR 1.024 or 2,048.

See COMPSETUP, FVRSETUP and SRLATCH Commands
That looks very interesting. I shall Have a play. Thanks Goeytex

@Premelec - interesting idea but I really want the Picaxe to do the work.
 

smeagol

Member
Wow, success. Thanks for the pointer Goeytex. :D I used the Hardware Interrupt rather than the comparator but it seems to work well. I will look at the comparator if the sensor I am making does not go high enough to trigger the Hardware interrupt.

Using pretrigger mode at it's fastest. 500 K Samples / Second there is no visible difference between I/P and O/P. So it works well on the scope next step testing it for real.

I used the following code: ( I hope I'm using it correctly )

Code:
[color=Blue]input b.0
output b.1

hintsetup [/color][color=Navy]%00000010     [/color][color=Green];set b.o as Hardware Inerrupt[/color]
[color=Blue]SRLatch [/color][color=Navy]%10001000[/color][color=Black], [/color][color=Navy]%10000000[/color]

[color=Black]Main:
      [/color][color=Blue]Srreset
      pause [/color][color=Navy]5000[/color]
[color=Blue]goto [/color][color=Black]main[/color]
 

techElder

Well-known member
Can you explain how you are using an interrupt without an Interrupt subroutine?

I must not understand something about your setup.
 

Pongo

Senior Member
I wondered about that too, but manual2 has the answer. Bit 7 is set in config2, the second config string for srlatch:

Code:
SRLatch %10001000, %10000000
and per the doc:

For 20X2 part:
Bit 7 = 1 HINT1 sets latch (see hintsetup)
 

smeagol

Member
The code itself was just used for timing purposes. I need an output high as fast as possible in response to an input.

The output is being controlled by the base pic, Picaxe basic is just used to set the hardware so I don't need to use picaxe basic to check if the condition is true, massive time saving.

My code sets up the Hint1 (B.0) as input hardware interrupt that sets SRQ (B.1) high as soon as it sees a high on Hint1 (B.0). That is what I was looking to do, I don't need any further Picaxe code to check B.0 for input. At the fastest a DPScope II can run on Pre-Trigger mode I can't see a real time difference between B.0 going high and B.1 going high in response.

What I can do now is add code to do stuff once the SRQ (B.1) goes high, that's the time critical part, as it will stay that way until a SRReset is issued. The additional code will not be as timing critical as the detection. I may not ever use an Interrupt routine, limited as you can only have one interrupt routine, I may be able to do everything in a normal subroutine, I can read the state of B.1 with OutpinsX.
 
Last edited:

hippy

Technical Support
Staff member
Why is it not possible to simply split the output from the base pic so it goes to what it already controls as well as being used as a simple input to the PICAXE ? There doesn't seem any need to pass the signal through the PICAXE.
 

smeagol

Member
Versatility really. The input is going to be used for a variety of sensors, and different output timing options. Only one of the options requires a really fast response.

Simplicity of the hardware design and for the easy changes that can be made with software only as I get more ideas. It's also really easy to get them timings of the outputs as accurate as I want with a Picaxe.
 

techElder

Well-known member
Thanks for the clarification, smeagol. I'd certainly like to see more as you start developing your code.
 
Top