I use ATmega32 and i need to make delay 1 sec exactly. I used
_delay_loop_2(1000);
_delay_ms (1000);
; however, none of them is accurate, so do I misunderstand those functions?
Have you defined the correct clock speed for your project?
The delay of _delay_ms() is based on the defined clock frequency and of course on the accuracy of the clock source.
Also note that any interrupt during the delay will pause the delay routine until the interrupt is executed and then the delay will resume.
you call it with the number of iterations up to 65536, the loop executes four CPU cycles per iteration so depending on the clock you can delay up to 65536*4 clock cycles
It would help a lot if you posted your code here. Then, we could see if there are other mistakes or the more common mistakes as have been already stated above. Which compiler are you using? I'm guessing you're using avr-gcc (WinAVR IDE).
yes interrupt may be the problem, check if you are using any interrupt.
and if the delay going shorter than programmed then it may not be the interrupt.
_delay_loop_2(30000) is not a delay in ms, it executes 30000 iterations taking four CPU cycles each so the delay is 30000*4= 120000 * (1/clock) where clock is in Hz
for example with 8000000Hz clock the delay is 120000 * 0.000000125 = 0.015 which is 15ms
Use _delay_ms(1000) instead but define your clock frequency first in the project properties (you enter the frequency in Hz)