I am trying to use the included delay.h and the _delay_ms function for timings.
As a basic test, I am trying to switch an led on and off at precisely 1x/sec. Something like this...
while (1) { //1000 ms total for 1 second //LED Toggle PORTD = 0b00000001; _delay_ms (200); //LED Toggle PORTD = 0b00000000; _delay_ms (800); }
When I do this while watching the second hand on a watch, the timing is not accurate. I'm thinking this has to do with cpu settings, but I thought that the purpose of this function was to automatically make the calculation for you.
I am using AVR Studio 4 / WinAVR, and have the cpu settings configured in the menus. Testing on STK500.
What am I doing wrong? Thanks.