0

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.

asked Dec 8, 2016 at 19:41
3
  • The function adc_set_channel_input_gain() is not compliant with the basic analog input library which use only analogReadResolution() and analogRead(). Please read more about adc_init(ADC... for the "sam3x". Commented Dec 8, 2016 at 21:44
  • @J.Piquard, thank you for help, where can I find documentation? Commented Dec 8, 2016 at 23:04
  • Take a look to that Guide: "Quickstart guide for SAM ADC driver". Commented Dec 8, 2016 at 23:17

1 Answer 1

0

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);
}
answered Dec 21, 2016 at 22:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.