Created
January 19, 2013 14:53
-
-
Save aarmot/4573062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "msp430.h" | |
/* | |
BLDC motor driver ver1 | |
P2.0 P2.1 P2.2 go through cycle | |
010 | |
011 | |
001 | |
101 | |
100 | |
110 | |
This pattern can be generated using initial state 010 | |
and xor mask 001, rotating latter left after each use | |
Compiled using msp430-gcc 4.6.3 | |
aarmot 2013-01-19 | |
*/ | |
#define OUTPUT_MASK 0b111 | |
#define INITIAL_BITS 0b010 | |
#define INITIAL_MASK 0b100 | |
// Approximate period, measured in usec | |
#define PERIOD 1000 | |
unsigned char xormask = INITIAL_MASK; | |
void main(void) | |
{ | |
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog | |
BCSCTL1 = CALBC1_1MHZ; // Running at 1 MHz | |
DCOCTL = CALDCO_1MHZ; | |
P2DIR |= OUTPUT_MASK; // Output direction | |
P2OUT = INITIAL_BITS; | |
TA0CCTL0 = CCIE; // CCR0 interrupt enabled | |
TA0CCR0 = PERIOD; | |
TA0CTL = TASSEL_2 + MC_2; // SMCLK, contmode | |
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt | |
} | |
__attribute__((__interrupt__(TIMER0_A0_VECTOR))) | |
void Timer0_A(void) | |
{ | |
P2OUT ^= xormask; // Toggle output | |
xormask >>= 1; | |
if(xormask == 0) xormask = INITIAL_MASK; | |
TA0CCR0 += PERIOD; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment