MC2A

From Curuxa

MC2A

Motor controller module. It can power two independent DC motors in both directions up to 1A.

If you are using low-power DC motors (less than 600mA) at the same voltage as the rest of your circuit (usually 5V), you might be interested in MC2B, the simplified version of MC2A.

Contents

Electronic circuit

Bill of materials:

  • 1x L293B or L293NE
    • Do NOT use L293C, L293D or any other model
  • 1x 16 PDIP socket
  • 8x 1N4148
  • 1x Jumper
  • 16x Straight male headers (usually sold as 40-pin strips)
  • 20-22x Straight female headers (usually sold as 40-pin strips)
  • 1x 56nF ceramic capacitor
  • Some thin wire
  • Some heat shrink tubing

Also, you have to build its PCB.

Schematic
Layout: top view

Printable version: One per page (A4), Two per page (A4)

Printable layout (required for building the PCB): One per page (A4) Twelve per page (A4) PNG (its real size is W=33.274mm, H=28.448mm)

Wiring

Wiring
This module has multiple inputs and outputs:
  • A -> Motor 2 digital bits
  • B -> Motor 1 digital bits
  • C -> Main power supply. Pin 1 can be 4.5-7V. Pin 2 is Ground
  • D -> Optional motors power supply. If you want to power the DC Motors from a different power supply or at a different voltage, you can use these pins. If you prefer to power the entire circuit (electronics and motors) from the same power source (the Main Board) leave them disconnected
  • E -> Power selection jumper. If you want to power the DC Motors from a different power supply or at a different voltage, leave this disconnected. If you prefer to power the entire circuit from the same power source, put a jumper here. It will short-circuit both power supplies.
  • F -> Connect it to Motor 1
  • G -> Connect it to Motor 2

How it works

This module can control two DC motors up to 36V, 1A each. Each motor is controlled from the microcontroller using 3 digital pins.

Motor 1/2 digital bits are the data lines used to control both motors from the microcontroller:

  • Pin 1 -> Enable bit. When the enable bit is "1" the motor will receive power. In the other case, the motor will spin freely.
  • Pin 2, 3 -> Input bits. Motor will turn in one or the other direction depending on Pin 2 and 3 values. If both pins are set at the same digital value the motor will be braked electrically

More information can be found in the L293B datasheet.

Construction

MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A MC2A

Test

The following code can be compiled using SDCC.

/*==================================================================
* Sample program for MC2A using MBP18
*
* Motor 1 begins moving forward, then backwards, then it stops
* and motor 2 begins moving forward, then backwards, then it stops
* and motor 1 begins moving forward...
*
* Note: PIC16F88 runs by default at 31.25kHz (internal oscillator)
*
* http://curuxa.org
*=================================================================*/
 
#include <pic16f88.h>
 
typedef unsigned int config;
config at _CONFIG1 __CONFIG = _CP_OFF & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO;
 
//Pinout
#define M1Enable Rxx
#define M1In1 Rxx
#define M1In2 Rxx
#define M2Enable Rxx
#define M2In1 Rxx
#define M2In2 Rxx
 
//Move motor 1 forward
void M1Fwd(){
	M1Enable=1;
	M1In1=1;
	M1In2=0;
}
 
//Move motor 1 backwards
void M1Bck(){
	M1Enable=1;
	M1In1=0;
	M1In2=1;
}
 
//Brake motor 1 electrically
void M1Brake(){
	M1Enable=1;
	M1In1=0;
	M1In2=0;
}
 
//Motor 1 spins free
void M1Free(){
	M1Enable=0;
}
 
//Move motor 2 forward
void M2Fwd(){
	M2Enable=1;
	M2In1=1;
	M2In2=0;
}
 
//Move motor 2 backwards
void M2Bck(){
	M2Enable=1;
	M2In1=0;
	M2In2=1;
}
 
//Brake motor 2 electrically
void M2Brake(){
	M2Enable=1;
	M2In1=0;
	M2In2=0;
}
 
//Motor 2 spins free
void M2Free(){
	M2Enable=0;
}
 
//Simple delay for an unspecified amount of time
void Delay(){
    long i;
 
    for (i=0; i<200; i++) {
        //do nothing
    }
}
 
void main(){
        //configure data pins as digital outputs
        ANSEL=0;
        TRISA=(edit this);
        TRISB=(edit this);
 
        while(1){
                M1Fwd();
		Delay();
		M1Bck();
		Delay();
		M1Brake();
 
		M2Fwd();
		Delay();
		M2Bck();
		Delay();
		M2Brake();
        }
}
Retrieved from "http://curuxa.org/en/MC2A"