teensy2 ADC weired behaviour
I have an app which uses 2 ADC channels on differnet Ports because of layout linitaions. Reading channel 1 from Port F on Pin PF1 works fine, but reading channel 11 from Port C on Pin PB4 returns garbage.
I reduced the code to reading the same value on both Pins every second in a loop. Teensy is on a breadboard with a voltage divider and a capacitor for the value to read. Code for ADC is adc_read, copied from the pjrc site. Settings for the channels is:
DDRB &= ~(1<<4); // ADC 11
DDRF &= ~(1<<1); // ADC1
Call is:
uint8_t Tastenwert=0;
Tastenwert=(adc_read(1)>>2); // Read channel 1
lcd_putint12(Tastenwert); // Display a 12Bit number on the LCD
Tastenwert=(adc_read(11)>>2); // Read channel 11
lcd_putint12(Tastenwert); // Display a 12Bit number on the LCD
Result of channel 1 is correct, channel 11 gives 127
Changing the order of the calls changes nothing. Same behaviour on two teensy2, oneof them out of the box. Reading on other channels on Port F is OK, on other channels of Port C is not. There are no timers or other interrupts in the code.
I think there is a very basic mistake in the code, but no idea what. I made several apps with teensy2++ with no such problems.
I have an app which uses 2 ADC channels on differnet Ports because of layout linitaions. Reading channel 1 from Port F on Pin PF1 works fine, but reading channel 11 from Port C on Pin PB4 returns garbage.
I reduced the code to reading the same value on both Pins every second in a loop. Teensy is on a breadboard with a voltage divider and a capacitor for the value to read. Code for ADC is adc_read, copied from the pjrc site. Settings for the channels is:
DDRB &= ~(1<<4); // ADC 11
DDRF &= ~(1<<1); // ADC1
Call is:
uint8_t Tastenwert=0;
Tastenwert=(adc_read(1)>>2); // Read channel 1
lcd_putint12(Tastenwert); // Display a 12Bit number on the LCD
Tastenwert=(adc_read(11)>>2); // Read channel 11
lcd_putint12(Tastenwert); // Display a 12Bit number on the LCD
Result of channel 1 is correct, channel 11 gives 127
Changing the order of the calls changes nothing. Same behaviour on two teensy2, oneof them out of the box. Reading on other channels on Port F is OK, on other channels of Port C is not. There are no timers or other interrupts in the code.
I think there is a very basic mistake in the code, but no idea what. I made several apps with teensy2++ with no such problems.
Last edited: