Using MDD10A with CIKU

1

Introduction

MDD10A stands for Motor Driver Dual Channel 10(Amps). This DRIVER is the dual channel version of MD10C which is designed to drive 2 brushed DC motors with high current up to 10A each continuously. Just like MD10C, MDD10A also supports locked-antiphase and sign-magnitude PWM control. It is also using full solid state components which result in faster response time and eliminate the wear and tear of the mechanical relay.

I am using CIKU to control the motor driver. CIKU uses MP Lab IDE X compiler whilst arduino has its own compiler, ARDUINO IDE because CIKU uses PIC18F4550.

Don’t you worry! Cytron is always here to make your life easier. Although CIKU utilises PIC microcontroller, we have expanded the library of CIKU to be compatible with arduino (but not FULLY compatible ya 😉 ).

You may download the libaries here. If this is the first time you encounter this product, please click here to get started! 😀

I have done one tutorial on using this motor driver with ARDUINO UNO. Have a look! 😀

What is PWM & DIR?

PWM” stands for Pulse Width Modulation which means varying or modulating the pulse width (not the frequency). This will vary the duty cycle.

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 to enable the motor to rotate, besides the DIR pin, there must duty cycle too 🙂

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 but most people tend to be careless in the setup part of the common GND. If there is no common GND, the motor driver might take the voltage from the microcontroller and will cause weird results. Cytron is always here to make your life easier. Therefore, we have 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. 😀 cool right? 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 feature, though that I would like to highlight is its support for sign-magnitude and locked anti-phase PWM signal. Ever heard of these terms?

  • Sign-magnitude mode

In this mode, you need to use 2 separate signals to control the motor. This is because you need to define the PWM duty cycle and the direction of the motor individually to create PWM (Pulse Width Modulation) signals: one is for the direction of rotation of the motor and the latter is for the speed 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, the mechanical side might tell a different story. On top of that, if there’s external torque applied to the motor, simply centering the PWM drive will not stop it. (You will not be able to stop a car down-hill like that) 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/)

What is CIKU?

CIKU is PIC18F4550 based Arduino form factor starter kit for hobbiyst, student, developer or any maker that likes to use PIC microcontroller and want to utilize Arduino shield. We acknowledge and appreciate the ease of hardware interface provided by hundreds of Arduino shield out there. I am sure PIC lover would like to utilize these shields, and with CIKU, you will have it.

CIKU is born from the experiences of using Arduino and feedback we gather from SK40C users. Ciku comes with PIC18F4550 pre-programed with Microchip USB HID Bootloader and with this, loading program will only require a USB Mini-B cable, no extra programmer is needed. This will lower the cost needed to get start. It reserves the PICkit2/3 6-way ICSP pads for those that like to use ICD or PICkit2/3 to load program.

To utilize Arduino shield, CIKU has been designed based on Arduino form factor, the side female headers, pin assignments, 5V, 3.3V, Reset and GND are compatible with 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). You will be able to use the pinMode(1, OUTPUT) and analogRead(A1) as in Arduino IDE. It is not 100% software compatible, we are trying to minimize the transition effort needed. And it is open source, we welcome and invite everyone that love CIKU to help and contribute in library development, and share it, any form of feedbacks are more than welcome!

OK. Enough of explaining. Let’s do something practical!

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 PWM digital pins. To identify which pin can produce PWM signals:

10587-600x800

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

DSC00285

  • Do you know how to choose the correct motor for your project? Have you ever wondered what these words written on the motor mean? Well, if you do then bravo! If you don’t, don’t worry. I’m here to help you. See the “Model: SPG30-300K” word? 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 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 and the CIKUCIKU 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

[code lang=”c” highlight=””]

#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]

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 used “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

[code lang=”c” highlight=””]
#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]

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

[code lang=”c” highlight=””]
#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]

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

[code lang=”c” highlight=””]
#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]

Code overview

  • Similarly, the analogRead(pin) command is used to read the values from the potentiometer whilst, 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 was 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 Post

Getting Started with Encoder Sensor Module (SN-ENC-MOD)

Getting Started with 3A Motor Driver Shield and Arduino Uno

Peak Current vs Continuous/Rated Current

Raspberry Pi: Line Following Robot

Leave a Reply

Your email address will not be published. Required fields are marked *