delays in spin1
Damn! Spin on the Prop1 is slow executing. I just made a tight loop that was meant to count off microseconds but it failed dismally ... and it took me some time to believe it was due to processing speed.
pub waitus( us ) | ticks, interval interval := div33( clkfreq, 1_000_000 ) 'calc 1 us ticks := cnt 'start timing repeat us ticks += interval waitcnt( ticks )
On an 80 MHz sysclock, I had to change the interval calculation to 20 microsecond to allow enough time for the repeat loop to cycle. My lack of experience on the Prop1 showing up again.
Anyone have a solution for finer granularity than 20 us?
Comments
I suppose the answer is use the old
waitcnt( cnt + x)
Use flexspin
. Or waitcnt, as you suggested later.
Just calculate the amount of cycles ahead of time and then wait for that. At 80 MHz it takes a bit less than a minute to overflow the counter, so that should be fine.
Unrelatedly, if you want to get performance from P1 Spin, you kindof have to think inside its box. Your code there is a good example: you add a value to
ticks
and then use that value on the next line. Spin prefers when you write likewaitcnt(ticks+=interval)
Also, try flexspin's bytecode compiler. It will automagically save cycles and bytes everywhere.
Funnily, I'm using PropIDE on Linux because PropTool can't find a comport in Wine. I note PropIDE defaults to using bstc for compiling. It seems to have its own download facility ...
Coooool! Dug up proploader and changed to flexspin for compiling ... the div33() calculation time has now dropped from 4300 ticks odd to 816, so a x5 speed up ... and same for the loop time, needs about 4 us now.
I'm happier back using Kate text editor now anyway. PropIDE was annoying.
Basically identical timing to BST Compiler when using
--interp=rom
in Flexspin. I'm getting 3552 ticks for the div33() in both cases. Faster than I had thought for bstc.For reasons I forgot (and I don't think are relevant anymore),
--interp==rom
doesn't perform any IR optimizations by default. Enable-O1
manually. The gains over BSTC range from none to quite a bit. Note that BSTC is already faster than the Proptool compiler.Okay, yep, -O1 helped. Now 3408 ticks for the div33().