Page 1 of 1

Controlling Voltage

Posted: Mon May 11, 2020 11:39 pm
by mike6216
Is there a way to control the voltage with a raspberry pi without using PWM. Basically, having a 12V DC power cable, be able to change the voltage output and polarity direction using code? What can be used in conjunction with the raspberry pi to achieve this to change voltage directly and does not involve PWM?

Re: Controlling Voltage

Posted: Tue May 12, 2020 6:44 am
by drgeoff
You need a Digital to Analogue Converter (DAC) of which there are other types in addition to PWM.

Re: Controlling Voltage

Posted: Tue May 12, 2020 7:51 am
by Brandon92
mike6216 wrote:
Mon May 11, 2020 11:39 pm
Is there a way to control the voltage with a raspberry pi without using PWM. Basically, having a 12V DC power cable, be able to change the voltage output and polarity direction using code? What can be used in conjunction with the raspberry pi to achieve this to change voltage directly and does not involve PWM?
Why don't you want to use PWM. Are you trying to control a motor? To change the polarity, you need a h-bridge.

By the way, you can add a filter at the PWM output and you have a variable voltage.

Re: Controlling Voltage

Posted: Tue May 12, 2020 11:44 am
by ElEscalador
You can use a digital to analog converter, as mentioned, but that will almost certainly use PWM unless you spend much $$. If you only need a few voltages you could cobble something together with relays to switch a few fixed voltages and polarity. More details of the end goal would be helpful.

Re: Controlling Voltage

Posted: Tue May 12, 2020 3:05 pm
by Rossqwerty
I am in a similar situation. I need to supply 0-10VDC to a voltage controlled pressure regulator and read the voltage from a 0-5 VDC pressure transducer. I hope this works. I've received it but haven't taken it out of the box yet. Anyone tried something like this? At $33 I figured it was worth the risk. Hopefully there is a Python library for it.
Waveshare High-Precision AD/DA Expansion Sheild Board for Raspberry Pi
https://www.amazon.com/dp/B0105DPYNO/re ... ljaz10cnVl

Re: Controlling Voltage

Posted: Tue May 12, 2020 7:24 pm
by boyoh
To change the 12v Dc to different levels ,by just using code , will not be possible, Unless you use controlled switching stages
You want to decide what stages of different voltage levels you want , and at what currents you want. You must work out the
total current you want from each stage , This level must not exceed the total out put impedance ( resistance ) of your main
power supply . I would suggest using over/load protection on the output of you main power supply
You must not connect 12vdc in to the Raspberry Pi , You must only use 5vdc to feed the Pi
.
You could use voltage regulators for the different voltage levels.

If the currents are low you could use Zenner Diodes to give you the different levels. Using research there might be other methods.

Your first step is to understand basic electronics.

Regards BoyOh

Re: Controlling Voltage

Posted: Wed May 13, 2020 8:06 pm
by Rossqwerty
boyoh wrote:
Tue May 12, 2020 7:24 pm
To change the 12v Dc to different levels ,by just using code , will not be possible,
Regards BoyOh
Hey BoyOh
I get your point but not strictly true. There are many 5 Volt USB devices that will provide an analog voltage that you control programmatically. Granted, they are not designed to provide much current, they are just providing a signal voltage. Multifunction DAQmx boards from National Instruments and Measurement Computing have true (not PWM) Analog Outputs (and Inputs). As an example, I use the DAQmx boards linked below to drive the voltage for voltage controlled pressure regulators and read the voltage from pressure transducers. I have been using LabVIEW since 2009 to control this kind of stuff. Now I need to learn Python.
This is a common device for the work I do. Compact Electro-Pneumatic Regulator - https://www.smcusa.com/products/ITV00-C ... tor~160733. I am trying to figure out if I can control this regulator/transducer device with Raspberry Pi and Python in a similar way I do with a Laptop and LabVIEW. I don’t think I can use the NI or MC USB boards but there must be something that will work with the Pi and have a Python library.

Two of the common DAQmx devices I use are:
NI USB-6002 - https://www.ni.com/pdf/manuals/374371a.pdf This is nice because it has an Input and Output range of + 10VDC
Measurement Computing USB-200 - https://www.mccdaq.com/PDFs/specs/USB-2 ... s-data.pdf Analog Input range of + 10 VDC, Output of 0-5VDC

I am just learning the world of Raspberry Pi because I an trying to build smaller more self-contained test fixtures. My electronics skill is very good. My Python programming and Raspberry Pi understanding, not so much.
Thanks,
Ross

Re: Controlling Voltage

Posted: Wed May 13, 2020 10:19 pm
by mike6216
Brandon92 wrote:
Tue May 12, 2020 7:51 am
mike6216 wrote:
Mon May 11, 2020 11:39 pm
Is there a way to control the voltage with a raspberry pi without using PWM. Basically, having a 12V DC power cable, be able to change the voltage output and polarity direction using code? What can be used in conjunction with the raspberry pi to achieve this to change voltage directly and does not involve PWM?
Why don't you want to use PWM. Are you trying to control a motor? To change the polarity, you need a h-bridge.

By the way, you can add a filter at the PWM output and you have a variable voltage.
Yes I am trying to control a 12V DC motor. I tried PWM with l298N but at a low duty cycle of below ~40 the motor does not spin. I tried playing around with the frequency but that does not fix the problem. My project requires the motor to spin at different speeds from the lowest to the highest speed associated with if the voltage was 3V to 12V, so PWM would not work because there is still a wide range of speeds that I need below a duty cycle of ~40 that would've worked if I simply attached a DC power supply and changed the voltage between 3-12V. A solution which includes changing the voltage physically would also not work as I wanted the speed and direction controlled fully through code

Re: Controlling Voltage

Posted: Thu May 14, 2020 12:15 am
by Idahowalker
One can use PWM to control a mosfet to gate power, much like a switching regulator.

One can use a digipot to control a mosfet to gate power, much like a switching regulator.

One will not get rail to rail voltage output.

Re: Controlling Voltage

Posted: Thu May 14, 2020 12:22 am
by emma1997
dupity dup...

Re: Controlling Voltage

Posted: Thu May 14, 2020 12:44 am
by emma1997
Actually both PWM and digital pot are rail-to-rail.

It is the failure of most motors to start at 1/10th or even 1/3rd voltage that is confusing OP. The solution is to understand the concept of impedance, scaling, and offset. Easily implemented with op amp, properly biased transistor, or if frightened by DIY then simple limit translation in software using built-in PWM or just about any DAC hat.

Re: Controlling Voltage

Posted: Thu May 14, 2020 4:28 am
by mike6216
emma1997 wrote:
Thu May 14, 2020 12:44 am
Actually both PWM and digital pot are rail-to-rail.

It is the failure of most motors to start at 1/10th or even 1/3rd voltage that is confusing OP. The solution is to understand the concept of impedance, scaling, and offset. Easily implemented with op amp, properly biased transistor, or if frightened by DIY then simple limit translation in software using built-in PWM or just about any DAC hat.

Sorry for the confusion, I'm not too knowledgeable in electronics but have to complete this project. I am aware that motors don't start at around 1/10th or 1/3rd voltage but at a duty cycle of below ~40, the motor tries to move but all that happens is a loud squealing noise with no movement. I know it is capable of operating because the speed at lets say 42 duty cycle is much higher than the speed I measured when given 4V with DC power supply. Therefore I wanted an alternative to PWM which uses change in voltage output instead of pulsations to achieve the full or most of the range.

Can you explain how to implement a DAC if that is a solution. Would it be used in conjunction with the l298N or alone? Is PWM used in conjunction with DAC or is the DAC used alone? Would additional components (op amp, transistor, capacitor, resistor, etc) be needed if DAC is used, and if so which ones, what values and how are they supposed to be connected to the rest of the setup. Can someone walk me through the setup please?

Re: Controlling Voltage

Posted: Thu May 14, 2020 5:21 am
by emma1997
I have considerable experience with most motor types, ac/dc, brushed/bldc, big/tiny, and had suggestions.

Using variable DC voltage will waste thousands of times more power as heat compared to PWM. Expensive and bulky linear power amp with huge heatsink needed instead of simple transistor. Probably have to feed it a PWM signal anyway or use a DAC. Neither replaces the power drive circuit.

An L298N h-bridge (or single tiny transistor) even with no heatsink will have no trouble using PWM.

Either way for stable control due to mass and inertia motors need quite a boost for the first few milliseconds to get started. For smooth startups software needs to account for this. Big motors with feedback as in ebikes and cars need sophisticated algorithms like PID etc. Smaller brushed motors generally only need short increase in voltage to get going then behave better.

So a dynamic task, not just setting volts and thinking it will immediately go to that speed and stay there. Specially with varying loads where controlled operation needs optical or magnetic tach feedback which is easier to implement with PWM.

All depends on how fancy you want to get. No matter what linear will be more costly, complicated, and clunky compared to PWM switcher.

(Note to self: check to see if my PWM stock investments have increased on Wall St. lol)

Re: Controlling Voltage

Posted: Thu May 14, 2020 8:47 am
by Brandon92
mike6216 wrote:
Wed May 13, 2020 10:19 pm
Brandon92 wrote:
Tue May 12, 2020 7:51 am
mike6216 wrote:
Mon May 11, 2020 11:39 pm
Is there a way to control the voltage with a raspberry pi without using PWM. Basically, having a 12V DC power cable, be able to change the voltage output and polarity direction using code? What can be used in conjunction with the raspberry pi to achieve this to change voltage directly and does not involve PWM?
Why don't you want to use PWM. Are you trying to control a motor? To change the polarity, you need a h-bridge.

By the way, you can add a filter at the PWM output and you have a variable voltage.
Yes I am trying to control a 12V DC motor. I tried PWM with l298N but at a low duty cycle of below ~40 the motor does not spin. I tried playing around with the frequency but that does not fix the problem. My project requires the motor to spin at different speeds from the lowest to the highest speed associated with if the voltage was 3V to 12V, so PWM would not work because there is still a wide range of speeds that I need below a duty cycle of ~40 that would've worked if I simply attached a DC power supply and changed the voltage between 3-12V. A solution which includes changing the voltage physically would also not work as I wanted the speed and direction controlled fully through code
Oke it should work. What is the type of motor you are using, what is is power. It could be that the l298n is not the best solution for you. It has a reasonable high resistance when it is on.

Re: Controlling Voltage

Posted: Thu May 14, 2020 12:54 pm
by LTolledo
maybe this setup may be applicable to your requirement?
LM317-voltage-regulator-digitally-selected-output.png
LM317-voltage-regulator-digitally-selected-output.png (21.77 KiB) Viewed 487 times

Re: Controlling Voltage

Posted: Thu May 14, 2020 8:29 pm
by Brandon92
mike6216 wrote:
Wed May 13, 2020 10:19 pm
My project requires the motor to spin at different speeds from the lowest to the highest speed associated with if the voltage was 3V to 12V, so PWM would not work because there is still a wide range of speeds that I need below a duty cycle of ~40 that would've worked if I simply attached a DC power supply and changed the voltage between 3-12V. A solution which includes changing the voltage physically would also not work as I wanted the speed and direction controlled fully through code
Coming back to this.
I you successfully make a variable power supply that regulate the voltage from 3V to 12V. This this setup will not work. Because the L298N is not suitable for this. The first reason is that the minimum supply voltage for the L298N to operate is 5.8V in your application.

And the other imported specification of the L298N is VCEsat. Lets say that your motor wil consume 1A. Then the voltage drop in the h-bride inside the L298N between 1.8V to 3.2V. So if you supply it with 12V, (at worst case) the motor only will see 8.8V (at 100% duty cycle). So when you supply the L298N with 6V, it could drop to 3.4V across the motor (at 100% duty cycle).

So it is important that we have more Information about your setup. It is also important that you use the correct cables and things like that.

Re: Controlling Voltage

Posted: Fri May 15, 2020 6:05 am
by mike6216
Brandon92 wrote:
Thu May 14, 2020 8:29 pm
mike6216 wrote:
Wed May 13, 2020 10:19 pm
My project requires the motor to spin at different speeds from the lowest to the highest speed associated with if the voltage was 3V to 12V, so PWM would not work because there is still a wide range of speeds that I need below a duty cycle of ~40 that would've worked if I simply attached a DC power supply and changed the voltage between 3-12V. A solution which includes changing the voltage physically would also not work as I wanted the speed and direction controlled fully through code
Coming back to this.
I you successfully make a variable power supply that regulate the voltage from 3V to 12V. This this setup will not work. Because the L298N is not suitable for this. The first reason is that the minimum supply voltage for the L298N to operate is 5.8V in your application.

And the other imported specification of the L298N is VCEsat. Lets say that your motor wil consume 1A. Then the voltage drop in the h-bride inside the L298N between 1.8V to 3.2V. So if you supply it with 12V, (at worst case) the motor only will see 8.8V (at 100% duty cycle). So when you supply the L298N with 6V, it could drop to 3.4V across the motor (at 100% duty cycle).

So it is important that we have more Information about your setup. It is also important that you use the correct cables and things like that.

So looking back at my recorded data, at 100% duty cycle using the L298N with 12V inputted the output voltage is about 10V so it makes sense that below 30% duty cycle it wont work. However I tested the same thing with a L9110S which is rated for 2.5-12V and at 100% duty cycle the output voltage is about 11.3V so it should function at a duty cycle below the L298N but it still does not function under a duty cycle of 30% just like the L298N. Two things confuse me: 1. When set to a duty cycle of below 30% the motor squeals but does not move, however when given voltage from an immediate DC power supply at a voltage lower than allowed (lets say 1 or 2V) it simply does not turn with no squealing and 2. When experimenting within a duty cycle around 30% (~25 - 40%), sometimes the motor will squeal and not spin at a specific duty cycle and frequency and sometimes it will spin at that exact duty cycle and frequency, so why is that it does't work sometimes at the same values? So the ultimate question is can this be solved to allow use at slightly lower duty cycles, and if not how can a DAC be used in this situation? Thanks

I was using the setup below except that the 12V 5A power supply used goes into a 1 to 2 barrel splitter, one going to the L298N as shown and the other going into a 12V to 5V step down module to power the pi. It is good to note that when supplying voltage to the motor directly with DC power supply, the motor did not need more than 0.8A current with any voltage 0-12V. I used 24 gauge wires for the motor, 18 gauge wires for the power supply, and 28 gauge jumper wires for pi connections. With the L9110S I used 24 gauge wires for the motor and 28 gauge jumper wires for everything else.

Image

Re: Controlling Voltage

Posted: Sun May 24, 2020 12:38 pm
by Brandon92
Sorry for the late reaction.

Okay good to here that your measurements are the same that what is stated in the datasheet of the driver IC. The motor need to have a x amount of "on time" (the on time is the x seconds that the PWM signal is high.) so that it can turn and if not it wil make only some noise.

The L9110S might be on the small size for your motor if you measured it will take 0.8A. Because the inrush current will be probably a lot higher that that value. And your setup looks good.

Another way is to use a gear box to decrease the speed of the motor.

Coming back to the "on time" what is previous talked about. You could drive the motor driver with a different PWM signal. But this requires a bit more software and its a bit harder to do. The idea is that you use a normal PWM to lets say 45% duty cycle with a fix frequency. Then you fix the on time that is the best for your motor. Then you decrease the frequency but the on time stays the same. So you need to adjust the frequency and the duty cycle at the same time. In this way you give the motor enough time to turn and when you decrease the frequency the motor will decrease the speed.

I hope this makes al sens.