基于MSP430f5529的电动机调速程序

代码如下:

 1 #include "MSP430F5529.h"
 2 void Sys_Init(){
 3   P1DIR |=BIT2;
 4   P1SEL |=BIT2;
 5   P1DIR |=BIT3;
 6   P1SEL |=BIT3;
 7 
 8   P7DIR |=BIT4+BIT0;
 9   P7OUT |=BIT4;    //AN1=1   反转
10   P7OUT &=~BIT0;   //AN2=0
11 
12   TA0CCR0=800;
13   TA0CCTL1=OUTMOD_7;
14   TA0CCR1=500;
15   TA0CCTL2=OUTMOD_7;
16   TA0CCR2=500;
17   TA0CTL =TASSEL_1+MC_1+TACLR;
18 }
19 
20 int main( void )
21 {
22   // Stop watchdog timer to prevent time out reset
23    WDTCTL = WDTPW + WDTHOLD;
24    int i;
25    char SpeedMode=0;
26    Sys_Init();
27    while(1)
28    {
29      for(i=0;i<4000;i++);  //延迟
30 
31      if(SpeedMode==0)      //加速模式下
32       {
33        TA0CCR1++; //占空比不断提高
34        P1DIR |=BIT0;
35        P1OUT |=BIT0;            
36        if(TA0CCR1>=500) SpeedMode=1; //到达100%后转为减速模式
37       } 
38      if(SpeedMode==1)      //减速模式下
39       {
40        TA0CCR1--;             //占空比不断降低
41        if(TA0CCR1<=200) SpeedMode=0; //到达40%后转为加速模式
42      }     
43    }
44 }

 

posted @ 2020-12-13 15:10  叕叒双又  阅读(827)  评论(1编辑  收藏  举报