DC Motor and Servo motor Control with ARM and Arduino Created by: Andrew Kaler (39345) Tucker Boyd (46434) Mohammed Chowdhury (860822) Tazwar Muttaqi (901700) Mark Murdock (98071) May 4th, 2017
Objective (written by Tucker Boyd) The goal of this semester project was to create a system that uses embedded processors and pulse width modulation (PWM) to control a DC and servo motor. To create this project the following materials were needed: ARM Cortex-M4 Microprocessor Arduino Uno Microprocessor Micro Servo Motor 12V DC Motor Switch Breadboard L298N H-bridge 9V battery Potentiometer Oscilloscope To control either motor, an analog signal will be generated when the shaft of the potentiometer is rotated. That analog signal will determine the duty cycle of a PWM wave generated by either the ARM or the Arduino. If the switch is in position 0, then the PWM of the ARM processor will control the speed of the DC motor. If the switch is in position 1, then the PWM of the Arduino will control the position of the servo motor. In either of these cases, rotating the shaft of the potentiometer will control whichever motor is enabled by the switch. The oscilloscope will be used to verify the PWM signal going to either motors.
Procedure (written by Andrew Kaler) The main steps of this project included both designing the circuit and the code for the processors. To simply focus on either the circuit design or coding was extremely impractical as the designs for both were interdependent on each other. Consequently, there was much collaboration between those responsible for coding and those responsible for circuit design. The results of this collaboration resulted in the following circuit design (Figures 1 and 2) and code for the ARM and Arduino (Figure 3): Figure 1: The physical circuit, including all of the components outlined in the Objectives section (the oscilloscope probes are currently connected in the circuit)
Figure 2: A diagram showing the connections of the physical circuit (Provided by Tazwar)
Figure 3: Code for both the Arduino and ARM mbed. Figure 1 represents the physical circuit actually created, and Figure 2 shows a symbolic depiction of our circuit mainly displaying the connections between the different components. The logic behind the connections of the processors are only apparent when examining Figure 3. As seen in Figure 3, the code compiled on the ARM mbed gave a certain set of inputs and outputs: a PWM output on pin 26 labeled dc, an output on LED1 on the mbed ARM labeled led1, an output on LED2 on the mbed ARM labeled led2, a digital output on pin 28 labeled ins, an analog input on pin 19 labeled pot, and a digital input on pin 20 labeled sw. The code compiled on the Arduino also creates certain inputs and outputs: pin 8 is a designated digital input, A0 is an analogue input, and pin 9 is a designated PWM output wave. When analyzing Figures 1, 2, and 3, the correlation between the circuit and software design becomes evident.
Results (written by Andrew Kaler) In order to control the DC motor, pin 20 on the mbed ARM should not receive a logic high (correlating to position 0 on the switch). If this is the case, then manipulation of the potentiometer controls the DC motor and the brightness of LED1 on the ARM mbed platform (LED2 of the ARM mbed will be off). The potentiometer is connected in our circuit with three terminals: one connected to the 5V output on the H-bridge (pin 6, explained later), one connected to ground, and one connected to pin 19 on the mbed ARM (these are done through common nodes on the breadboard, not direct connections). The potentiometer connection between pin 19 and pin 6 of the H-bridge establishes a voltage divider circuit. By rotating the potentiometer, the resistance of the potentiometer changes and consequently changes the amount of voltage pin 19 receives of the mbed ARM. This value of voltage read into pin 19 will translate to a relative duty cycle of a PWM wave generated from pin 26. For example, twisting the potentiometer fully one way will give a 100% duty cycle, and twisting it fully the other way will give a 0% duty cycle. These two extremes are depicted in Figures 4 and 5 respectively, and Figure 6 shows a PWM with approximately a 50% duty cycle. Figure 4: PWM wave generated by ARM as shown on the oscilloscope. The PWM wave is set to approximately 100% duty cycle.
Figure 5: PWM wave generated by ARM as shown on the oscilloscope. The PWM wave is approximately set to a 0% duty cycle. Figure 6: PWM wave generated by ARM as shown on the oscilloscope. The PWM wave is approximately set to a 50% duty cycle.
This PWM wave is then input to the H-bridge before it reaches the DC motor. There are 7 pins that are used on the H-bridge. Figure 7 outlines the pins on the L298N H-bridge used (note the picture in Figure 7 is a red color, but it is the same chip as the blue version in our circuit in Figure 1): Figure 7: Pins of the L298N H-bridge used for control of the DC motor. Pin 9 of the H-bridge is for the input of the PWM wave from the mbed ARM. Pins 8 and 5 are attached to ground, pin 4 is the 9V input voltage from the Batteries, pin 6 is a 5V output voltage regulator (if pin 4 has between 7V-12V, this feature is available), and pins 1 and 2 connect to the positive and negative terminals of the DC motor respectively. This integrated circuit takes the PWM wave and enables the supply voltage to reach the terminals of the DC motor when the PWM wave is a logic high. For example, when the duty cycle of the PWM is 100% then 9V will supply the motor, and when the duty cycle is 0%, then 0V will supply the motor. Basically, whatever percentage of duty cycle the PWM wave is, this will be the percentage of 9V that is supplied to the motor. For control of the servo motor, the switch must be in position 1. The switch in position 1 gives a logic high to pin 20 on the ARM, and this indicates that the potentiometer will no longer control the PWM wave generated from the ARM. A logic high on pin 20 of the ARM also creates a logic high from pin 28 of the ARM, and this signals the Arduino to take control of the servo motor. In this case, the potentiometer will control the position of
the servo motor, LED1 of the ARM mbed will be off, and LED2 of the ARM mbed will be on. The potentiometer will be connected to the 5V supply from the H-Bridge, ground, and pin A0 on the Arduino (again not direct connections, but through a common node on the breadboard). Similar to its application with the ARM, the potentiometer creates a voltage divider between the 5V supply voltage from the H-bridge and pin A0 of the Arduino. This analogue input signal is then read by the Arduino and translated into an output signal (PWM wave) from pin 9 to control the position of the servo motor. The servo motor is connected by three wires: one is from the designated 5V output of the Arduino, one is to ground (connected from the Arduino board, but the ground is common to the whole circuit), and one is the PWM wave from pin 9 of the Arduino. Rotating the potentiometer will give different duty cycles of the PWM wave as shown in Figures 8 and 9. Note that in this case the PWM wave generated will be incapable of a 100% duty cycle as about a 25% duty cycle was enough to fully rotate the servo motor to 180 degrees. Figure 8: PWM wave generated by Arduino as shown on the oscilloscope. The PWM wave is approximately set to a 0% duty cycle.
Figure 8: PWM wave generated by Arduino as shown on the oscilloscope. The PWM wave is approximately set to a 25% duty cycle. Conclusion (written by Mark Murdock) This project required the interfacing of many different devices and the collaboration of group members working on different parts of the project. Originally we were pursuing a system design using the PIC32 processor. But as we continued to have difficulties getting a PWM wave or any output from the PIC32 s pins, we decided to switch to the ARM Cortex-M4 Microprocessor. We learned during this phase of work on the project just how difficult it is to create truly independent modules as we struggled to obtain a working signal to test the hardware side of the project. Switching to the ARM processor significantly simplified the coding process while still providing good results. We also learned how to pass the output of one microprocessor to another microprocessor when we later added the Arduino into our design. By using the ARM and Arduino microprocessors in the design we also learned how to program some in both platforms. By having started out using the PIC32 we also learned concepts of programming a microprocessor using a non-object oriented language (PIC32 uses C). We also learned how to connect and code a potentiometer to give an analog signal that controlled the duty cycle of the PWM wave produced by the microprocessors. We also saw that the duty cycle of the wave (percent of each period that the voltage signal is high) determines the average voltage supplied by the wave. We also learned how to connect an H-bridge to isolate the higher voltage motor device from the part of the circuit containing the lower voltage microprocessors, as well as to supply a 5V voltage
Discussion (written by Mark Murdock and Mohammed) This project had many different design aspects to it. Most of the designs were very simple and others became difficult, needing a lot of trial and errors to get the system to work. The major problem that the group encountered was attempting to perform this project with the PIC32 microprocessor. The problem with this platform was the low level coding language (C) and the group was not getting the proper PWM output to show on the oscilloscope in the initial output tests. With these problems being very difficult to problem solve the group decided to switch the platform to the Arm processor. The Arm processor had an easier coding language (C++) to work with and the group got an actual PWM waveform from the output of the processor. Our initial approach for the second circuit was to use the ARM mbed for controlling both motors, but this proved to be too much of a strain on the processor. The Arm processor would send the proper signal to the servo motor but this would cause the processor to overheat and shut down. In order to combat this problem, the group attached the servo motor to the Arduino Uno processor to lessen the strain on the Arm processor. This project was a success for what the group was aiming for, but when examining the circuit design and code there can be some improvements and additions to the physical design. Future Work (written by Mohammed) In future work, the speed (RPM) of the dc motor can be measured by Hall effect sensor. In this project, it was tried to build also the feedback system of for the dc motor speed. the plan was to build a feedback system, where the change of speed of dc motor with the change of potentiometer will be shown by the led intensity change from the feedback of hall sensor. Due to faulty sensor, it didn t work. Here a PC fan is used as hall effect sensor is built in there. Arduino mega is used as the microcontroller and led is used to visualize the speed. The plan was the intensity of the led will change with the speed from getting the feedback from hall effect sensor. Below is the image of the fan used here. The yellow line in there gives the analog signal from hall effect sensor. Figure 9: PC fan with integrated hall sensor
A Hall effect sensor is a transducer that varies its output voltage in response to a magnetic field. So, when motor runs the magnetic field change in every turn because of internal magnet of the motor. Hall effect sensor sense the change and generate analog signal. The hall effect sensor input is connected to the analog input port of the Arduino and led is connected with digital output pin and ground. The fan is powered from external power supply. The setup Arduino code, and the Simulink block for the system is given below. Figure 10: Feedback setup of dc motor speed. Figure 11: Simulink diagram for microprocessor.
Figure 12: Arduino code for feedback system