//DC motor control using the H-Bridge on Dragon12 with Channel 0 PWM //Dragon12 board comes with TI's 754410 H-bridge driver (Google for data sheet and study it) //On Dragon12 PORTB and PORTP are used to control BOTH 754410 chip and 7-seg LEDs //WE CANNOT USE BOTH 7-SEG LEDs and 754410 AT THE SAME TIME. //J24 (on left side of CPU) is used to provide power to 7-seg LEDs driver //and J18 (at the bottom left side of the board by the buzzer) is used to provide power to H-bridge driver. //ONLY ONE OF THEM SHOULD HAVE A JUMPER //The Dragon12 is shipped with J24 (7-Seg LEDs) power enabled and nothing on J18. //If you want to use H-Bridge you MUST move the jumper from J24 to J18. ONLY ONE OF THEM SHOULD HAVE A JUMPER //On Dragon12 the PP0 (PWM chan 0) is connected to EN12 pin of 754410. //PB0 is connected to 1A and PB1 to 2A input pins of the 754410. That means M1 (1Y) and M2 (2Y) outputs are controled by PB0,PB1 and PP0. //Also the PP1 (PWM chan 1) is connected to EN34 pin of 754410. //PB2 is connected to 3A and PB3 to 4A input pins of the 754410. That means M3 (3Y) and M4 (4Y) outputs are controled by PB2,PB3 and PP1. //The 754410 chip allows to have an external power source of up to 36V (4.5V-36V) to drive DC motor. DO NOT USE MORE THAN 9 V //The Dragon12 board allows you to use an external power source of your own. See T4 screw terminal on the bottom left of the board //To use your own external power source for 754410 PUT the jumper on lower 2 pins. //Steps to connect and run this program to control DC motor //1)move jumper from J24 to J18 to power the 754410 chip //2)Connect an external 5V-9V DC power to the VEXT and GND pins on T4 Terminal Block //3)Next to the VEXT place a jumper to lower 2 pins. //4)Connect the + lead of your DC motor to M1 pin in T4 Terminal block //5)Connect the - lead of your DC motor to M2 pin in T4 Terminal block //Now, power your Dragon12 board and //Compile (F7), Download (F5) and run(F5), this program //This program will turn the DC motor clockwise(CW) for 3 seconds, //then it stops and turns CCW for 3 seconds. It always stops and rests for 1 second before changing direction //It does that continuosly. // Written and tested by M. Mazidi. //for PWM and DC motor control see chapter 17 of HCS12 book by Mazidi & Causey. #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); void main(void) { /* put your own code here */ DDRB = 0x03; //PORTB as output since the M1 and M2 drivers are controlled by PB0 and PB1 pins PORTB=0b00000000; //Stop DC motor(PB0=0 and PB1=0). //NOTICE ONLY ONE OF THEM CAN BE ON FOR TURNING CLOCKWISE (CW PB0=1) OR COUNTER CLOCKWISE (CCW PB1=1) //DO NOT NOT USE PB0=1 AND PB1=1 AT THE SAME TIME. PWMPRCLK=0x5; //ClockA=Fbus/2**5=24MHz/32=750000 Hz PWMCLK=0x00; //ClockA for Chan 0 PWMPOL=0x01; //high and low for polarity PWMCAE=0; //Left aligned PWMCTL=0; //8-bit chan and PWM freeze during wait PWMCNT0=0; //start the PWMCount with 0 value PWME=0x01; //Enable PWM chan 0 for(;;) { PWMPER0=100; //PWM_Period Freq. = ClockA/100= 750000 Hz/100=7500 Hz PWMDTY0=60; //Duty Cycle=60% (60% of 100). Change this value and experiment with duty cycle. PORTB=0b00000001; //turn on for clockwise direction (DO NOT USE 0b00000011 FOR BOTH ON) MSDelay(3000); //run for 3 sec PORTB=0x00000000;//stop the motor MSDelay(1000); //wait 1 sec for motor to stop completely before changing direction PORTB=0b00000010; //change direction to CCW (DO NOT USE 0b00000011 FOR BOTH ON) MSDelay(3000); //run for 3 sec PORTB=0x00000000; //stop the motor. MSDelay(1000); //wait 1 sec for motor to stop completely before changing direction. } } //millisecond delay for XTAL=8MHz, PLL=48MHz //The HCS12 Serial Monitor is used to download and the program. //Serial Monitor uses PLL=48MHz void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i