Hello all, I have been struggling with my circuit for over a week. I am trying to build a voltage tracker with a feedback loop. I want to get analog input reading using a potentiometer and I want to output exactly the same reading, 1v=1v,2v=2v,3v=3v,4v=4v,5v=5v. I am outputing pwm value and using RC filter to obtain a smooth analog value. R=1K, C=1uf. here is my problem, when I added a load of 1K ohm betwwen the R and the C of the filter, the analog maximum reading that I can get is 2.2V when my set point from the potentiometor is 5V. Though my feedback should bring it back to the same value it seems like the output can not supply enough something.
I would appreciate any help here. thanks in advance
this is my code
byte potentiometer = A0;
byte feedback = A1;
int PWM = 10;
void setup() {
Serial.begin(115200);
pinMode(potentiometer, INPUT);
pinMode(feedback, INPUT);
pinMode(PWM, OUTPUT);
setPwmFrequency(10,1);
}
void loop() {
int voltage = analogRead(potentiometer);
int output = analogRead(feedback);
///serial design
Serial.print("\n \n\n\n\n\n\n\n\n\n\n ");
Serial.print("\t \t\t\t\t\t\t\t\t\t\t ");
Serial.print("\r voltage = ");
Serial.print(voltage);
Serial.print(" ");
Serial.print("\r output = ");
Serial.print(output);
Serial.print(" ");
if (voltage > output)
{
pwm = (pwm + 1);
pwm = constrain(pwm, 1, 254);
}
if (voltage < output)
{
pwm = (pwm - 1);
pwm = constrain(pwm, 1, 254);
}
Serial.print("\r pwm = ");
Serial.print(pwm);
Serial.print(" ");
analogWrite(PWM, pwm);
}
also my frequency
void setPwmFrequency(int pin, int divisor) {
byte mode;
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch(divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 64: mode = 0x03; break;
case 256: mode = 0x04; break;
case 1024: mode = 0x05; break;
default: return;
}
if(pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
} else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
} else if(pin == 3 || pin == 11) {
switch(divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 32: mode = 0x03; break;
case 64: mode = 0x04; break;
case 128: mode = 0x05; break;
case 256: mode = 0x06; break;
case 1024: mode = 0x7; break;
default: return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
waiting for any ideas thanks