Code not working - new Cog
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.
CON scan_pin = 1 LED4 = 16 VAR long stack[40] PUB null cognew(input(5), @stack[0]) ' start generator (fake) cognew(catch, @stack[20]) ' start pulse counter PRI input(pulsecount) : delay dira[scan_pin]~~ ' set pin to output delay := clkfreq/pulsecount/2 ' delay between edges repeat !outa[scan_pin] ' toggle pin waitcnt(delay + cnt) ' pulse delay PRI catch : count dira[LED4]~~ ' set LED pin to output ctra := constant(%0_01110_000 << 23 | scan_pin) ' NEGEDGE frqa := 1 ' +1 for each HL edge repeat phsa~ ' clear accumulator waitcnt(clkfreq + cnt) ' wait a second count := phsa ' get edge count if 3 < count and count < 7 ' | toggle LED if !outa[LED4] ' | between 3 and 7 DAT org 0 ' pin validation res (scan_pin|LED4) >> 5 <# 1 fit 0thank you very much for your help !!!