Page 1 of 1

Time problem, delay_us function

Posted: 22 Nov 2009 13:29
by miletheking
Hi, I have problem with delay_us function. I was connect to port B led diode. In my program I light on diode for 10000 ms and light off diode for 10000ms. If my clock is 1 Mhz led will be on for 10 second and off for 10 second. If my clock is 2 Mhz led will be on for 5 second and off for 5 second. Why clock affect on delay_ms function?

My main problem is to create signal which is on high level for 1.8 ms and on low level for 20 ms. Can I be sure that if I use function delay_us(1800) and delay_us(20000) with clock of 1 Mhz that my signal will lock as I want?

I use bigavr2 board with ATmega 128 microcontroler.

Re: Time problem, delay_us function

Posted: 25 Nov 2009 17:18
by nikola.kostic
miletheking wrote:Hi, I have problem with delay_us function. I was connect to port B led diode. In my program I light on diode for 10000 ms and light off diode for 10000ms. If my clock is 1 Mhz led will be on for 10 second and off for 10 second. If my clock is 2 Mhz led will be on for 5 second and off for 5 second. Why clock affect on delay_ms function?
Delay is calculated from the clock, so you need to set oscillator/frequency settings correctly in your project. Don't forget that these settings can depend on quartz used on your board.