I have written a program about using msp430f149 according to its datasheet( http://www.kynix.com/uploadfiles/pdf8798/MSP430F1491IPM.pdf ) to control the step motor.I would like to show them here.
This is the program:
typedef unsigned int uint;
typedef unsigned char uchar;
#define PWM BIT2
BCSCTL1&=~XT2OFF; //open XT oscillator
BCSCTL2|=SELM1+SELS;//MCLK 8M and SMCLK 1M
IFG1 &= ~OFIFG; //clean the wrong sign of vibration
for(i = 0; i < 100; i++)
_NOP(); //delay waiting
while ((IFG1 & OFIFG) != 0); //If sign is 1,continue to wait
P1SEL|=PWM;//choose P12 to bePWM output
TACCR0=800;//PWM signal cycle 10KHz
TACCR1=400;//duty cycle 1：1
TACCTL1=OUTMOD0+OUTMOD1+OUTMOD2; //outputted mode choosing
int_clk(); //clock initialization
int_pwm(); //initialize PWM
The program is base on controlling the return of step motor by using msp4300f149.The outputted port of PWM is P1.2 while the signal cycle is 10KHZ. The duty cycle is 1:1.
Do you have any suggestions about my program? Welcome to discuss it with me.