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.

[SOLVED] Delay generated by delay_ms is not proper in XC8 compiler

Status
Not open for further replies.

shivakumar.r

Member level 1
Joined
Sep 5, 2011
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,601
Dear Friends,

I am using PIC16F1829 and XC8 compiler.
I am using external crystal of 4MHZ.

I am just trying to blink an LED for every 2 seconds.

I have used __delay_ms(2000); function to generate 2 seconds of delay.Also before the main i have included _XTAL_FREQ 4000000

Compiler is not giving any error,after i program the device instead of LED blinking for 2 seconds it is blinking for less than 1 seconds.

I have previously used Hightech c compiler and code was working fine and delays were accurate.Only if i use XC8 compiler i am getting this issue....

Please help me to solve this issue.......
 

ashugtiwari

Full Member level 4
Joined
Dec 12, 2008
Messages
218
Helped
45
Reputation
90
Reaction score
44
Trophy points
1,308
Activity points
3,310
1. check https://ww1.microchip.com/downloads/en/DeviceDoc/52053B.pdf , page 59, the delay function is explained. According to that if u need accurate delay, plz use timer peripheral.
2. the delay function converts into assembly instruction. It is always better if u write ur own routine. All the instruction takes exactly 4 clock cycles, so use a loop where u know how many instructions it has and run loop for clock cycles multiplied by some number which equals 2 second delay.
3. check if PLL is off and the corresponding .h file is included for delay and freq determination macro.

hope that helps.
 

shivakumar.r

Member level 1
Joined
Sep 5, 2011
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,601
Thanks for the feedback....

The issue is solved...

4xPLL was enabled ,when i disabled it issue got solved....

Thanks a lot....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top