I want to increase gain of the ADC channel. To achieve this I'm using adc_set_channel_input_gain
function from adc.h. Here is the entire sketch:
const byte aPin = A6;
void setup() {
analogReadResolution(12);
// Configure ADC gain
// Arduino/hardware/arduino/sam/system/libsam/include/adc.h
adc_channel_num_t ch = (adc_channel_num_t)(g_APinDescription[aPin].ulADCChannelNumber);
adc_set_channel_input_gain(ADC, ch, ADC_GAINVALUE_3);
Serial.begin(9600);
// Delay for serial stabilization
Serial.println("Begin.");
delay(2000);
}
void loop() {
int analog = analogRead(aPin);
Serial.println(analog);
delay(500);
}
The problem is that output values are not depending on the gain value.
1 Answer 1
Well, the solution was very simple. We just need to call adc_enable_anch()
before changing gain or offset of the ADC. I improved my setup and the sketch works as expected now:
void setup() {
analogReadResolution(12);
// Configure ADC gain
// Arduino/hardware/arduino/sam/system/libsam/include/adc.h
adc_channel_num_t ch = (adc_channel_num_t)(g_APinDescription[aPin].ulADCChannelNumber);
adc_enable_anch(ADC);
adc_set_channel_input_gain(ADC, ch, ADC_GAINVALUE_3);
Serial.begin(9600);
// Delay for serial stabilization
Serial.println("Begin.");
delay(2000);
}
Explore related questions
See similar questions with these tags.
adc_set_channel_input_gain()
is not compliant with the basic analog input library which use onlyanalogReadResolution()
andanalogRead()
. Please read more aboutadc_init(ADC...
for the "sam3x".