Precision of delay

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
vinctech
Posts: 7
Joined: Sat Dec 24, 2016 1:18 am
Has thanked: 7 times
Contact:

Precision of delay

Post by vinctech »

Hi,

I have a question on the precision of the standard delay block in FC8.1

FC8.1
PIC 16F1823
Internal oscillator, 1MHz (OSCCON=0x58)
Clockspeed in FC8.1 Project Configuration: 1MHz

I inserted a 'delay' function block of 500ms, (with no extra code in the project except for blinking a led).
At runtime, the actual delay time appears to be 15..20% larger.

At first, I checked the actual clockspeed (Fosc/4 output on port A4), which was a perfect 250kHz.
My conclusion is, that the timing error is caused by the implementation of the 'delay' function block.

Question: can you give an estimate of the acceptable precision of the 'delay' function?
Of course, I can create my own precision delay time with a timer/interrupt, but I really value the built-in 'delay' block.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Precision of delay

Post by Benj »

Hello,

1MHz is fairly low speed and so the delay will consume 500ms and then other code, e.g. to wrap around the loop and to output the state to the pin are going to take some instruction cycles. Also make sure you have the "Auto Clear Watchdog" setting in the project options disabled or this will add extra instruction cycles to clear the watchdog counter during the delay period.

XC8 is also known to de-optimise code in free mode which will be adding extra instruction cycles.

So for more accurate (tighter) delays I would advise the following.

1) Run the chip faster
2) Make sure other code is as clean and straightforward as possible
3) Disable Auto Clear Watchdog
4) Try using XC8 in the 60 day free Professional mode (this will likely be by far the biggest difference)

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Precision of delay

Post by medelec35 »

What about a tight loop with a timer interrupt that causes loop to exit?
Martin

vinctech
Posts: 7
Joined: Sat Dec 24, 2016 1:18 am
Has thanked: 7 times
Contact:

Re: Precision of delay

Post by vinctech »

Hi Benj,

- Increasing clockspeed gives no improvement (from 1MHz to 16MHz)
- Disable Auto clear watchdog gives a slight improvement
- Using XC8 pro trial: I installed and activated the compiler, but fail to get Flowcode using it. I searched the forum for directions, but cannot find a good set. Can you provide a 'good' link?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Precision of delay

Post by Benj »

Hello,

Simply click Build -> Compiler options.

Click the save button at the top right, give the new setting a name e.g. Pro XC8 and click OK.

Select the new Pro XC8 setting on the left hand side list.

Change the compiler location to the path to your new XC8.exe

Code: Select all

C:\Program Files (x86)\Microchip\xc8\v2.00\bin\XC8.exe
Change the compiler parameters to

Code: Select all

--chip=$(chip) "$(target).c" --MSGDISABLE=359,1273,1388
Finally ensure that the Default Compiler tickbox is ticked and click OK.

Hopefully this should be all you need to do.

If you need to go back then simply click on the default setting and tick the default tickbox.

vinctech
Posts: 7
Joined: Sat Dec 24, 2016 1:18 am
Has thanked: 7 times
Contact:

Re: Precision of delay

Post by vinctech »

Hi Benj,

Thank you for the install help of the XC8 pro compiler; it works! An uninstall+reinstall of the original flowcode toolchain was required, but after that, the new compiler worked as expected.

The delay time error (500ms timer) decreased/improved to 7% deviation (535 ms measured).
I consider this as the best I can get with the standard delay-block.

For more precise delays, I will use the timer/interrupt construct.

Thank for assistance, we may close this call.

Post Reply