Page 1 of 1

Delays

Posted: Thu May 07, 2009 4:46 pm
by echase
How does Flowcode proramme delays? E.g. if I set a 4 second delay I assume the code in the PIC runs around a dummy loop lots of times until about 4 secs are up. How accurate is it?

If I add a TMR0 interrupt at 15Hz to do another short macro this will interrupt this delay about 60 times and so presumably slow it down. Is that right or does the delay auto compensate for the interrupt time

Re: Delays

Posted: Fri May 08, 2009 8:59 am
by Benj
Hello

The delays are based on clock speed. If your clock speed is accurate then the delays will also be accurate or at least down to the nearest micro/nano second. Clocks generated from ceramic resonators, RC circuits or internal oscillators will generally be fairly inaccurate. If you give me your clock speed and the delay time then I can work out the error for an accurate crystal.

Unfortunatly the interrupt routine will indeed slow down the delay. You can look at the casm file generated from flowcode and work out exactly how many assembler commands there are in your interrupt routine. This will let you know exactly what the slow down amount will be over a second so you can compensate if need be.

Re: Delays

Posted: Wed May 13, 2009 3:07 pm
by echase
I am using a 4 second and four 150mS delays with a 250kHz internal precision clock. How accurate is that? Thought that clock was pretty accurate even though it's not a crystal one.

The reason for the four 150mS delays is that I discovered rather too late that Flowcode doesn’t appear to process a number higher than 255. Any chance of an error message if a user attempts to enter a higher number? Far as I can tell entering say 900mS just truncates to 255 or is it 900-3*255?

My June EPE article is in newsagents this week with you guys mentioned.

Re: Delays

Posted: Thu May 14, 2009 8:04 am
by Steve
A delay of 900ms will automatically be converted to 3 delay_ms(255) plus 1 delay_ms(135).

I think when a variable is used, it may work differently.

By the way, I saw the article. It looks like a massive project! Oh, and thanks for the mention... Glad we could help.

Re: Delays

Posted: Thu May 14, 2009 8:45 am
by echase
Yes a massive project for me. Hence lots of questions!

I was using a variable preset in the boot routine to between 500 and 999ms and am pretty certain it was not correctly calculating it. I can see that an error message is difficult when a variable is used as Flowcode does not know the variable value.

Re: Delays

Posted: Thu May 14, 2009 9:06 am
by Benj
Hello,

Thanks for the mention looking forward to reading the article.

When using a variable delay you can do something similar to the following where delayval is your INT delay variable.

calc: delayval = 800

loop: delayval > 255
{

delayms: 255

calc: delayval = delayval - 255

}

delayms: delayval