Help with circuit to emulate a DC motor's current draw through micro-controller

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
Hi i'm engineering student and am very new to circuits, as in I haven't taken any circuits courses yet. I'm familiar with the very basics of circuits and programming and would like to see if any one could give me some ideas to how to approach this. My goal is to emulate a DC motor by using whatever means to create a circuit that has a variable resistance that can be micro-controlled with the raspberry pi. The idea is that if I can change the resistance through the pi I can emulate the current draw of the DC motor. For example when it starts up it has a huge current spike of then levels off, and if it has variable loads I can account for that with a current oscillation all by programming it on the pi. I'm thinking that I should use PWM and transistors to accomplish some sort of variable resistance but am not really sure if this would be the best or simplest approach. I would very much appreciate any ones input on this project that could help me get going.
 

Reloadron

Joined Jan 15, 2015
7,218
If you want to emulate or simulate a DC Motor Current to a Rasberry Pi I can tell you how I would go about it. The Rasberry Pi cannot read an analog signal like a motor current directly but you can add an ADC (Analog Digital Converter) very easily. I suggest you give this a read. I would run a DC Voltage into the ADC and read it. I would just use a simple potentiometer with the wiper output into the ADC. To simulate the motor start current I would either use a push button across my potentiometer or work it into my code which is reading the ADC.

The motor would have a low resistance current shunt inline on the low side. The shunt output gets amplified and the voltage scaled to be proportional to actual motor current. To simulate this I would just run a pot wiper out into an ADC and use the Rasberry Pi to read the ADC.

Ron
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
I guess I wasn't very clear on what exactly it is that I want to accomplish. I think, and correct me if i'm wrong, what you are saying is to use a pot to vary the resistance and therefore the current draw and to feed that into an ADC so that the Pi can read the current i'm generating. What i'm trying to do is have the Pi be able to to control the draw of current from some constant voltage source. I would then be able to set my desired draw based on the characteristics of some motor through a program. I want the circuit to be able to handle the initial voltage draw of the desired motor, let's say 400 mA. So in the end if I could somehow get a current over time reading of the circuit it would look like a classic graph of the current draw of a DC motor where it goes from zero, spikes and then levels off when it reaches its operating speed.
 

Reloadron

Joined Jan 15, 2015
7,218
What I was suggesting is that a Rasberry Pi does not have or allow for an analog I/O (Input Output) Using a potentiometer with one end at 5 volts and the other at common ground the wiper will vary 0 to 5 volts. That would simulate a current shunt sensor as to the motor's current.
What i'm trying to do is have the Pi be able to to control the draw of current from some constant voltage source.
Then you want a circuit similar to that posted by ronv. The DioA is simulating a ramping up voltage and the circuit output is current. In this case the DioA (V1) would be replaced by a D/A (Digital to Analog Converter). The Rasberry Pi generates a signal to the D/A which generates a voltage proportional to the digital input. That voltage is converted into a current. You can build or buy the current source. Calex makes a current source I used quite a bit. The Model 930 is a programmable current source that provides an output current that stays constant with changes in load impedance. Others also make a canned solution. Either way the Rasberry Pi can't handle Analog Input or Output so you will need a converter out there of some sort.

Ron
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
I think you could do something like this:
View attachment 128295
You will need a DtoA converter for your PI.
https://www.abelectronics.co.uk/p/74/ADC-DAC-Pi-Zero-Raspberry-Pi-ADC-and-DAC-expansion-board
Pardon my ignorance ronv but what exactly is that component(s) labeled U2 and STP80NF12. Also my final goal is to be able to connect this circuit up to a system that drives a motor and reads the current it is drawing. In the system the motor is only connected by its two red and black wires, positive power and ground. An alternative circuit measures the current draw. The idea is to trick the system into thinking it has a motor running and to feed the system data about the current that I determine by coding it on the pi. Would this circuit work for that?
 

Reloadron

Joined Jan 15, 2015
7,218
If you want to actually measure a motor current the easy turn key solution is to just buy a current sensor like this one. This entire ready made board is available from Spark Fun Electronics using the ACS 712 current sensor. That gets you 0 to 5 Amps with everything done. You have a few pots on the board for scaling.

Next, the Rasberry Pi does not have any analog inputs so whether you sense actual current or wish to simulate current you will need an analog input between your Rasberry Pi and the source. Nothing actually measures current but rather a current is converted to a voltage which is proportional to the current. A simple Google of "analog input to raspberry pi" will bring up a dozen hits with most suggesting an Analog to Digital chip like the MCP 3008 from Microchip.

Teaching the Raspberry Pi how to read analog inputs is easier than you think! The Pi does not include a hardware analog-to-digital converter, but an external ADC (such as the MCP3008) can be used, along with some bit banged SPI code in Python to read external analog devices. You may want to read this link. You may find this chip on a pre made experimenter board like the ACS 712 above. There isn't much to it. The Analog to digital converter is a 10 bit device so you get a bit count of 0 to 1024 bits proportional to the input.

I guess Python is popular with the Rasberry Pi and while I don't know Python things in your code would go a little like this:

An input to your A/D converter might be for example 0 to 5 Volts which represents 0 to 1.0 Amp of current. With the A/D it becomes 0 to 1023 bits = 0 to 1.0 Amp so we could say:
AnalogIn/1023 = Some number & "Amps".

For example if my current was 500 mA my analog input voltage would be about 512 bits so ...
512/1023=0.5 Amp

Now if we eliminate the current sensor and only want to simulate current in this example all we need is a potentiometer, for example a 10K pot.
0  to 5 Volt Pot.png

So we can place a current sensor out front or a simple pot. You write your code to read the A to D but regardless you need an A/D converter in front of the Rasberry Pi. If you wish some room and resolution I would use a 10 Turn 10K Ohm pot.

Ron
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
So to clarify, the only thing the DtoA converter accomplishes is taking my 3.3 V Raspberry Pi signal and allow me to out put what ever voltage between 0 V and 3.3 V based on what ever resolution the DtoA component has? for instance Reloadron was giving 1024 bits as an example. Then that OpAmp boosts that signal that the Pi would output and run it into the gate of the MOSFET to boost the current running between the drain and the source? So I could control the current draw through the MOSFET with control from the Pi? Thanks for all your information Reloadron and ronv.
 

ronv

Joined Nov 12, 2008
3,770
So to clarify, the only thing the DtoA converter accomplishes is taking my 3.3 V Raspberry Pi signal and allow me to out put what ever voltage between 0 V and 3.3 V based on what ever resolution the DtoA component has? for instance Reloadron was giving 1024 bits as an example. Then that OpAmp boosts that signal that the Pi would output and run it into the gate of the MOSFET to boost the current running between the drain and the source? So I could control the current draw through the MOSFET with control from the Pi? Thanks for all your information Reloadron and ronv.
You've got it right.
The STP80NF12 is a NFET transistor. You don't need one so large, so before you start we should nail down the maximum current you want to draw from the supply and size it accordingly.
 

Sensacell

Joined Jun 19, 2012
3,257
In what context do you intend to use this device?

If the goal is to truly emulate a DC motor, we need to emulate the back-EMF voltage, and winding inductance.
A bit more complex than just controlling a current sink.
 
Top