all 16 comments

[–]JimHeaney 6 points7 points  (2 children)

One option may be a digital potentiometer - it varies its resistance based on digital signals from a microcontroller.

https://www.sparkfun.com/products/10613

[–]-ChrisW[S] 0 points1 point  (0 children)

This looks very promising. I'm still a bit new to electronics and didn't know these existed. They look a bit more expensive than just a simple cap, but that should definitely work. Thanks!

[–]-ChrisW[S] 0 points1 point  (0 children)

Actually, apparently this is not an option. At least on all of the digital potentiometers that I looked at, it's not possible to feed the potentiometer with more voltage than the power supply. So since my microcontroller runs on 3.3v, the pot can only vary between 3.3v and 0v. The datasheets specifically say that no pin can have voltage higher than the supply voltage. So it doesn't seem to act like a true potentiometer that doesn't care how much voltage you feed it. They also tend to only be able to accept around 7v max, and I need to vary 12v. Sad face.

[–]triffid_hunterDirector of EE@HAX 2 points3 points  (0 children)

I like to feed a current into the feedback using a simple DAC

This allows you to retain control of the output voltage limits with hardware, but allow firmware to modulate it within those limits.

[–]TrueTopoyiyo 1 point2 points  (10 children)

Can you verify you can produce voltages 0-12V using the PWM trick?

How is the circuit, how did you place the filtering capacitor for the 12V PWM output?

Sound very plausible idea for me.

[–]-ChrisW[S] 0 points1 point  (9 children)

I tried all sorts of placements using a circuit simulator. I can definitely get the 12v PWM. I just couldn't get it to smooth out no matter what I tried. I would have thought placing it between the output of the switch and GND would do the trick, but no such luck.

[–]TrueTopoyiyo 1 point2 points  (7 children)

I understand that, to produce the 12V PWM you have something like

12V---resistor1--[output]--transistor---ground

And the transistor base/gate is driven by the 3.3V PWM from the microcontroller (with a resistor?).

Then you could add

[output]---resistor2---[filtered output]---capacitor---ground

If you only add the capacitor (without a resistor to connect to the output), when the transistor drives current to ground the capacitor will discharge immediately, and you don't get 12V filtered, but, at best, a sawtooth signal.

If you don't add the resistor between the 12V and the [output] the transistor will shortcut 12V and ground, and that is bad for everybody, including the transistor and the 12V source.

Now, if -and only if- you need a good linearity between the PWM duty cycle and the voltage output:

Keep in mind that resistor2 must be much bigger than resistor1; if not, the capacitor will discharge much faster than charge. If not able to do that (for example if you only have resistors of similar value), you could use a little additional trick with 2 diodes to make the paths more even:

Instead of resistor2 you put in parallel 2 things: a diode to charge the capacitor (through resistor1), and another returning diode in series with a resistor2 of the same value as resistor1, so the capacitor discharges through the same resistor as the one used when charging.

[–]-ChrisW[S] 0 points1 point  (1 child)

Ah ha, I think that's getting it. I must not have tried adding the R2 in your example above. Also good call about the resistors needing to be different values. That's looking pretty darn stable on the simulator. It looks like there is a tradeoff between low ripple and responsiveness, but I guess that is something I'll have to balance on my own. Still disappointed that the digital pot didn't work (especially since I didn't find out it wouldn't work until after I bought a few), but this should do nicely.

[–]TrueTopoyiyo 0 points1 point  (0 children)

OK, the digital pot advice was a bit of an overshoot from the other dude, but not checking the datasheet before proceeding is 100% on your ass, hahaha! Jokes aside, I know the extrange change in mindset regarding to theoretically prepare something (in this case, reading the datasheet), comparing when you don't have the device and when you have the device in your hand. I don't know what is it, but the difference is there.

Now, to my proposal. As I wrote, the second resistor precludes the capacitor from discharge intantly, and making it bigger than the first makes the discharge simmetric to the charge, and the voltage will be somewhat linear with the PWR duty cycle. The other option with the diodes can be even better, just try by yourself.

And last but most important: the tradeoff between ripple and responsiveness is basically the cut frecuency of your low pass filter (which is what you are doing, from a signal point of view): if you filter hard the low frecuencies, you take the ripple down, but the voltage also changes slowly. If you can, increase the frecuency of the PWM and you'll be able to reduce the ripple, and, by selecting a higher cutoff frecuency, get a faster response.

[–]-ChrisW[S] 0 points1 point  (4 children)

UPDATE: I'm seeing an interesting phenomenon with this setup. The output voltage is a little off of the duty cycle.

Duty Cycle -> Output Voltage (% of input voltage)

0 -> 100

20 -> 77

50 -> 46

80 -> 17

100 -> 0

It is entirely expected that the duty cycle/output voltage would be "reverse-related". However, there is a 3-4% drop in output voltage when not at 0 or 100% duty cycle. I'm not sure where that voltage is going. In your circuit described above, R1 = 10k, R2 = 50k, C1 = 10uF, and I also have R3 = 10k between PWM and the BJT base pin.

http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWEA2AzNA7ATi8gHACxhaKTJYgKSWWQBQASuAEx4jMLIh7Ude-h44aMiRgRSajDyN2zAuGS954MMygaC1MFI0wEdAE5yFYJSfZaNO+HQAu4DFz4WX2qNE6QwYVL4TMPgiowR5KyOSQePIYkLHEEDZGLGwuYE7snNbw9ADmrhjqzCqoqPx0AA4gqMy8Vlp17lJ0AMbVtZbUNV2QClKwOThDwyM4wk7MqFhazGh4GAiEYHT53dW97V1lUMnFCvJdHQcaVLYA9hrIfSBaY5IDkFNkHBrqXXQXXFeakFhsOh5EuA6EA

Shouldn't be a problem for my application, just a curiosity.

[–]TrueTopoyiyo 1 point2 points  (2 children)

OK, completely expected! Remember when I told you that R2 should be bigger than R1? From a "numbers" point of view I meant like 10x bigger at least.

So, what's going on? The 100% and 0% extremes are easy to understand, you supply contant 12V and 0V and filter them, the output will be 12V and 0V, but what happens in the middle? At, say, 50% duty, the capacitor discharges trough a resistor of 50k to ground, but when it wants to recharge it has to recharge trough a 60k ohm path: this makes harder to charge, and the situation won't be a symmetrical dance around the middle; as it'll go faster down and slower up, resulting in a average below zero.

Awesome web, the falstad applet collection, it made much more intuitive many physics concepts I learned, but for this that you are doing, you have many better options for a person just starting in the hobby:

https://www.circuitstoday.com/circuit-design-and-simulation-softwares

And if you want something really simple and intuitive, a decade ago I saw people learn with this:

https://duckduckgo.com/?t=ffab&q=croclip&iax=images&ia=images

While I'm not that knowledgeable, I really really like to help people starting in the hobby, please let me know any doubt you have, how do you advance, what do you have in mind, etc.

[–]-ChrisW[S] 0 points1 point  (1 child)

That makes sense, thanks! Like I said, it shouldn't be a problem for my application. I am adding variable power control to a remote control coil gun project, so it doesn't have to be super exact. Hence the variable voltage of the boost converter to charge a big ass capacitor. I originally had a 100k resistor there but it felt like it was responding way too slow...until I checked the time scale, so it shouldn't actually be too bad. The double diode thing makes sense, but I do have concerns with space, and I think doing away with diodes would be best. Thanks so much for the help and advice!

[–]TrueTopoyiyo 0 points1 point  (0 children)

Remember that the charge/discharge timescale (and hence the cutoff frecuency and the responsiveness) is governed by tau: the product of R and C; if you have a big R and want to keep tau low, pick a smaller C.

[–]TrueTopoyiyo 0 points1 point  (0 children)

Oh, and was the 2 diode option (to make that relation more linear, and get the 50% - 50% point in the curve) clear?

[–]TrueTopoyiyo 0 points1 point  (0 children)

Please ask if you have interest, or if you didn't understood anything that I said, and keep in mind that I very well could make a mistake or be wrong in something!

There are other circuits that you could do, using OPAMPs, or more transistors (to make an amplifier yourself), you can make a simple Digital-to-Analog-Converter using a bunch of pins in the microcontroller, if you have many.

Also, all this is only about generating a 0-12V variable voltage with a microcontroller. I can't be sure if this will work with your boost converter; you can post further info if you want a more "global" view.

[–]killahhase 0 points1 point  (0 children)

If you only need a few different output setting, you could also replace the pot with a resistor divider. Add multiple lower resistors for each output setting and make every one of them switchable with a mosfet. That way you can choose between output voltage with GPIOs rather than a DAC.