im working on a code which takes sine wave as input converts it through adc and takes the peak value , but the issue im facing is that the input amplitude of sine wave is 1.5v while the output wave amplitude doesnt exceed 0.5v even when the input is passed as it is to the output. why is there this kind of distortion?
``` const int input=A0;
const int output=A1;
float peak=0;
float inputVoltage=0;
float outputVoltage=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//analogueReadResolution(12);
}
void loop() {
// put your main code here, to run repeatedly:
int inputRaw = analogRead(input);
int outputRaw = analogRead(output);
// Convert raw ADC values (0-4095) to voltage (assuming 3.3V reference):
inputVoltage = (inputRaw * 3.3) / 1023.0;
outputVoltage = (outputRaw *3.3) / 1023.0;
Serial.print("the output voltage is : ");
Serial.println(outputVoltage);
if(outputVoltage>peak){
peak=outputVoltage;
Serial.print(" new peak is :");
Serial.println(peak);
}
else{
Serial.print("the previous peak was : ");
Serial.println(peak);
}
delay(2);
}
It would help enormously of you could post a schematic of your circuit. Hand drawn is fine, pictures joined with lines, or physical layout diagrams are not.
Get rid of this, it is screwing your results, if you are trying to track the input wave looking for a peak.
Also all thous serial print statements slow things down tremendously especially at that ridiculously slow baud rate. As is all the conversion into a floating point voltage. This is totally unnecessary, just go with the raw readings.
So this makes me unsure about the rest of it. Can you post in a new reply the current sate of your code. Have you incorporated my other suggestions as well?
Also we need to see a schematic, as this problem shows all the hallmarks of a voltage biasing issue.
You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, we don't stand a chance.