pasm question
mikea
Posts: 283
I'm trying to ramp down a led as a pasm lesson, but can't seem to get it right. I've been copying examples from the manual and slightly changing them. I have a couple questions...
is... "delay long 0" near the bottom considered an unchangeable constant or is it just the starting point and will change if added to? If the "0" is left off is it assumed as a starting point and delay is more like a variable. The main problem here is i'm trying to increment delay with a limit of 80_000_000, so the rate of toggle slows to one second on one second off. Seems pretty straightforward, but it's not working.Any advice would be appreciated
is... "delay long 0" near the bottom considered an unchangeable constant or is it just the starting point and will change if added to? If the "0" is left off is it assumed as a starting point and delay is more like a variable. The main problem here is i'm trying to increment delay with a limit of 80_000_000, so the rate of toggle slows to one second on one second off. Seems pretty straightforward, but it's not working.Any advice would be appreciated
{{ AssemblyToggle.spin }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB Main {Launch cog to toggle P16 endlessly} cognew(@Toggle, 0) 'Launch new cog DAT {Toggle P16} org 0 'Begin at Cog RAM addr 0 Toggle mov dira, Pin 'Set Pin to output mov Time, cnt 'Calculate delay time :loop waitcnt time, Delay 'Wait xor outa, Pin 'Toggle Pin max Delay, #apex 'limit delay value to 80_000_000 add Delay, #1 'increment delay value jmp #:loop 'Loop endlessly Pin long |< 16 'Pin number Delay long 0 'Clock cycles to delay apex long 80_000_000 Time res 1 'System Counter Workspace
Comments
would add delay to time and in the next Loop wait for that counter-value. But adding 0 means that you already missed the counter-value and that you have to wait for ~50 seconds until the counter passes the value again.
So, in your code you also have a minimum delay which makes the code run as expected (not missing the counter value). This minimum value also depends on the runtime of instructions after the waitcnt,
Delay is a variable which is initialized to be 0, but you can change it anywhere in your code!
The waitcnt instruction behaves like a wait, then an add.