trying to relearn PASM
TreeLab
Posts: 138
Greetings All;
After several years away, I am trying to code a PASM routine to control a pulse. And with advancing age, I am having limited success.
The program is to output a pulse (pin 0) followed by a controlled delay. When this delay is hard-coded into a PASM variable (OffDuration) the program works as expected, all the time. WHen I try to have the PASM code rdlong the delay count from hub memory (variable dT), it gives sporadic pulses. I have tested to see if the OffDuration is zero and toggle Pin1 to show this : this works fine for hard-coded values, but when I rdlong the dT=zero from hub, it doesn't see it as zero, and Pin1 is unaffected.
If behaves badly even if I only do the rdlong once, before the repetition loop is entered, so I don't think the time to synch the cog is the issue.
Obviously I am missing something pretty basic here. I would very much appreciate any help that folks can provide.
Cheers!
After several years away, I am trying to code a PASM routine to control a pulse. And with advancing age, I am having limited success.
The program is to output a pulse (pin 0) followed by a controlled delay. When this delay is hard-coded into a PASM variable (OffDuration) the program works as expected, all the time. WHen I try to have the PASM code rdlong the delay count from hub memory (variable dT), it gives sporadic pulses. I have tested to see if the OffDuration is zero and toggle Pin1 to show this : this works fine for hard-coded values, but when I rdlong the dT=zero from hub, it doesn't see it as zero, and Pin1 is unaffected.
If behaves badly even if I only do the rdlong once, before the repetition loop is entered, so I don't think the time to synch the cog is the issue.
Obviously I am missing something pretty basic here. I would very much appreciate any help that folks can provide.
Cheers!
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Set to standard clock mode and frequency (80 MHz) VAR long dT pub start(ptr) cognew(@PulseEntry, @dT) pub Main dira~~ dT := 40*80 start(@dT) repeat dat org 0 PulseEntry mov temp, par rdlong OffDuration, temp ' read from hub the off time in clock cycles mov dira, dira__ ' set up the dira register :PulseLoop cmp OffDuration, #0 wz ' set the Z flag if off-time=0 if_z mov outa, #2 ' DEBUG : use pin 1 as an indicator of the z flag if_nz mov outa, #1 ' set the pin high if the off-time is >0 mov Time, cnt add Time, OnDuration if_nz waitcnt Time, #0 ' only delay if the pin was set high (ie off-time>0) mov outa, #0 ' set the pin low, regardless mov Time, cnt add Time, OffDuration ' rdlong OffDuration, temp ' get value of off-time to be used for next cycle if_nz waitcnt Time, #0 ' do the wait iff the off time was >0 jmp #:PulseLoop temp long 0 OffDuration long 80*90 OnDuration long 80*10 Time long 0 zero long 0 dira__ long |< 0 + |<1 ' pin 0 is the one to use, pin 1 is for debug tracking of Z flag
Comments
-Phil
I'm pretty sure you have to put {pub start} after {pub Main}, as the code will go in order and run pub start first and then main will run it again.
And you passing along a prt in start, but are not using it so change it to:
pub start(ptr)
cognew(@PulseEntry, ptr)
It's not the loss of memory that gets you, it is the not-knowing that you have forgotten ...
Thanks again!