/* This program drives a stepper motor using half-step. * * The Wytec EduPad board has a quad half-H-bridge motor driver, * which is capable of driving two DC motors or a stepper motor * with up to 15V and 1.2A continous current. * * The enable pins of the half-bridge are connected to PORTB 3-0. * The PWM inputs are connected to PORTF 2 and PORTF 3. These * pins are shared with the LEDs. The PORTB pins are connected to * the LEDs on the EduBase board. The PORTF pins are connected to * the LEDs on the Tiva LaunchPad. * * The four output pins of the motor driver device are connected to * the blue terminals marked M1, M2, M3, and M4. Use of external * power supply for motor is recommended. External power should be * connected to the terminals T3 and the jumper J4 should be at EXT. * * Built and tested with Keil MDK-ARM v5.24a and TM4C_DFP v1.1.0 */ #include "TM4C123.h" void delayMs(int n); int main(void) { const char halfsteps[ ] = {0x9, 0x1, 0x5, 0x4, 0x6, 0x2, 0xa, 0x8}; int i = 0; SYSCTL->RCGCGPIO |= 0x20; // enable clock to GPIOF SYSCTL->RCGCGPIO |= 0x02; // enable clock to GPIOB // Use PORTF3, 2 as PWM for motor control GPIOF->DIR = 0x0C; // set PORTF3, 2 pins as output pin GPIOF->DEN = 0x0C; // set PORTF3, 2 pins as digital pins GPIOF->DATA = 0x0C; // assert PWM for now GPIOB->DEN |= 0x0F; // PORTB 3-0 as digital pins GPIOB->DIR |= 0x0F; // set PORTB 3-0 as output while(1) { GPIOB->DATA &= ~0x0F; // clear motor enable pins GPIOB->DATA |= halfsteps[i++ & 7]; // set the motor enable pins delayMs(100); } } /* delay n milliseconds (50 MHz CPU clock) */ void delayMs(int n) { int i, j; for(i = 0 ; i< n; i++) for(j = 0; j < 6265; j++) {} /* do nothing for 1 ms */ }