Count 16 external clock cycles and waitpeq style interrupt
TransistorToaster
Posts: 149
Hello,
I was wondering if there is an efficient way to make a prop count pause until 16 external clock cycles are counted. I know it's easy with an external counter, but I'd like to do it purely in software.
I thought about writing several waits with the state alternating 0 and 1 16 times.
Other ideas?
Thanks,
Frank
I was wondering if there is an efficient way to make a prop count pause until 16 external clock cycles are counted. I know it's easy with an external counter, but I'd like to do it purely in software.
I thought about writing several waits with the state alternating 0 and 1 16 times.
Other ideas?
Thanks,
Frank
Comments
Or use the hardware counter in edge detect mode, set frqa as 1 and wait unil phsa is 16.
Graham
Post Edited (TransistorToaster) : 6/10/2007 3:48:38 PM GMT
Do you want to use the divided clock or just output it again?
Graham
something like (in pseudo code)
WAITPEQ 'sync to the incoming pulses
temp = CNT
temp = temp + 16*6 - 4 'the minus 4 compensates for the time spent sampling CNT
WAITCNT(temp)
'it's now 16 cycles later
'so do stuff
Marty
TT,
Assembly is fast enough and it provides quite a bit of time to process between clocks. Using waitcnts is possible but that ties up an entire cog just to doing the divide, it can't do anything else.
Using a counter is good because you can do the compare, then reset it and do some processing and then come back to check it again, just make sure the processing fits in the time frame.
I don't actually know if spin is fast enough even using the counters, I have no feel for its speed.
Graham
I have not tried this, so I'm only speculating.
You want to delay action of a cogg by 16 (or 16*16?) clock ticks seen by cog, right?
One assembler 'wait' ·command : NOP taks 4 clock ticks.
Would be enough to write an assemble code with 4·NOP instructions.
If you need dealy of 256 ticks, a loop in assembler should work.
On command in SPIN 'costs' 100-200 colck ticks·- probably it is hard·to get such short delay in SPIN.
If you·choose to assembler you need to 'sacrifce' the whole cog, since it can't run spin·& assebler code simultanously
Jan
Graham