pin in/out at top speed
TCP71
Posts: 38
Once again, please forgive my ignorance.
I am trying to test an input pin for a specific state and then toggle another pin as quickly as possible once the state has been reached. What is the fastest method to have this happen. It seems that waitpeq in spin code, followed by an "outa" instruction seems to take almost 9uS to occur. This is probably completely simple to do in assembly, but I'm the furthest thing from a programmer you can imagine. Any (simple?) ideas would be appreciated.
I am trying to test an input pin for a specific state and then toggle another pin as quickly as possible once the state has been reached. What is the fastest method to have this happen. It seems that waitpeq in spin code, followed by an "outa" instruction seems to take almost 9uS to occur. This is probably completely simple to do in assembly, but I'm the furthest thing from a programmer you can imagine. Any (simple?) ideas would be appreciated.
Comments
I wonder if you can set up the counter in spin, in a set and forget?
I'm not sure, as I'm a assembler dude.
Logic modes of operation
Modes %10000 through %11111 operate differently that the other modes of operation.
In these Logic modes, APIN and BPIN are inputs into the counter which dictate when
the FRQA register is added into the PHSA register.
Only when the logic equation specified by the mode is true is the FRQA
register added to the PHSA register.
The %10000 (LOGIC never) mode is equivalent to mode
%00000 (Counter off), since the FRQA register is never added to the PHSA register.
The %11111 (LOGIC always) mode is similar to the system clock in that the FRQA
register is added to PHSA register every cycle.
The remaining modes accumulate when the mode’s logic equation evaluates as
true. These modes operate on buffered inputs, so the values present at the APIN
and BPIN of the previous clock cycle are used in the equation for the present clock cycle.
Set one counter to your desired "toggle ... as quickly as possible" ... this can be up to 125MHz
Set another counter pointing to the same output pin as a 'POS detector with feedback' or 'NEG detector with feedback' depending on the pin state you want to look for. ... <-- you could do this using the ina and dira but the time required to execute ina and dira in SPIN would defeat the purpose. The way that the dir and out registers are OR'd ... 'POS detector with feedback' is the proper way to do this.
You might look at this attached info on counters.