Digitally adjustable voltage with feedback

Hi, I’m trying to use my arduino to digitally adjust voltage via an opto-isolator and a transistor as the voltage control.
The voltage control will be between 0 and 600v and I don’t want to adjust the voltage based upon a control value I want to adjust the control value based upon the intended voltage. So if the voltage is above or below the set voltage it will correct itself.

I was thinking of perhaps using a potentiometer to set a numeric value between 1 and 5 (as a prototype value) for 1-5 volts and then have the program do voltage value/5*225 and then send that as an output value for analogWrite to the opto-isolator.
Then I’ll have it read the output voltage and have it adjust the value until the input value matches the output value.

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  
}

// the loop routine runs over and over again forever:
void loop() {
  //Power source for adjustable voltage
  digitalWrite(13, HIGH);
  // Reads potentiometer voltage to get a reference number used for intended output voltage
  int reference = analogRead(A1);
  // Takes analogRead value and turns it into the intended voltage reference number
  float ReferenceNumber = reference * (5.0 / 1023.0);
    
  // Translation from intended voltage number to analogWrite voltage
  float output=ReferenceNumber/ (5*225.0);
  // output to Opto-isolator
  analogWrite(9,output);
  
  // reads the output voltage for feedback control
  int feedback = analogRead(A0);
  // If the output voltage is greater or less than the intended voltage then the opto-isolator bias will be adjusted.
  if (feedback*(255/1023.0) > output ) {
  feedback = -1 ;}
  if (feedback*(255/1023.0) < output ) {
  output = +1 ;}
  //Prints the output voltage
  Serial.println(feedback);
}

Unfortunately the output value is reading .17v no matter whee I turn the pot.

Is there a flaw somewhere?

Feedback.ino (1.12 KB)

You forgot to tell us about the external circuitry.
Post a schematic diagram (hand drawn is fine, Fritzing is not welcomed).

This is the basic design

An ADC will feed a microcontroller the voltage output data and then a microcontroller will bias the opto-isolator so the output matches the set voltage.

coinmaster:
This is the basic design

An ADC will feed a microcontroller the voltage output data and then a microcontroller will bias the opto-isolator so the output matches the set voltage.

This kind of vague description is why we ask for a schematic. Any answer to it will probably be wrong.

What else do you want to know? I don't know what else I can tell you about it, it's all right there.
There's nothing wrong with my external circuitry anyway, it works fine until I drive it with the microcontroller using this sketch.

Why didn't you continue with the thread you started earlier rather than start another one?
variable DC voltage from the arduino

Hi,
What arduino controller are you using and can you please attach your circuit diagram please.

Tom.... :slight_smile:

Your attachment doesn't show for me. I tried copy-pasting the link but I get an error that says I must be signed in.

OldSteve:
Why didn't you continue with the thread you started earlier rather than start another one?
variable DC voltage from the arduino

That's a totally different subject.

MorganS:
Your attachment doesn't show for me. I tried copy-pasting the link but I get an error that says I must be signed in.

Sorry try this
Imgur
Imgur

Post your design using this

This is how to posting a project photo to arduino forum

Digitally adjustable voltage 600V with feedback.png

What current do you need on the 600V output?

I'm not sure what you mean by "what do you need on the 600v output".,the design will be used in a few different circuits.
For the arduino I'm using a potentiometer to set a value between 1 and 5 (for 1-5 volts) and then converting that into an analogWright voltage. Then I read the output voltage and adjust the analogwrite output until the output matches the intended voltage.

I'm prototyping it with 5v right now since it can't output or read 600v.
It works fine as a variable voltage when I use an external power supply on the opto-isolator.
The problem is when I use the arduino to power the otpo the feedback I wrote in isn't changing from .17v.

I realized I made a mistake here

if (feedback*(255/1023.0) > output ) {
feedback = -1 ;}
if (feedback*(255/1023.0) < output ) {
output = +1 ;}

I changed it to

if (feedback*(255/1023.0) > output ) {
output = -1 ;}
if (feedback*(255/1023.0) < output ) {
output = +1 ;}

Now the output is reading a constant 35, considering how 5 should be the maximum number I’m not sure how it can be 35.

That circuit would not provide a "voltage".
When driven by a PWM signal it would produce a higher voltage PWM signal.

I am asking "What current do you need on the 600V output?"

The analogWrite() output is PMW, you need RC circuit to convert it to variable voltage.

BillHo:
I am asking "What current do you need on the 600V output?"

Oh sorry, the output will be in series with the circuit it's in so the circuit will dictate the current.

BillHo:
The analogWrite() output is PMW, you need RC circuit to convert it to variable voltage.

I threw an RC filter onto it with a 1k resistor and a 100uf capacitor and it changes from 203.7 to 203.8 mv when turning the pot.

You can try the RC filter onto it with a 220 ohms resistor and a 4.7uf capacitor.

The output doesn't read any different whether the PWM is filtered or not. If PWM works with LEDs how is it any different with an opto?

coinmaster:
Oh sorry, the output will be in series with the circuit it's in so the circuit will dictate the current.I threw an RC filter onto it with a 1k resistor and a 100uf capacitor and it changes from 203.7 to 203.8 mv when turning the pot.

  1. Yes, what current does your circuit dictate?

  2. Where did you "throw" it? Please update the schematic. If it is before or after the optoisolator, or after the transistor, it makes a difference to the answer.

MorganS:

  1. Yes, what current does your circuit dictate?

There are a few different circuits, the currents to be highly variable even within the individual circuits. It's not really related to the problem at hand as the only thing I'm concerned with is variable voltage.

MorganS:
2. Where did you "throw" it? Please update the schematic. If it is before or after the optoisolator, or after the transistor, it makes a difference to the answer.

After the PWM output.

  1. Yes it's relevant. What is the range? Milliamps? One to Ten amps?

  2. So before the opto then? Optos are poor at analog. It is best if you give it a digital signal and smooth the PWM after the opto.