[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
Visit site
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.......
 

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.
 

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

Cookies are required to use this site. You must accept them to continue using the site. Learn more…