This tutorial covers the details of Driving a motor on the Qorivva TRK-MPC5604B: MPC5604B StarterTRAK evaluation board.
In this exercise students will utilize the sample project to turn a DC motor on an off using the Qorivva TRK-MPC5604B board.
Students will:
To successfully complete this exercise students will need the following board and development environment.
There are several steps in this process:
The first step of this tutorial is to gain background information on background information on motors, timer modules, PWM signals and counters. To learn more about these general topics read the Drive A DC Motor overview article.
You will need to connect your motor to the microcontroller via the Motor Drive board. This board is connected to the battery, and serves to power the motors. separate power source. This is an easy process using the provided Motor Controller Board.
The Freescale Cup Motor Drive VA board uses the following connector type:
white 3 pin connectors (for motor) (Molex 3-pin .100")
white 2 pin connector (for battery) (Molex 2-pin .100")
Wiring Connections for the TRK-MPC5604B
The next step is to import an existing project into your Workspace. in this case, the TRK-MPC5604B Sample project. Follow the instructions on the codewarrior project import page if you can't remember how to to import the project into CodeWarrior.
If you have more than one project in your project view, make sure the proper project is the focus. The most reliable way to do this is to right click the project and choose Build Project as shown below. You can also go to the Project menu and choose the same command.
If you encounter errors, look in the Problems view and resolve them. You can ignore any warnings.
What will happen:
This demo is setup for two motors (one left and one right). You will then independently turn on and off each motor
This file sets up the Pulse Width Modulation Timer Module for use by a DC Motor. It is set to utilize Edge-Aligned PWM, and this file properly configures the period, and pulse width for use by the other modules
void MOTOR_LEFT(void)
{
TransmitData("****Left Drive Motor Test****\n\r");
SIU.PCR[16].R = 0x0200; /* Program the drive enable pin of Left Motor as output*/
SIU.PGPDO[0].R = 0x00008000; /* Enable Left the motors */
Delaywait();
SIU.PGPDO[0].R = 0x00000000; /* Disable Left the motors */
}
void MOTOR_RIGHT(void)
{
TransmitData("****Right Drive Motor Test****\n\r");
SIU.PCR[17].R = 0x0200; /* Program the drive enable pin of Right Motor as output*/
SIU.PGPDO[0].R = 0x00004000; /* Enable Right the motors */
Delaywait();
SIU.PGPDO[0].R = 0x00000000; /* Disable Right the motors */
}
void RIGHT_MOTOR_CURRENT(void)
{
TransmitData("****Right Motor Current****\n\r");
SIU.PGPDO[0].R = 0x00004000; /* Enable Right the motors */
Delaywait();
for (i=0;i <10;i++)
{
ADC.MCR.B.NSTART=1; /* Trigger normal conversions for ADC0 */
while (ADC.MSR.B.NSTART == 1) {};
curdata = ADC.CDR[2].B.CDATA;
printserialsingned(curdata);
}
SIU.PGPDO[0].R = 0x00000000; /* Disable Right the motors */
}
void LEFT_MOTOR_CURRENT(void)
{
TransmitData("****Left Motor Current****\n\r");
SIU.PGPDO[0].R = 0x00008000; /* Enable Right the motors */
Delaywait();
for (i=0;i <10;i++)
{
ADC.MCR.B.NSTART=1; /* Trigger normal conversions for ADC0 */
while (ADC.MSR.B.NSTART == 1) {};
curdata = ADC.CDR[1].B.CDATA;
printserialsingned(curdata);
}
SIU.PGPDO[0].R = 0x00000000; /* Disable Right the motors */
}
Qorivva Sample Code Download Link
Application Note 4251 and Software.
TRK-MPC5064B Freescale Webpage
TRK-MPC5064B Freescale Reference Manual
TRK-MPC5064B Freescale Schematic