Simple Voltage Divider Feedback

Hello, my current project is to build a simple proportional feedback system using a voltage divider and potentiometer. I am new to Arduino and programming and am having a little trouble with this one. It seems like the arduino's PWM is incapable of producing negative voltage values, is this true? The system is completely unstable and oscillates between 0 and 5 volts. It seems like what's happening is that it "overshoots" the set value and cannot provide a negative voltage to return back to the set value, it seems like it only gets worse. Here is the code below. I have printed to an LCD both the value I am trying to set (which is 100/1023 volts), and the value in volts that the PWM is producing. Does anyone have any suggestions or tips? Thanks

float pwmValue;    
float outputValue;        
int Output = 9;
int Pwm = A0;
int V_Out = A5;

void setup(){
  pinMode(9,OUTPUT);
  pinMode(A0,INPUT);
  pinMode(A5,INPUT);
 
  Serial.begin(9600);
}

void loop(){
  float Voltage_Out = analogRead(V_Out);
  float Pwm_Voltage = analogRead(Pwm);
                     //read input value: range between (0,1023)
  float setpoint = 100;
  float gain = 5;
  float err = gain*(Voltage_Out-setpoint);
  float Feed_Output = err*255/1023;
                    //PWM can only ouput 255 different values
  analogWrite(Output,Feed_Output);
  //sensorValue = analogRead(A0);
  //outputValue = map(sensorValue, 0, 1023, 0, 500);//scale voltage value to 0-5V
  outputValue = Voltage_Out*5/1023;
  pwmValue = Pwm_Voltage*5/1023;
  Serial.write(0xFE);
Serial.write(0x51);
Serial.print("Voltage = ");
Serial.write(0xFE);
Serial.write(0x45);
Serial.write(0x0E);
Serial.print(" V");
  Serial.write(0xFE);
  Serial.write(0x45);
  Serial.write(0x0A);
  Serial.print(outputValue,2);
  Serial.write(0xFE);
  Serial.write(0x45);
  Serial.write(0x40);
  Serial.print("Voltage = ");
Serial.write(0xFE);
Serial.write(0x45);
Serial.write(0x4E);
Serial.print(" V");
  Serial.write(0xFE);
  Serial.write(0x45);
  Serial.write(0x4A);
  Serial.print(pwmValue,2);
  delay(1000);        // delay 1ms in between reads for stability
}

It seems like the arduino's PWM is incapable of producing negative voltage values, is this true? The system is completely unstable and oscillates between 0 and 5 volts.

A PWM output signal ( as used in analogWrite() ) does not output a true analog signal, but rather a digital on/off switching signal where the ratio or on time Vs off time is the variable amount. If one requires a true analog output voltage derived from the PWM output signal the output must be wired to a low pass filter which can be a simple series resistor and capacitor to ground and the analog voltage taken from the junction of the resistor and cap. You will then end up with a true analog voltage that can range from 0 volts to +5vdc corresponding to analogWrite(pin, 0) to analogWrite(pin,255).

Lefty

It seems like the arduino's PWM is incapable of producing negative voltage values, is this true?

Correct, and also inputting them.

Does anyone have any suggestions or tips?

You can feed the pwm output through a low-pass filter and then your divider to obtain an analog output.

BTW, unless you are very lucky, your implementation, as is, will likely be unstable. Google PID to see how it can be done.