Is is possible that the constants used for the delay calculations are incorrect?
I think the steps for each of the different loop types should be 3, 770, 197122 and 50463234, not 3, 770, 196355 and 50070530.
Sorry for a so late answer, I forgot monitoring the forum ;-)
As I'm not the primary author, I never check if formula were right.
Why do you think its are wrong?
Do you made some simulation or calculation?
I'll check the formula quickly.
I ran the code in the MPLAB IDE on a MSWindows machine. I have not checked the last value 50463234. I think there is a pattern to the numbers e.g.
If the pattern is valid then the code could be rewritten to generate the divisors as needed and hence remove these hardcoded numbers.
I'm not sure this pattern is fully valid, but I agree with you, the code is really wrong, I tested it with gpsim :-(
I'm working to fix this but I get some difficulties with the 3 counters delay (of course, the 4 counters delay isn't yet writen :-)), because I want to write a very accurate delay.
Finally, I can confirm you were right ;-)
The pattern is right but it is insufficient to write a formula.
And I discovered exceptions to managed: if a counter is calculated to be zero (so, no loop), this is a problem because 0 clearly means 256!!
Either I'll release a 0.2.5 to fix this problem, but some delays can't be compute, either I'll release a 0.3.0 if I rewrite all the code to be able to provide 3 machine cycles accurate delays.
I have a spreadsheet where I have analysed the code sizes for various delays that might be of some use to you. I have determined a pattern in the no of cycles versus no of loops required. I have written a Ruby program and also an assembly macro that will generate the code given the required number of cycles, accurate to the cycle. It adds 'goto $+1' and 'nop' instructions to get the exact number of cycles. If you would any of this let me know how I can get it to you. I've included the macro below. I've tested quite a few boundary cases but only with online=0.
DELAY_CYCLES MACRO cyc,inline,cblockstart
n=n-4 ;Use 4 cycles for call and return
while (n2+256*loopincdelay<n-2) && levels<4
n-=4*levels ;take off min cycles
n+=1 ; Add back one we saved
To use it:
Log in to post a comment.