I am building a hobby oscilloscope on ATmega16. I am testing ADC by generating a square wave at 2kHz with small amplitude and applying it to the ADC pin through a capacitive input with a voltage divider to shift zero-level.
This is how the signal looks after being sampled by ADC:
It looks fine, but after I start shifting zero-level by adjusting the potentiometer I get these strange spikes:
After shifting level a bit higher it looks fine again:
Overall, I get 3 ranges where the spikes appear.
Some info
- AVR is running at 16MHz
- ADC uses internal 2.56 reference voltage
- ADC is in free running mode at 125kHz (prescaler=128)
- I transfer data via CP210 to an android tablet which is used for real-time plotting. The circuit is also powered from the tablet. I get the same results when the circuit is connected to PC.
- USART baudrate is 500000b/s (UBRR=1)
- AVcc and AREF are not connected. I also tried connecting AVcc to Vcc and adding a .1uF cap between Gnd and AVcc but this had no effect.
Some more info
- this noise does not come from the generator (tested with analog oscilloscope)
- this noise does not come from the potentiometer
- LFUSE = 0xFF, HFUSE = 0x89.
ADC initialization routine
ADMUX = (1 << REFS0); // AVCC with external capacitor at AREF pin
ADCSRA = (1 << ADEN)
| (1 << ADIE)
| (1 << ADATE)
| (1 << ADPS0)
| (1 << ADPS1)
| (1 << ADPS2); // Division factor = 128
MCUCR |= 1 << SM0;
MCUCR |= 1 << SE; // Sleep-mode enabled
ADCSRA |= (1 << ADSC);
ADC data transfer routine
volatile uint8_t adcLow;
volatile uint8_t adcHigh;
int main(void) {
....
while (1) {
if (ADCSRA != 0x00) {
USARTSendByte(adcLow);
USARTSendByte(adcHigh);
}
}
}
ISR(ADC_vect) {
adcLow = ADCL;
adcHigh = ADCH;
}
uint16_t adcValue = ADC;
\$\endgroup\$