Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

Wiring myDAQ with L298N motor drive to control DC motor

Solved!
Go to solution

Dear community,

 

for a laboratory application, I need to control a DC motor with a computer (on/off/direction of rotation/speed). I have an electric motor from an old stick blender, a NI myDAQ and a L298N H-Bridge motor driver at hand.

 

Unfortunately, I am not an engineer and I don't know how to wire the motor driver with the myDAQ (i.e. which screw terminals of the myDAQ I need to connect with which terminals of the L298N). Due to my ignorance in engineering, my question might lack essential information. I hope not to thereby offend anybody, please feel free to ask for details. Thank you in advance for your kind advice.

 

Esra

0 Kudos
Message 1 of 11
(8,390 Views)
Solution
Accepted by Metazoa

Hi Esra,

 

This isn't hard, I've done this before.  The L298N driver is quite popular in the Arduino and maker community.  The motor from your blender is most likely a DC motor. 

 

You can then look at this guide: https://lastminuteengineers.com/l298n-dc-stepper-driver-arduino-tutorial/ 

 

Basically you want to replace the Arduino with the myDAQ.  If you just want to drive 1 motor, essentially you need 3 digital signals from the myDAQ: 1) Enable, 2) PWM Signal, 3) Dir Signal.  The enable and dir signals should be just simple on/off, you can use myDAQ to toggle these digital output signal.  For outputting PWM, you can check this out: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000x1P0CAI&l=en-US 

 

Hope this helps!

Message 2 of 11
(8,315 Views)

Hi,

 

sorry for the late reply. I just read your answer today; thought I'd get an email notification in case of a reply.

 

Thank you very much that you took your time for explaining these basics and for searching the links!

 

I'll go through them, assemble everything accordingly and will give feedback here in the next days.

 

Esra

0 Kudos
Message 3 of 11
(8,289 Views)

No problem!  Motion control is my specialty.  I did a similar project with myRIO a long time ago, with some Pololu A4988 stepper motor drivers: https://www.youtube.com/watch?v=pdbDDZlHsr0.  Have fun!

0 Kudos
Message 4 of 11
(8,284 Views)

With the help of the links, which you kindly! provided, I have managed to control the direction and the speed of the DC motor with the L298N motor driver connected to myDAQ and Labview.

 

Here is how I got it going:

 

Wiring:

  1. Power Supply with a 9 Volt battery connected to the power supply Pins of the L298N motor driver (- to GND and + to +12V)
  2. DC Motor + and – with L298N outputs „Out1“ and „Out2“
  3. L298N Inputs „IN1“ and „IN2“ with the myDAQ digital Outputs (DIO) „0“ and „1“
  4. Analogue Output (AO) „1“ from MyDAQ with the L298N motor driver Input „ENA“ (there are two pins at the ENA input, I have used the one towards the edge of the plastic board)

MyDAQ:

  1. Control of on/off and direction of DC motor with Digital Writer „NI ELVISmx“ (Part of NI ElvisMx Instrument Launcher)
    1.  „lines to write“ set to „0-3“
    2. Set to "run continuously" and click "Run"
    3. Manual Pattern set to 0=low (LO) and 1=High (HI) for forward spin of DC motor and 1=low (LO) and 0=High (HI) for forward spin of DC motor. If both 0 and 1 are low or high, motor is switched off
  2. Control of Motor speed with PWM
    1. Use of this existing LabView digital pulse train „PWM.vi“ :

https://forums.ni.com/t5/NI-ELVIS-II-and-myDAQ/Pulse-Width-Modulation-PWM-with-NI-myDAQ-or-ELVIS-II/...

  1. PWM.vi generates an analogue output of PWM for controlling the motor speed
  2. Since the ENA input pin of the L298N motor driver is connected with the Analogue Output AO1, the Output of the „Physical Chanel“ needs to be set as „myDAQ1/ao1“
  3. Klick on one of the arrow symbols on the top left of the window to get it running (it's running when the output waveform chart shows waves according to the wave settings)
  4. In order for the speed regulation to work, the „Waveform Type“ needs to be a „Square Wave“
  5. My DC motor works most fluently with an amplitude of 0,5
  6. Speed control is achieved via the „duty cycle“ control bar

 

Metazoa_0-1626258971330.png

 

I hope this is of help for anybody facing the same challenge...

 

 

 

0 Kudos
Message 5 of 11
(8,205 Views)

Very nice! Glad you got it working.

0 Kudos
Message 6 of 11
(8,195 Views)

The control of the DC motor in Labview (solved question from above) is part of a development project of a new laboratory device. With this device, I want to measure the flow of compressed air through a porous material into the atmosphere at a defined (very small) air overpressure of 1 mbar. The final goal is to determine the air-permeability of the porous material at 1 mbar air pressure.

 

The next development step is to automatically set and hold the air pressure in the system at 1 mBar, with a sort of feedback loop between the measurement of air pressure and the control of inflow of compressed air. The DC motor is supposed to control the inflow of air, by pressing and releasing a soft rubber part of the tube through which the compressed air flows. The pressing of the rubber tube is achieved by translating the circular motor movement into a linear movement with help of a Lego linear actuator 🙂 . The air pressure is measured with an electric pressure transducer, which is also connected to Labview via the myDAQ interface.

 

The DC motor is controlled with the myDAQ Outputs DIO 0 and 1 (direction control) and AO 1 (PWM speed control). At the moment I use the NI ELVISmx digital writer for that purpose. The electrical input signal from the pressure transducer is continuously transmitted through the input channel AI 0+. At the moment it is measured with the NI ELVISmx Data Logger.

 

A value of 0 mbar pressure in the system corresponds to -10,7 V. The target value of 1 mbar corresponds to,  let’s say,  -9 V (this is just an example value, because I don’t know the exact value at the moment. I need to measure it with another device in the lab later on).

 

So my question is: How can a feedback loop be created, in which LABview controls the direction and speed of the DC motor as a function of the air pressure signal in Volt with -9 V as a target value?

 

As an example: The target value of air pressure of 1 mbar corresponds to a certain volt value, lets say, -9 V. This signal comes continuously from the AI 0+ input of the myDAQ. When the actual measured Volt value is -10,7 (corresponding to 0 mBar), it means that the control of air flow is far away from the target value, since the tube is closed and no air can flow through. Hence, the DC motor can run with maximum speed (PWM control with AO 1 output) in the direction that opens the tube and therefore increases the pressure, leading to a more positive Volt value (output DIO 0=“high” and DIO 1=“low”). The nearer the Volt value of the continuous measurement comes to the target value of -9 V, the slower the DC motor needs to turn. When the target value ‑9 V is reached, the DC motor needs to stop and keep the same pressure continuously for approx. 1 min.

 

I hope I presented all the necessary specifications. If I have been missing something, please let me know.

Thanks a lot for your help in advance,

 

Esra

0 Kudos
Message 7 of 11
(8,129 Views)

Hi Esra,

 

Look up "PID control loop LabVIEW".  Here's a great tutorial: https://www.ni.com/en-us/innovations/videos/10/building-a-pid-controller-with-your-computer.html

 

This should get you started.  Have fun! 

0 Kudos
Message 8 of 11
(8,115 Views)

Hi RIObotics, thanks a lot for the tutorial! I'll go through it and will then present the results.

0 Kudos
Message 9 of 11
(8,098 Views)

I have gone through the tutorial about PID control. Unfortunately the PID control seems to work only for analogue output (or am I wrong with that?). But my DC motor is controled via a H-Bridge that requires digital output (DIO Lines 0 and 1 set to "high" or "low"). I might control the motor speed (PWM ) with the PID, but first I need to tell the motor in which direction to run at which circumstances.

 

For that purpose the DIO (Digital Output) Lines need to be set as follows: DIO Line 0=“high” and  Line 1=“low” for backwards spin of the motor that opens the tube, when analogue input Value is below the target value of -9 V; and vice versa DIO 0=“low” and DIO 1=“high” for forwards spin of the motor that closes the tube, when analogue input Value is above the target value of -9 V. 

 

In the attachment you find my unsuccessfull block diagram ( "Air permeameter loop control.vi"). I have connected the Analogue Input (DAQ Assistant, called "Analogue pressure Input in V (AI0+)" in my example) with "Greater than" and "Smaller than" operators. Then I have set the comparison  values ("y") to the target value of -9 V. Then I inserted the ELVISmx Digital Writer in the block diagram. But I was not able to control the DO lines of the ELVISmx Digital Writer as described above with the output of the operators "Greater than" and "Less than".

 

If you have an idea about how to get it going, I'd appreciate it if you could also directly illustrate it in the example vi file.

 

Many thanks in advance,

 

Esra

 

 

0 Kudos
Message 10 of 11
(8,088 Views)