/* Sample program of DC motor control through Wytec EduBase board. * The Wytec EduBase board has a motor control device that consists of four * half-bridge circuit. This program uses two half-bridges to control the output * of M3-M4 terminals. A DC motor should be connected between M3 and M4 terminals * of the board. Pin 39 is used to control the pulse-width modulation of the output. * Pin 19 and 38 control the direction of the half-bridges and in turn control the * direction of the motor. * The program speeds up the motor, slows down the motor, reverse the direction then repeats. */ /* Tiva TM4C123 */ //const int PWM34 = PF_3; const int PWM34 = 39; /* Tiva TM4C123 */ //const int HalfBridgeLeft = PB_2; const int HalfBridgeLeft = 19; /* Tiva TM4C123 */ //const int HalfBridgeRight = PB_3; const int HalfBridgeRight = 38; void setup() { pinMode(HalfBridgeRight, OUTPUT); pinMode(HalfBridgeLeft, OUTPUT); } void loop() { // change motor direction digitalWrite(HalfBridgeRight, HIGH); digitalWrite(HalfBridgeLeft, LOW); // ramp up the pulse width for(int pulseWidth = 0 ; pulseWidth <= 255; pulseWidth +=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // delay 50 ms } // ramp down the pulse width for(int pulseWidth = 255 ; pulseWidth >= 0; pulseWidth -=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // delay 50 ms } // change motor direction digitalWrite(HalfBridgeRight, LOW); digitalWrite(HalfBridgeLeft, HIGH); // ramp up the pulse width for(int pulseWidth = 0 ; pulseWidth <= 255; pulseWidth +=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // delay 50 ms } // ramp down the pulse width for(int pulseWidth = 255 ; pulseWidth >= 0; pulseWidth -=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // delay 50 ms } }