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.
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.
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.
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:
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.
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.
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.