Something's wrong ... and it's driving me crazy
tmaynard
Posts: 27
Here's a simple, little LED blinker. I've been over it a million times, I've tweaked it a thousand ways, but it flat doesn't work:
It's supposed to blink at 1 Hz, with a 25% duty cycle. The behavior is just as if the second WAITCNT missed its "window". I get one quick flash, and then the LED stays on *forever* (well, you know how long), and then a quick flash, etc. I have tried:
Tom.
[noparse][[/noparse]Edited to add that it works just fine if either WAITCNT is commented out, only when both are active does the problem appear.]
org 0 entry or dira, Pin ' Select P4 for output (1) andn outa, Pin ' Set P4 low (0) mov OnTime, OnDelay ' Set up delays on/off add OnTime, cnt mov OffTime, OffDelay add OffTime, cnt :loop xor outa, Pin ' Toggle pin waitcnt OnTime, OnDelay ' Pause 1/4 sec xor outa, Pin ' Toggle pin waitcnt OffTime, OffDelay ' Pause 3/4 sec jmp #:loop Pin long |< 4 OnDelay long 80_000_000 / 4 OffDelay long (80_000_000 / 4) * 3 OnTime res 1 OffTime res 1 fit
It's supposed to blink at 1 Hz, with a 25% duty cycle. The behavior is just as if the second WAITCNT missed its "window". I get one quick flash, and then the LED stays on *forever* (well, you know how long), and then a quick flash, etc. I have tried:
- Using the same initial value of CNT for both waits
- Using a small immediate value (#24) instead of Delay on the first go
- Using hard-coded Delays (20_ and 60_000_000)
- Reordering the MOV/ADD
- Grouping the MOV/ADD
- etc.
Tom.
[noparse][[/noparse]Edited to add that it works just fine if either WAITCNT is commented out, only when both are active does the problem appear.]
Comments
needs to be:
waitcnt OnTime, OffDelay ' Pause 3/4 sec
As waitcnt adds ondelay to the OnTime varible during the wait .
As you use a new varible that is set to zero, it would take 58sec for the counter to roll over
Do this instead:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Harprit
You then want the WAITCNTs to move ahead 1 second each time through the loop like:
That's true, but I'm adding dozens of millions of Delay cycle time, too. I was sure that I was missing the "window" -- but I just don't see how.
I'll try all suggestions and report back.
Thanks!
TonyP12 and Kye's suggestions really amount to the same thing, and I get one quick flash (1/4 sec), and then a steady stream of 3/4 sec flashes.
Mike's idea produces a series of 1/4 second flashes only. Not exactly what I'm looking for.
I want the LED to be ON for 1/4 second, and OFF for 3/4 second. Like so, from the PE Kit book:
Tom.
-Jack
Thanks to one and all for your suggestions.