Qorivva: Drive DC Motor Tutorial

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Qorivva: Drive DC Motor Tutorial

Qorivva: Drive DC Motor Tutorial

This tutorial covers the details of Driving a motor on the Qorivva TRK-MPC5604B: MPC5604B StarterTRAK evaluation board.

Overview

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:

  • Put together the car chassis
  • Open the Sample Project
  • Make changes to main.c to call the motor functions
  • Build the Motor function code
  • Download and run the code on a Qorivva TRK-MPC5604B board.
  • Learn how the code works

To successfully complete this exercise students will need the following board and development environment.

  • Qorivva TRK-MPC5604B board.
  • Freescale Cup Chassis
  • (connector for the motor/board)
  • Motor Drive Version A board
  • Kit Cables and interconnects
  • 7.2v Nicad Battery
  • CodeWarrior for Microcontrollers V2.8
  • Recommend completing the the Blink LED Tutorial
  • Motor Example code

1. Put together the Car Chassis:

  There are several steps in this process:

  1. Build the Freescale Cup Car Chassis
  2. Add the Qorivva-Mpc560xb version components to the chassis

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.

Motor Controller Board Version A.

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")

Schematics

Wiring Connections for the TRK-MPC5604B

2. Import the Sample Project

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.

3. Build the Code

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.

4. Download/Debug/Run

5. Learning Step: DC Motor Code Description

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

Functions

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

Motor_Right () & Motor_Left()

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 */
}

Motor_Right_Current () & Motor_Left_Current()

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 */
}

Sample Code Download Link

Qorivva Sample Code Download Link

Alternative Examples:

Application Note 4251 and Software.

Other Qorivva Tutorials:

  1. Qorivva: Blink a Led Tutorial
  2. Qorivva: Turning a Servo Tutorial
  3. Qorivva: Line Scan Camera Tutorial

Useful Technical Links

TRK-MPC5064B Freescale Webpage
TRK-MPC5064B Freescale Reference Manual
TRK-MPC5064B Freescale Schematic

Labels (1)
No ratings
Version history
Last update:
‎09-10-2020 02:47 AM
Updated by: