Hey guys,
I am experiencing a strange problem using Pedvide's (great) ADC library and the audio library :
I am trying to read a (10k linear) pot while reading an audio input through the adc,
here is my code :
audio input is fed to pin 16 (A2) and the pot is connected to 3.3v, GND and pin 17(A3).
While the audio goes through very nicely, the reading of the pot is quite strange :
I get a very precise reading for only half of the turn of the pot and for the other half
it only gives the highest value, for example for the 16 bit resolution half of the dial
gives all the range (0..65536 and very precisely so) and when I turn the knob further
it only stays on the value 65536. My initial thought was that this is a faulty pot but then
I ran this code :
which is the same, only without the audio library and the readings of the pot are perfect!
I can't figure this out, help anyone ?
Thanks in advance
I am experiencing a strange problem using Pedvide's (great) ADC library and the audio library :
I am trying to read a (10k linear) pot while reading an audio input through the adc,
here is my code :
Code:
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <ADC.h>
ADC *adc = new ADC();
const int readPin = A3;
// GUItool: begin automatically generated code
AudioInputAnalog adc1; //xy=161,80
AudioOutputAnalog dac1; //xy=329,47
AudioConnection patchCord1(adc1, dac1);
// GUItool: end automatically generated code
void setup() {
AudioMemory(12);
pinMode(17, INPUT);
Serial.begin(57600);
adc->setAveraging(32, ADC_1); // set number of averages
adc->setResolution(16, ADC_1); // set bits of resolution
adc->setConversionSpeed(ADC_HIGH_SPEED, ADC_1); // change the conversion speed
adc->setSamplingSpeed(ADC_HIGH_SPEED, ADC_1); // change the sampling speed
adc->setReference(ADC_REF_3V3, ADC_1);
}
int value = 0;
void loop() {
value = adc->analogRead(readPin, ADC_1); // read a new value, will return ADC_ERROR_VALUE if the comparison is false.
Serial.print("Pin: ");
Serial.print(readPin);
Serial.print(", value ADC1: ");
Serial.println(value, DEC);
}
audio input is fed to pin 16 (A2) and the pot is connected to 3.3v, GND and pin 17(A3).
While the audio goes through very nicely, the reading of the pot is quite strange :
I get a very precise reading for only half of the turn of the pot and for the other half
it only gives the highest value, for example for the 16 bit resolution half of the dial
gives all the range (0..65536 and very precisely so) and when I turn the knob further
it only stays on the value 65536. My initial thought was that this is a faulty pot but then
I ran this code :
Code:
#include <ADC.h>
ADC *adc = new ADC();
const int readPin = A3;
void setup() {
//pinMode(17, INPUT);
Serial.begin(57600);
adc->setAveraging(32, ADC_1); // set number of averages
adc->setResolution(16, ADC_1); // set bits of resolution
adc->setConversionSpeed(ADC_HIGH_SPEED, ADC_1); // change the conversion speed
adc->setSamplingSpeed(ADC_HIGH_SPEED, ADC_1); // change the sampling speed
adc->setReference(ADC_REF_3V3, ADC_1);
}
int value = 0;
void loop() {
value = adc->analogRead(readPin, ADC_1); // read a new value, will return ADC_ERROR_VALUE if the comparison is false.
Serial.print("Pin: ");
Serial.print(readPin);
Serial.print(", value ADC1: ");
Serial.println(value, DEC);
//value*5.0/adc->getMaxValue(ADC_1)
}
which is the same, only without the audio library and the readings of the pot are perfect!
I can't figure this out, help anyone ?
Thanks in advance