getting low output voltage after adding a resistor

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

what I want is fixing this voltage drop when I add a load

Use a unity gain buffer amp. Like this...

Allan

buf.pdf (13.9 KB)

my question is that, can I get the five volt output by only modifying the code?

or is it a dead end and I have to use the amp?

No.

Yes - or something similar.

Allan

MaxTec:
what I want is fixing this voltage drop when I add a load

and schematic is ?

my question is that, can I get the five volt output by only modifying the code?

Not with the filter and the load... The 1K resistor in the filter and the 1K load form a 50/50 [u]voltage divider[/u]. With two equal-value resistors you should get 2.5V out with 5V in.

Note that an output-high (or PWM=255) may not give you exactly 5V out, especially with a load. And you can't get exactly 5V is your 5V power is a little low.

The input of an op-amp is very-high impedance so there will be essentially no voltage divider effect. However, your op-amp may need a power supply higher than 5V if you want 5V out, and you may need dual power supplies (positive and negative) if you need to get-down to zero-volts out. Or there are "rail-to-rail op-amps that should get close to the full 0 - 5V range.

I am trying to build a voltage tracker with a feedback loop

The op-amp buffer will do that with no software. :wink:

There are current limits for op-amps too. A 1K load will be OK with most op-amps, but regular op-amps are not "power supplies" or "power amplifiers".

Thank you all. I really appreciate your help. thanks it is solved