Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

XC8 C delays for PIC micros not right timing

Status
Not open for further replies.
T

treez

Guest
Hi,
When i program a PIC16FXXXX with XC8 , it doesnt give the right delay time
__delay_(20m) gives 80ms or sometimes 160ms delay.
Do you know why?
Also, the program goes wrong if i put in too big a delay value...do you know whats the max?
 

The delay statement may go wrong if the compiler can't determine the actual clock frequency in effect, a matter of your code structure.

Parameter range is specified in the XC8 doc, I think. I don't have it at hand now.
 
  • Like
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
The delay is a software loop and therefore dependent on the clock frequency and maybe (depending on the PIC type) an internal divider option. Check the clock frequency you have specified, in MCC if you use it or directly in the source code.
If you need accurate timing it is far better to use interrupts and a timer module, they are more accurate in most cases and do not block normal code execution.

Brian.
 
  • Like
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
The max value for the delay macro is in the XC8 user guide.
The delay is also affected by interrupts.
Have you set the correct value of _XTAL_FREQ?
You have not told us the clock source (or anything else of real value) so without a short code example that demonstrates the problem, it is really hard to advise you.
Susan
 
  • Like
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top