Forum: Compiler & IDEs _delay_ms(200) ist zu schenll


von Nick (Gast)


Lesenswert?

Hallo,
wenn ich folgenden Code schreibe ist die delay funktion nicht 200ms lang 
sondern viel schenller, an was kann das liegen?

#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL     /* Quarz mit 16 Mhz  */
#include <avr/delay.h>      /* definiert _delay_ms()

int main (void)
{
  int i;
  CLKPR = 0x80;      //Change System CLK-Prescaler to 1
  CLKPR = 0x00;      //Change System CLK-Prescaler to 1
  PORTE = 0x00;
  DDRE = 0xE0;


  while (1)
  {

  PORTE = 0xff;
  _delay_ms(200);
  PORTE = 0x00;
  _delay_ms(200);


  }

  //never goes here!
  return 0;
}

von Timo Dittmar (Gast)


Lesenswert?

Hallo,

aus der avrlibc Dokumentation:

void _delay_ms    (     double      __ms     )


Perform a delay of __ms milliseconds, using _delay_loop_2().

The macro F_CPU is supposed to be defined to a constant defining the CPU 
clock frequency (in Hertz).

The maximal possible delay is 262.14 ms / F_CPU in MHz.

CU Timo

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.