Bukit Mertajam, Penang

Using MDD10A with CIKU

1

Introduction

MDD10A stands for Motor Driver Dual Channel 10(Amps). This DRIVER is the dual channel version of MD10C, designed to drive 2 brushed DC motors with high current of up to 10A each, continuously. Just like MD10C, MDD10A can be controlled with two different methods: locked-antiphase and sign-magnitude PWM control. It also only uses solid state components which results in faster response time and eliminates the wear and tear of mechanical relays.

What is CIKU?
CIKU is an embedded circuit running on PIC18F4550 based on Arduino form factor, so it has identical the side female headers, pin assignments, 5V, 3.3V, Reset and GND with the Arduino UNO. Furthermore, to provide the feel of Arduino environment, we are developing library for CIKU with MPLAB X IDE and XC8 Compiler (both are free IDE and compiler from Microchip). Common commands such as pinMode (1, OUTPUT) and analogRead(A1) are all available in the library. It is not yet 100% software compatible, but we are trying to minimize the transition effort needed. The library is open source and we welcome everyone to contribute in its development, any form of feedback is more than welcome!

If this is the first time you encounter the CIKU, please click here to get started! If you’re interested in controlling this motor driver with an Arduino, we have a tutorial on that too.

What is PWM & DIR?

PWM” stands for Pulse Width Modulation which means varying or modulating the pulse width (duty cycle and not period). 

pwm

The figure above shows an example of PWM signal. Note that the frequency and the period is constant. Only the ON time and the OFF time pulse (duty cycle) varies. The higher the duty cycle, the longer the ON time, which means higher power will be transmitted to the load. For example, if the PWM signal is 12V. At 75% duty cycle, 9V is delivered to the load.

On the other hand, “DIR” is a digital 2-level signal. When at HIGH state, the motor rotates in one direction whilst at LOW state, the motor rotates in the opposite direction. Of course, both DIR pin, and the PWM signal are needed to enable the motor to rotate 🙂

How does MDD10A work?

Basically, MDD10A is a siamese twin of a MD10C motor driver. It has 2 separate PWM ports (PWM1 & PWM2) and DIR ports (DIR1 &DIR2). Most of the basic feature of a MDD10A motor driver are similar to a MD10C motor driver. So, people might ask:

Why do you want create a dual channel motor driver? I can just use 2 motor drivers to drive 2 motors.

Yes, indeed you can but most people tend to be careless when setting up a common GND. If there is no common GND, the motor driver might take the voltage from the microcontroller and glitch out, so Cytron has come up with this design to ease your work. You can use it as a mono-channel motor driver or a dual channel motor driver. Plus, MDD10A is cheaper compared to 2 x MD10C. If you would like to see a tutorial on how to use the MD10C motor driver, please click here.

One of the features I would like to highlight is its support for sign-magnitude and locked anti-phase PWM signals.

  • Sign-magnitude mode

In this mode, you need to use 2 separate signals to control the motor. One is a PWM signal, its duty cycle determines the speed of the motor. The other is a constant current that determines direction of rotation of the motor.

  • Locked anti-phase mode

In this mode, only 1 signal  is required to control the speed (PWM pin) and direction of the motor (DIR pin). The magnitude pin that previously controls the speed of the motor in the sign magnitude mode is always at HIGH state, while the direction pin is fed with PWM signals. There are 3 cases over here:

– When the duty cycle is <50%, the motor rotates from the highest speed and goes gradually slower

– When the duty cycle is 50%, the motor comes to halt.

-When the duty cycle is >50%, the motor starts to rotate in the opposite direction until the max speed.

The good news is that you can always set the PWM’s duty cycle to 50%, to bring the motor safely to (almost) a halt without causing your battery to charge or raising the supply voltage to dangerous levels.

The bad news is that you have no control over how long it will take the motor to stop, so while electrically this might sound a safe choice, mechanically it is a completely different story. On top of that, if there’s external torque applied to the motor, simply centering the PWM and not providing torque will not stop it (Eg: You will not be able to stop a car rolling down-hill by simply taking your feet off the pedal). Besides that, locked-antiphase mode has lower efficiency then PWM, which results in the motor heating up more. This is because the AC component of the result of low-pass filtering is higher than sign magnitude PWM, because the rate of decay of the current is higher.

(source taken from http://www.modularcircuits.com/blog/articles/h-bridge-secrets/lock-anti-phase-drive/)

Objective: At the end of this tutorial, you should learn the following:-

1. How to connect the motor driver to the motors and to CIKU.

2. Control the motors using sign-magnitude mode and locked anti-phase mode using programming, potentiometer and switches.

Components needed:

Mode 1: Sign-magnitude mode

NOTE: PLEASE READ!!!! While you are setting up:

  • Please make sure that the pwm 1 and pwm 2 pins of MDD10A are connected to the CIKU’s digital PWM pins 5 and 6:

10587-600x800

  • The diagram below shows the pin connection of the switch and its size.

DSC00285

  • Bonus knowledge: Do you know how to choose the correct motor for your project? Have you ever wondered what the words written on the motor mean? See the “Model: SPG30-300K”? It is not just a model name. “SPG30” represents the size of the motor. “300K” is known as the gear ratio. This means that 1 rotation of the motor output shaft requires 300 spins inside the motor. Meanwhile “12RPM” meaning there is 12 Rotation Per Minute whilst “1176mNm” represents the torque value. If you run this motor with a 12V power source, you will notice that the rotation is very slow compared to any motor with a smaller gear ratio, such as the SPG30-30K model.

DSC00309

  • Make sure that the terminals of the power supply to the motor driver are connected properly to avoid damaging the motor driver. MDD10A does not come with polarity protection.
  • Remember to connect the GND pin on the motor driver, GND pin on the CIKU and the negative terminal of the power supply to a common GND. Otherwise, the motor will not function optimally.

(a) Controlling the motor speed with program

Set up

tutorial2ciku_bb

Program

#include "Arduino.h"

//define pin name
#define dir_1 7
#define pwm_1 6
#define switch_1 13
#define switch_2 12
#define dir_2 4
#define pwm_2 5
#define pot A1 //potentiometer

void setup(){
//declare pins as INPUT/OUTPUT
pinMode(pwm_1,OUTPUT);
pinMode(dir_1,OUTPUT);
pinMode(pwm_2,OUTPUT);
pinMode(dir_2,OUTPUT);
pinMode(pot,INPUT);
pinMode(switch_1, INPUT);
pinMode(switch_2, INPUT);
Serial_begin(9600); //I am using Serial Monitor instead of LCD display
}
void loop(){
int pwm_value;
for (pwm_value=0;pwm_value<=1023;pwm_value++){
digitalWrite(dir_1,digitalRead(switch_1)); //controls the direction the motor
digitalWrite(dir_2,!digitalRead(switch_2));
analogWrite(pwm_2,pwm_value); //increase the speed of the motor from 0 to 1023
analogWrite(pwm_1,(1023-pwm_value)); //decrease the speed of the motor from 1023 to 0
Serial_printString("PWM:");
Serial_println();
Serial_write(pwm_value); //Display the value of PWM
Serial_println();
delay(100);
}

while(1) continue; //terminate the program
}

Code overview

  • Over here, I am using #arduino.h library to use the Arduino compatible commands. As mentioned, CIKU can be used as Arduino compatible. To use the arduino commands, we have to include this library.
  • Another distinct difference was the command used for serial monitor is different. In Arduino, we use “Serial.begin” command but in CIKU, “serial_begin” command is used instead.
  • Other than that, you noticed that the codes are almost similar to the Arduino version.

(b) Control the speed of the motor by potentiometer

Set up

tutorial2ciku2Program

#include "Arduino.h"

//define pin name
#define dir_1 7
#define pwm_1 6
#define switch_1 13
#define switch_2 12
#define dir_2 4
#define pwm_2 5
#define pot 1 //potentiometer

void setup() {
// put your setup code here, to run once:
pinMode(pwm_1,OUTPUT);
pinMode(dir_1,OUTPUT);
pinMode(pwm_2,OUTPUT);
pinMode(dir_2,OUTPUT);
pinMode(pot,INPUT);
pinMode(switch_1, INPUT);
pinMode(switch_2, INPUT);
Serial_begin(9600); //I am using Serial Monitor instead of LCD display
}
void loop() {
// put your main code here, to run repeatedly:
int pwm_value=0;
int reading=0;
int prev_reading=0;

//controls the direction the motor
digitalWrite(dir_1,digitalRead(switch_1));
digitalWrite(dir_2,!digitalRead(switch_2));
//controls the speed of the motor
for (int i=0;i<5;i++) //gets the average value of the pot value for better accuracy
reading+= analogRead(pot);
reading/=5;
analogWrite(pwm_1,reading);
analogWrite(pwm_2,reading);
Serial_printString("PWM:");
Serial_write(reading); //Display the value of PWM
delay(100);
}

Code overview

  • In ARDUINO, “analogRead(pin)” command gives 10-bit value but “analogWrite(pin,value)” gives 8-bit value. Therefore when we need to transfer the data to the motor driver, we have to convert the 10-bit value to 8-bit value.
  • In CIKU, both “analogRead(pin)” and “analogWrite(pin,Value)” gives 10-bit value. So, we do not need to do any conversion.

Mode 2: Locked anti-phase mode

(a) Controlling motor speed by program

Set up

tutorial2_bbciku1

Program

#include "Arduino.h"

// define pin name
#define pwm_2 4
#define pwm_1 7
#define dir_2 5
#define dir_1 6
void setup() {
pinMode(pwm_2, OUTPUT);
pinMode(pwm_1, OUTPUT);
pinMode(dir_1, OUTPUT);
pinMode(dir_2, OUTPUT);
Serial_begin(9600);
Serial_printString("DIR");
}

void loop() {
int pwm_value = 0;
int opposite_i;
digitalWrite(pwm_1,HIGH);
digitalWrite(pwm_2,HIGH);

for(int i=0;i<=1023;i++){
analogWrite(dir_1,i);
opposite_i=1023-i;
analogWrite(dir_2,opposite_i);
delay(120);
Serial_write(i);
Serial_println();
}
while(1)
continue;
}

Code overview

  • The coding concept is the same as the pervious ones. The only changes made are the pwm_1 and pwm_2 pins are set to HIGH state at all times whilst the dir_1 and dir_2 pins are connected to digital pins with PWM i.e. pin 6 and 5. Basically, I just switched the position between the dir and pwm for motor 1 and 2.
  • Initially, the dir_1 has 0% duty cycle whilst dir_2 pin has 100% duty cycle but both still rotate at the same direction at maximum speed.

(b) Controlling motor speed by potentiometer

Set Up

tutorial2ciku_bb2

Program

#include "Arduino.h"

#define pwm_2 4
#define pwm_1 7
#define dir_2 5
#define dir_1 6
#define pot A1

void setup() {
// define pin name
pinMode(dir_1, OUTPUT);
pinMode(dir_2, OUTPUT);
pinMode(pwm_1, OUTPUT);
pinMode(pwm_2, OUTPUT);
pinMode(pot,INPUT);
Serial_begin(9600);
}

void loop() {
int reading = 0;
int output=0;
int opposite_output=0;
digitalWrite(pwm_1,HIGH);
digitalWrite(pwm_2,HIGH);

for (int i=0;i<5;i++)
reading+= analogRead(pot);
output=reading/5;
opposite_output=1023-output;
analogWrite(dir_2,output);
analogWrite(dir_1,opposite_output);
delay(30);
Serial_printString("DIR");
Serial_println();
Serial_write(output);
}

Code overview

  • Similarly, the analogRead(pin) command is used to read the values from the potentiometer while the anlaogWrite(pin,value) command is used to assign the values to the pin stated.
  • The codes for the lock anti phase mode is similar to the sign magnitude mode. The only change is that the DIR pins are connected to PWM digital pins on the CIKU.
  • On the other hand, the pwm pins on the motor driver are always at HIGH state.

To learn how to compile the code and upload the program, please click here.

  • After downloading the library file, open the file in MP LAB IDE X and add these source files to compile and upload the code.

In the zip folder:

Signed-magnitude mode

1. Controlling motor with program — motor1.c

2. Controlling motor with potentiometer — motor2.c

Locked anti-phase mode

1. Controlling motor with program — motor3.c

2. Controlling motor with potentiometer — motor4.c

 I hope you find this tutorial useful! If you have any question, please feel free to post it in our forum! If you feel that this tutorial is helpful, please let me know at the comment section below! Thank you! 😀

Related Posts

Leave a comment

Get 7 Tips for Developing Electronic Projects
We respect your privacy.
Loading...