Loop not repeating correct number of times, help?
dayoade
Posts: 13
in Propeller 1
Hello everyone,
I'm trying to fire a light five times. I thought this loop would do that but it only fires twice. Does anyone have any ideas why?
I'm trying to fire a light five times. I thought this loop would do that but it only fires twice. Does anyone have any ideas why?
org 0 start or dira, light andn outa, light mov Count,#5 loop or outa, Pin 'toggle light on andn outa, Pin ' toggle light off djnz Count, #loop
Comments
Also, your loop will complete in microseconds. Are you using a scope to count the pulses?
Finally, there's nothing at the end to keep any random code that was loaded with yours from executing. You should either include an instruction that jumps to itself, or a cogstop to kill the cog.
-Phil
Where's your delay?
Where's "Count"?
Where's the rest of the code?
Why would you code this in PASM anyway?
-Phil
If you have a Scope, and an almost-working system, you likely just need some fault analysis...
Change the #5 and see if the pulses change ?
Are the pulses you do get, of expected width & spacing ?
If you add another pin that sets just before the loop, and clears after DJNZ, what time does that take ?
[/quote]
BlinkCounter seems not declared, or loaded anywhere, whilst Counter is loaded but not used ?
If you have a Scope, and an almost-working system, you likely just need some fault analysis...
Change the #5 and see if the pulses change ?
Are the pulses you do get, of expected width & spacing ?
If you add another pin that sets just before the loop, and clears after DJNZ, what time does that take ?
[/quote]
Sorry it was supposed to be counter, if i change the amount of pulses, the firings are still coming up short of the number I want.
Ok that's a start, but short of you likely just need some fault analysis...
Tabulate the Count, and what you see. Is it always -3 ?
Did you add a start-end pin ?
If you trigger on that, what do you now see ?
How sure are you that the assembly routine is even being loaded into a cog?
I'm getting two pulses instead of five. Is that what you mean by -3? And what do you mean by start-end pin?
Also, please post the entire program, including the Spin code that starts the PASM cog.
-Phil
If you are fixed on 2, then that tells you what you change and think is the counter, is not the real counter.
See above, this is a pin you set at the code before the loop, and clear after the loop completes.
This should pulse once, and give a scope trigger to see all the other pulses.
yes, or, you could toggle the pin, and use just one delay. The scope toggles should match the loop counter.
It is possible the scope has a trigger offset issue, so another separate way to check counting would help.
Go back through starting with the top object and remove any code messing with any I/O that is not controlled by that cog (reading is not a problem, no mater how configured IIRC, all cogs can "see" the state of a pin at any time) do the same for all other cogs you are running. This one has gotten me a couple of times.
You still haven't posted the whole code. If we cannot recreate the issue, we can't do better than stare at the code you have
provided, which isn't where the problem is I suspect.
The djnz instruction works, trust me on that...
Yes, as usual posting the whole program allows the real issue to be quickly identified.
I always get a number less than the amount of pulses I set it for, but never the same amount. For example, if i set it to five, i would get three on the first, two on the second run, four on the third run.
How: Post your entire program -- not just the fragment that you think is problematic. Clearly, there is an issue beyond that else this would have been solved by now. I wrote a program in a couple minutes that worked exactly as you specify. Did you plug that fragment into your framework to see if it worked for you as it did for me?
Again... help us help you. Archive your program and attach it to a message.
Jon, can I amend the Jerry Maguire phrase to "no help us, no help yourself, no help at all"
It looks like you're reading three bytes from a UM245R USB to parallel FIFO module.
The 1st byte seems to be a command to either toggle a light on/off, set a new level, or blink a number of times.
The 2nd and 3rd bytes form a 16-bit word representing the light level or number of times to blink.
I suspect, as Frank Freedman said, that your Spin code and Pasm code are colliding. You start the Pasm code which sets each output high for 1/2 second, and moves on to the next after 1/4 second. While that is going on, your Spin code continues to read the UM245R, and if datin[0] equals 3, 5, 7, or 9 then the Spin code toggles one of the pins to output a high, which the Pasm code running in another cog is then unable to set low. If datin[0] ever equals 10, then your Spin code waits forever.
Remember: A pin is an output if any cog sets it to be an output; a pin is high if any cog that has it set to output also has it set high.
Simplest solution if you just want to see the pins toggle is to comment out everything underneath the cognew, or ensure some other way that the Spin code doesn't interfere with those pins.
Here's a cleaner, simple, version of your code (untested):
Thanks for your help. I posted the full code on the 14th, I didn't know how to archive the program and attach it to a message, so I just posted it in code tags. I was able to figure it out and the solution is below.
Although, the pins are being shared on Spin and assembly, I am only firing the pins in assembly. The Spin code was there for troubleshooting. I didn't think it was a conflict between PASM and Spin because I imagine that issue would look like a value stays high for too long (LED stays on for multiple cycles), so if this were the issue, I would expect to have seen high values that stayed high for longer than the intended duration, not values heading low prematurely. Great idea though that really got me thinking!
I was able to fix the problem. The PASM was firing zero voltage pulses before the non-zero voltage values were set from the external source. I feel foolish for not noticing this sooner. The decrementing variable was working correctly. To fix this, I placed the cognew command after all the light levels were set. Thank you all again for your help.
Wow, Chris. I really appreciate the effort you put in. I was able to solve the problem (see above). Although, now I want to test your code to just to see if it works. Thanks again for your help and I'll update you a bit later.