/* 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 P2.5, P2.4, * P3.3, and P3.2. These pins are shared with the LEDs on the EduBase board. * The PWM inputs are connected to P2.7 and P2.6. * * 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 MSP432P401R Rev. C, Keil MDK-ARM v5.24a and MSP432P4xx_DFP v3.1.0 */ #include "msp.h" void delayMs(int n); void display(int data); int main(void) { const char halfsteps[ ] = {0x9, 0x1, 0x5, 0x4, 0x6, 0x2, 0xa, 0x8}; int i = 0; // Use PORTF3, 2 as PWM for motor control P2->DIR |= 0xC0; /* P2.7, P2.6 set as PWM for motor control */ P2->OUT |= 0xC0; /* turn on P2.7 and P2.6 */ P2->DIR |= 0x30; /* P2.5, P2.4 set as output for half-bridge control */ P3->DIR |= 0x0C; /* P3.3, P3.2 set as output for half-bridge control */ while(1) { display(halfsteps[i++ & 7]); /* set the motor enable pins */ delayMs(100); } } /* system clock at 3 MHz, MSP432P401R Rev. C, Start-up v2.2.1 */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 750; i > 0; i--); /* Delay */ } void display(int data) { if (data & 8) /* bit 3 -> LED3 */ P2->OUT |= 0x10; else P2->OUT &= ~0x10; if (data & 4) /* bit 2 -> LED2 */ P2->OUT |= 0x20; else P2->OUT &= ~0x20; if (data & 2) /* bit 1 -> LED1 */ P3->OUT |= 8; else P3->OUT &= ~8; if (data & 1) /* bit 0 -> LED0 */ P3->OUT |= 4; else P3->OUT &= ~4; }