Probleme mit ADC im mega32

Gast #147931
Lesenswert?

Hi Leute,
mein ADC macht nur eine Messung nach dem Reset, danach Aktualisiert
sich der wert nicht mehr, obwohl ADSC gelöscht wird!
FreeRun mit Interrupt funktioniert, ich möchte aber später im Pogramm
einzelne Messungen durchführen.

Code:

void init_ADC(void)
{
  ADMUX = (0<<MUX0);
  ADCSRA
=(1<<ADEN)|(1<<ADPS2)|(0<<ADPS1)|(1<<ADPS0)|(0<<ADATE)|(0<<ADIE);//ADC
einschalten, teiler wählen
}

void Analog(void)
{

  sbi(ADCSRA,ADSC);
  while(bit_is_set(ADCSRA,ADSC));

  lcd_puti3(ADCL);
  lcd_home();
}

void main(void)
{

  lcd_init();
  init_ADC();

  while(1)
  {
  Analog();
  delay(255);
  }
}
Gast #147932
Lesenswert?

Auszug aus dem Datenblatt:
If the result is left adjusted and no more than 8-bit precision is
required, it is sufficient to
read ADCH. Otherwise, ADCL must be read first, then ADCH, to ensure
that the content
of the data registers belongs to the same conversion. Once ADCL is
read, ADC access
to data registers is blocked. This means that if ADCL has been read,
and a conversion
completes before ADCH is read, neither register is updated and the
result from the conversion
is lost. When ADCH is read, ADC access to the ADCH and ADCL Registers
is
re-enabled.

Das heist: lies auch ADCH, sonst ist der Zugriff blockiert.
Mit gnu-c sollte auch der Zugriff auf das 16-Bit Register ADC gehen.

Uwe

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren