Forum: Mikrocontroller und Digitale Elektronik This Capacitor makes me MAD !!!

Autor: Bob (Gast)

0 lesenswert
nicht lesenswert
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 

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);

    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){

    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];
    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.

Autor: Muraer (Gast)

0 lesenswert
nicht lesenswert
What do you mean with "as soon as I have a capacitor in a circuit"?
Where do you connect the cap??
Maybe you should post a schematic...

Autor: Diablo (Gast)

0 lesenswert
nicht lesenswert
No matter, where. If any capacitance is presented in a circuit, my 
pseudo-Oscillograph shows wrong values.

For example if C1 is between R1 and the ground. I've tried very simple 
RC-circuit and it doesn't work how it has to be.

Autor: eProfi (Gast)

0 lesenswert
nicht lesenswert
I think you want to implement a "AC-Coupling". In this case you must set 
the input to Vref/2 by connecting one resistor (10k - 100kOhm) between 
AGnd an Ain   and  a second resistor between Ain and Vref.

Autor: Bob (Gast)

0 lesenswert
nicht lesenswert
from Wikipedia:
Capacitive coupling is often unintended, such as the capacitance between 
two wires or traces that are next to each other. Often one signal can 
capacitively couple with another and cause what appears to be noise. To 
reduce coupling, wires or traces are often separated as much as 
possible, or ground lines or planes are run in between signals that 
might affect each other. Breadboards are particularly prone to these 
issues due to the long pieces of metal that line every row creating a 
several-picofarad capacitor between lines. To prototype high-frequency 
(10s of MHz) or high-gain analog circuits, often the circuits are built 
over a ground plane so that the signals couple to ground more than to 
each other. If a high-gain amplifier's output capacitively couples to 
its input it often becomes an oscillator.

and in my case... hm... I use breadboard !!! (Steckplatine) Thus, it is 
probably has capacitive coupling of some pF, isn't it ? But it is very 
doubtfully that even a very simple circuit (+5-R1-C1-ground) will create 
a capacitive noise

Autor: Bob (Gast)

0 lesenswert
nicht lesenswert
yeah, the problem was with breadboard! capacitive noise.

Antwort schreiben

Die Angabe einer E-Mail-Adresse ist freiwillig. Wenn Sie automatisch per E-Mail über Antworten auf Ihren Beitrag informiert werden möchten, melden Sie sich bitte an.

Wichtige Regeln - erst lesen, dann posten!

  • Groß- und Kleinschreibung verwenden
  • Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang

Formatierung (mehr Informationen...)

  • [c]C-Code[/c]
  • [avrasm]AVR-Assembler-Code[/avrasm]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] - Link zu Artikel
  • Verweis auf anderen Beitrag einfügen: Rechtsklick auf Beitragstitel,
    "Adresse kopieren", und in den Text einfügen

Bild automatisch verkleinern, falls nötig
Bitte das JPG-Format nur für Fotos und Scans verwenden!
Zeichnungen und Screenshots im PNG- oder
GIF-Format hochladen. Siehe Bildformate.
Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt.
Bitte hier nur auf die ursprüngliche Frage antworten,
für neue Fragen einen neuen Beitrag erstellen.

Mit dem Abschicken bestätigst du, die Nutzungsbedingungen anzuerkennen.