Waiting for CNT to be equal OR LARGER than a value
jac_goudsmit
Posts: 418
Hi everyone,
I'm working on a project that lets a Propeller bitbang the pins of a 6502 processor, including the clock input (see this page for more info).
The main loop of my Propeller code has to do its work within the 1 microsecond that it takes for the 6502 processor to execute a clock pulse, so timing is very tight. Obviously this part of the project is written in Assembly.
During normal operation, I can use a WAITCNT:
For the 6502 this is no big deal: it can run much slower than the usual 1MHz (as a matter of fact I'm running it at 10Hz for debugging), but if I use WAITCNT, I'll have to wait until the counter comes around to the same value again (50 seconds?). This is unacceptable. I also can't use a timer because that allows the 6502 to "run away" from the Propeller.
So, what I need is basically some assembly code that waits for an amount of time since the previous event, or continues right away if that minimum time has already passed. Is there an easy solution to do this, e.g. by using a WAITVID (obviously with the video pin mask set to 0)?
Unless there's no other way, the following is what I don't want to do:
===Jac
I'm working on a project that lets a Propeller bitbang the pins of a 6502 processor, including the clock input (see this page for more info).
The main loop of my Propeller code has to do its work within the 1 microsecond that it takes for the 6502 processor to execute a clock pulse, so timing is very tight. Obviously this part of the project is written in Assembly.
During normal operation, I can use a WAITCNT:
MainLoop ... ' Do stuff for the first part of the clock pulse waitcnt clock, count ' Wait until enough time passes or OUTA, mask_CLK0 ' Set the clock output ... ' Do stuff for the second part of the clock pulse waitcnt clock, count ' Wait until enough time passes andn OUTA, mask_CLK0 ' Reset the clock output jmp #MainLoopAs long as the Propeller can get its work done within the time limit, this works fine. But during certain special operations, I have to access the hub and perhaps later on even an SD card reader or serial port. So, I'm running into the possibility that my Propeller code is not done when it's already time to flip the clock output.
For the 6502 this is no big deal: it can run much slower than the usual 1MHz (as a matter of fact I'm running it at 10Hz for debugging), but if I use WAITCNT, I'll have to wait until the counter comes around to the same value again (50 seconds?). This is unacceptable. I also can't use a timer because that allows the 6502 to "run away" from the Propeller.
So, what I need is basically some assembly code that waits for an amount of time since the previous event, or continues right away if that minimum time has already passed. Is there an easy solution to do this, e.g. by using a WAITVID (obviously with the video pin mask set to 0)?
Unless there's no other way, the following is what I don't want to do:
MainLoop mov t1, CNT ' Store current time ... ' Do stuff for the first part of the clock pulse :loop1 mov t2, CNT ' Store current time sub t2, t1 ' Time difference in t2; Subtracting eliminates chance that t2 < t1 cmp t2, count wc if_nc jmp #:loop1 or OUTA, mask_CLK0 ' Set the clock output ... ' Do stuff for the second part of the clock pulse :loop2 mov t2, CNT ' Store current time sub t2, t1 ' Time difference in t2; Subtracting eliminates chance that t2 < t1 cmp t2, count_times_two wc if_nc jmp #:loop2 andn OUTA, mask_CLK0 ' Reset the clock output jmp #MainLoopThanks in advance for any suggestions!
===Jac
Comments
===Jac