Teaching myself electronics, trouble building programmable voltage source

I'm trying to teach myself electronics and Arduino. I thought I would make a programmable constant voltage source that I can maybe turn into a battery charger at some point. I figured there would be a lot of challenges to learn along the way. Anyway, the Arduino is outputting a 50% PWM signal to hopefully step down the voltage by half. However, when I breadboard the circuit, I get the full source voltage. I'm not sure why. Trying to test, it seems like I have something wrong with the IRL7833 MOSFET that's switching the high side P-Channel IRF9540N MOSFET, but I can't figure out what I'm doing wrong.

Any help or tips are greatly appreciated.

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

BTW
You will need a resistor from the source to gate on Q2.

Your feedback may be too slow for the cct. to work.

What will be your input control?

Q1 source and drain are switched ;).

Thanks for the help!

int voltInputPin = A0;
int voltPWMPin = 3;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int reading = analogRead(voltInputPin);
  float voltage = reading / 74.58;

  analogWrite(voltPWMPin, 128);

  Serial.print("Reading: ");
  Serial.print(reading);
  Serial.print("\tVoltage: ");
  Serial.println(voltage);

  reading = 0;
  delay(500);

}

How can I figure out the correct resistor size for Q2?

Default PWM frequency (~490Hz on pin3) is way too low for this kind of circuit.
A common 1N5400 is not 'fast' enough.
50%PWM is not half the voltage.
Feedback is too slow.
etc. etc.

Wise to first 'teach yourself' with a different project.
A switch-mode supply is one of the difficult ones.
Leo..

I have a friend who builds Tesla coils, he does what you are trying to do but the output is 100 of thousands of volts. Not sure how well your approach works for a few volts. If you want an electronically controllable variable voltage source I suggest getting a buck or boost switch mode PSU chip and experimenting with controlling it.

Beyond the other issues cited above, you cant breadboard switching powersupplies. They are extremely layout sensitive; even a custom designed circuit board requires close attention to the layout to minimize the size of the current loop. The textbook my father (an electrical engineer retired after >40 years doing cutting edge design work, but not power supply design) got when he was trying to understand the matter a few years back described breadboards as "kryptonite" for switching supplies.

Building switching power supplies is something you can start to do by using switchmode supplies based on dedicated switching dc-dc controller ICs by meticulously following the design and layout guidelines in their datasheet, once you are comfortable and experienced designing your own pcbs. Designing the whole thing from scratch and programming the controller is a considerably more advanced subject.

Hint: for high frequency switching of MOSFETs always use a gate-driver chip..

mullenba:
How can I figure out the correct resistor size for Q2?

The way you have wired it the moment Q1 is off, the gate of Q2 is floating - the charge present remains there, keeping Q2 on.

The gate/source resistor is to discharge the gate, and normally only to keep the part off when the gate is not driven. It's not a good way to switch off a MOSFET, it's too slow, draining the gate with a few mA. A gate driver (replaces Q1 basically) can charge/discharge the gate at currents of 1A or more, so easily 100 times shorter switching time than a resistor, or even the Q1 driver MOSFET in your circuit.

You may be getting your circuit to work, but don't expect much efficiency. Plus the comments above... Mind that the fastest reaction time you have is about 110µs, as that's how long it takes to do an analogRead()! (this can be improved with some register settings, at a loss of resolution, and then it's still a question of whether the Arduino is fast enough).

mullenba:
How can I figure out the correct resistor size for Q2?

A 10K resistor between gate and source of Q2 should do the trick.
Tom... :slight_smile:

mullenba:
I'm trying to teach myself electronics and Arduino. I thought I would make a programmable constant voltage source that I can maybe turn into a battery charger at some point. I figured there would be a lot of challenges to learn along the way. Anyway, the Arduino is outputting a 50% PWM signal to hopefully step down the voltage by half. However, when I breadboard the circuit, I get the full source voltage. I'm not sure why. Trying to test, it seems like I have something wrong with the IRL7833 MOSFET that's switching the high side P-Channel IRF9540N MOSFET, but I can't figure out what I'm doing wrong.

Any help or tips are greatly appreciated.

I see nothing that will turn OFF Q2 when the PWM off cycle occurs. I would try maybe a 100 ohm resistor between your "VCCA" and the gate of Q2.

Also, you depend on the microcontroller for regulation... that's WAY too slow. You should have a closed electronic feedback (regulation) loop and use your PWM to adjust the loop reference.

TomGeorge:
A 10K resistor between gate and source of Q2 should do the trick.
Tom... :slight_smile:

Nope, no chance. You are needing to switch the MOSFET fast, 10k is going to take 10's of microseconds to discharge the gate.

See my posting #6.

MarkT:
Nope, no chance. You are needing to switch the MOSFET fast, 10k is going to take 10's of microseconds to discharge the gate.

See my posting #6.

...and my #9... :slight_smile:

Atmega328p is fast enough for switch mode supply, but it's rather advanced project.
And there are microcontrollers better suited for this purpose.(I have working boost supply on AtTiny861)
Arduino(software stack) is last thing you want in your power supply.
Best beginner approach to power supply with arduino would be taking lm2596 module and replacing potentiometer with:
a) RC servomotor controlled potentiometer
b) electronic (programmable) potentiometer
c) opamp(s) +DAC circuit

It would follow this advice:

DrAzzy:
Beyond the other issues cited above, you cant breadboard switching powersupplies. They are extremely layout sensitive; even a custom designed circuit board requires close attention to the layout to minimize the size of the current loop. The textbook my father (an electrical engineer retired after >40 years doing cutting edge design work, but not power supply design) got when he was trying to understand the matter a few years back described breadboards as "kryptonite" for switching supplies.

Building switching power supplies is something you can start to do by using switchmode supplies based on dedicated switching dc-dc controller ICs by meticulously following the design and layout guidelines in their datasheet, once you are comfortable and experienced designing your own pcbs. Designing the whole thing from scratch and programming the controller is a considerably more advanced subject.