Speed control with DC Motor w/ Encoders PID Control L298N Driver
88 views (last 30 days)
I am trying to use Simulink/MATLAB to create a PID control with feedback to control the speed of a DC Motor. The DC Motor has two encoder outputs which is what's confusing me (Motor Link). I know that the encoders are for feedback but I'm uncertain about where these pins go. I'm also using an L298N Driver for PWM. I also have an Arduino Mega, which I'm not entirely sure if I'll need? I think I might need the Mega for the encoders but I'm hoping to only use one arduino component so are both an L298N and Mega necessary? Or does having both make the speed control much easier? How might the block diagram look in Simulink for the PID control with feedback from the encoders? Any resources and tips would be appreciated.
Akshay Khadse on 28 Mar 2019
Edited: Akshay Khadse on 28 Mar 2019
As per my knowledge, this motor contains a two channel quadrature encoder which has four connectors and the remaining two connectors are for the motor supply. In the following image, pins Motor+ and Motor- are for connecting motor supply voltage source while Sensor Voltage + and Ground is for connecting sensor input voltage. However, please note that the Motor- and Ground should not be connected together. The output can be sensed from pins Channel A and Channel B. This output will be in form of pulses.
In your Arduino program, you must maintain a counter variable because such incremental encoders don't provide an absolute value of angle or speed. You will need to poll these two channels and decide wether to increment or decrement the count. The calibration of this count would depend on the specifications of the encoder. Please read the following pages for more information on operation of encoders:
You can use a HCTL 2022 decoder IC to avoid this procedure and directly read the angle values. This will save you computational overhead but make the circuit more involved. Please refer the image attached to this post for circuit diagram from one of my projects.
Regarding the hardware requirements, you will need L298N to drive the motor and an Arduino Mega to implement a PID controller. Optionally, you may want to use an appropriate decoder IC.
Pradeep KS on 10 Apr 2019
In 19a release, there is a new block in Simulink Arduino support package to handle the Interrupts on the Arduino pins. Refer https://www.mathworks.com/help/supportpkg/arduino/ref/externalinterrupt.html for more details on how block works.
A reference example is given in the below link:
For your case, you need to connect Encoder Channel A and Channel B to 2 digital input pins on the Arduino hardware which supports Interrupt mode.
In the External Interrupt block, select the Digital input pin number and the triggerring mode (Rising or Falling). Connect the Interrupt block output to a function call subsytem which increments the counter every time you get a pulse from the Encoder.
More Answers in the Power Electronics Control