Go Down

Topic: Problems reading an analog input and output with 12 bits resolution (Read 4 times) previous topic - next topic

zeluiz

I'll write again the code. It's just necessary to write this


Quote
/*
Read the value of the potentiometer (1.000V) at A0 and multiply
for 1.652 and output it at DAC1 both with 12 bits resolution
*/
float val = 0; // variable to store the value coming from A0
float val2 = 0;
int analogInPin = 0; // Analog input pin connected to the variable resistor
void setup()
{
analogReadResolution(12);
analogWriteResolution(12);
}
void loop() {
 
val = analogRead(analogInPin); // read the voltage on the pot
val2=val*1.625;
analogWrite(DAC0,val2);
delay(5);
}

gbduino

zeluiz,
it is not just clear if you still have a problem, what the problem is or if you already could solve it.
In case you solved it - what have been your findings and why was it "just necessary to write this" (might be of interest or help for others).

zeluiz

You don1t have to use map.   As you can see in the code.   ThankĀ“s.

gbduino

thank you for your reply.
For me it was necessary to use mapping, to be able to obtain the correct voltage relation (as to your project) in the limited outout range my Dues provide. It could have been completely done in one step with "map", but for better understanding I used your multiplicator as first step to translate the input by 1.625 and the used map to obtain the correct voltage from the DAC as I found that not to be 1:1 (the value read for xV from ADC input did not result in xV when fed to DAC).
Are you able to set the voltage of the ADC-outputs in the full range from 0.0 to 3.3V !?
This would be different to what I and also others found.

Gericom


thank you for your reply.
For me it was necessary to use mapping, to be able to obtain the correct voltage relation (as to your project) in the limited outout range my Dues provide. It could have been completely done in one step with "map", but for better understanding I used your multiplicator as first step to translate the input by 1.625 and the used map to obtain the correct voltage from the DAC as I found that not to be 1:1 (the value read for xV from ADC input did not result in xV when fed to DAC).
Are you able to set the voltage of the ADC-outputs in the full range from 0.0 to 3.3V !?
This would be different to what I and also others found.

No, that's not possible. It's a limitation of the chip.
Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

Go Up