Gast
#495777
Ich verstehe nicht - warum ist so?
I have soldered a very simple oscillograph based on Atmega8. ADC in the
microcontroller measures voltage between +5 and the ground. This info is
being sent periodically through the serial line to PC.
All is ok. For example, if I use simple voltage divider (R1 and R2 in
series) and measure voltage between them, it shows me really nice exact
values.
But, as soon as I have capacitor in a circuit, all goes wrong. I know
how capacitors work and how they should work. But in my case, a
capacitor makes measured values to swing around the real voltage. Up and
down, up and down...
What the hell is it ? Any good oscillograph doesn't show something
similar ever. I suppose it is ADC issue inside Microcontroller.
My question is following:
How it is recommend to use ADC in the Atmega in order to measure any
outer voltage?
My ADC function looks so:
void ReadChannelInBuf(uint8_t mux, uint16_t *buf, int len)
{
uint8_t i;
//Frequenzvorteilersetzen auf 8 (1) und ADC aktivieren (1)
ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0);
// Kanal waehlen
ADMUX = mux;
// interne Referenzspannung nutzen
ADMUX |= (1<<REFS1) | (1<<REFS0);
for(i=0;i<len;i++){
ADCSRA |= (1<<ADSC);
while ( ADCSRA & (1<<ADSC) );
buf[i] = ADCW;
}
// ADC deaktivieren (2)
ADCSRA &= ~(1<<ADEN);
}
And I do measurements in the loop:
int main(void){
usart_init();
uint8_t i;
uint16_t result;
uint16_t *results;
results = (uint16_t *)malloc(sizeof(uint16_t)*LEN_BUF);
while(1) {
ReadChannelInBuf(0, results, LEN_BUF);
for (i=0;i<LEN_BUF;i++){
result = results[i];
usart_putchar((uint8_t)result);
usart_putchar((uint8_t)(result>>8));
}
}
return 1;
}
Please help me,
Thank you in advance and I am very sorry for my German, but my English
is a way faster for me.