Code not working - new Cog
guili_23
Posts: 11
Hi,
i was wondering if someone can help with this:
With Floppy_Giro_Ini I call a new Cog. This new Cog calls to Floppy_Giro.
Floppy_Giro has to Count between 3 and 7 times the variation of an input signal (Port one) in one second (and Toggle a led) and repeat the process. This Cog is supposed to do this all the time.
But it is not working.
Anyone ?
Thanks in advance
i was wondering if someone can help with this:
PUB Floppy_Giro_Ini Cog := (cognew(Floppy_Giro, @Stack) + 1) PUB Floppy_Giro | Contador,Time_aux if Cog > 0 repeat Time_aux := cnt + clkfreq Contador := 0 repeat waitpeq(%10,%10,0) waitpeq(%00,%10,0) Contador := Contador + 1 while Time_aux - cnt > 0 if 3 < Contador < 7 !outa[LED4]
With Floppy_Giro_Ini I call a new Cog. This new Cog calls to Floppy_Giro.
Floppy_Giro has to Count between 3 and 7 times the variation of an input signal (Port one) in one second (and Toggle a led) and repeat the process. This Cog is supposed to do this all the time.
But it is not working.
Anyone ?
Thanks in advance
Comments
There may be other (timing related) issues.
As for counting edges, you'd be better off using an edge counter. Reset it (to 0), wait a second, read the result. The way it's now waitpeq may block for an arbitrary amount of time (> 1 sec) if its condition isn't met.
Also, the expression 3 < Contador < 7 will always evaluate to TRUE. First 3 < Contador is evaluated which is either 0 (FALSE) or -1 (TRUE) both of which are less than 7. So you should use something like
A working example. It generates a square wave signal on pin 1 (scan_pin), the parameter to input() is the frequency in Hz. This is only for testing purposes as I don't have an external pulse generator. The second cog runs function catch which intialises a counter to simplify counting of negative edges. Then it sits there and updates LED4 every second.
thank you very much for your help !!!