WAITPEQ returns unexpectedly
trevorms
Posts: 7
I have an application which instantiates a state machine (SPIN code) into two different COGs. At one point the following line of code is called in COG 1:
waitpeq(0, |< awake_in[unit_instance], 0)
In this case unit_instance=0, awake_in[unit_instance] = 9.
This function returns unexpectedly when COG 2 executes this code:
outa[relay[unit_instance]]~~
outa[ign[unit_instance]]~
In this case unit_instance= 1, relay[unit_instance] = 5 and ign[unit_instance] = 7.
The awake_in input is pulled high with a 10k resistor and I confirmed with an oscilloscope that it does not change state either.
To work around this problem I call this code after the WAITPEQ function:
waitpeq(0, |< awake_in[unit_instance], 0)
delay(1) ' Wait 1 second
awake_state := ina[awake_in[unit_instance]]
if awake_state == 0
unit_state[unit_instance] := STATE_WAIT_TIMEOUT
In this case awake_state is 1.
It seems that WAITPEQ when waiting on one COG can return if another COG writes to its output pin registers.
Has anyone else experienced this problem or is there something wrong that I am doing?
I have attached the full spin code for my application. It depends on VGA_Text which can be found in the object exchange.
Cheers,
T.
waitpeq(0, |< awake_in[unit_instance], 0)
In this case unit_instance=0, awake_in[unit_instance] = 9.
This function returns unexpectedly when COG 2 executes this code:
outa[relay[unit_instance]]~~
outa[ign[unit_instance]]~
In this case unit_instance= 1, relay[unit_instance] = 5 and ign[unit_instance] = 7.
The awake_in input is pulled high with a 10k resistor and I confirmed with an oscilloscope that it does not change state either.
To work around this problem I call this code after the WAITPEQ function:
waitpeq(0, |< awake_in[unit_instance], 0)
delay(1) ' Wait 1 second
awake_state := ina[awake_in[unit_instance]]
if awake_state == 0
unit_state[unit_instance] := STATE_WAIT_TIMEOUT
In this case awake_state is 1.
It seems that WAITPEQ when waiting on one COG can return if another COG writes to its output pin registers.
Has anyone else experienced this problem or is there something wrong that I am doing?
I have attached the full spin code for my application. It depends on VGA_Text which can be found in the object exchange.
Cheers,
T.
Comments
Is this as you intended it to be, seems either your comment is wrong or the use of ~~ should be ~?
dira[relay[unit_instance]]~~ 'Set relay pin to output
outa[relay[unit_instance]]~ 'Make relay output low
dira[ign[unit_instance]]~~ 'Set ignition pin to output
outa[ign[unit_instance]]~~ '<<<<<Make ignition output low
The relay outputs are active high while the ign outputs are active low.
waitpxx is very sensitive, a single clock pulse is enough to trigger it (e.g. 12.5ns @80MHz). How is the signal on this input pin generated?
For the sake of it, can you connect an edge counter to the pin in question and monitor phsx just before and after the offending code sequence?
Please use a cog internal counter, it sees what waitpxx sees.
Hope this makes sense.