The principle of motor PWM speed regulation based on MSP430 microcontroller
[Copy link]
/*
Program description: Use timer TA to generate a fixed-cycle square wave, and control the high-level time of the square wave to control
the average output power. This control method is called PWM modulation.
The timer TA of the MSP430 microcontroller can output two PWM modulation waveforms without CPU intervention
. Use one of them (TA1) to drive the motor through a transistor. Just
write the CCR1 register to change the duty cycle at any time, thereby changing the motor power. This control
method has low power loss (the control element does not consume power when it is turned on/off) and is highly efficient.
*/
//
//
// MSP430FE425
// -----------------
// | XIN|-
// | | 32kHz
// | XOUT|-
// | |
// | P1.2/TA1|----->Transistor drive--->small motor
// | (CCR1) | _ _ _ _
// | | _| |__| |__| |__| |_
// | | 40%~100% PWM
//
#include <MSP430X42X.h>
void Sys_Init()
{
WDTCTL=WDTPW+WDTHOLD; //Disable watchdog
FLL_CTL0|=XCAP18PF; //Configure crystal load capacitance
P1DIR |= BIT2; // P1.2 output
P1SEL |= BIT2; // P1.2 TA1 otions
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
CCR0 = 500; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = 200; // CCR1 PWM duty cycle
}
void main( void )
{ int i;
char SpeedMode=0;
Sys_Init();
while(1)
{
for(i=0;i<4000;i++); //Delay
if(SpeedMode==0) //In acceleration mode
{
CCR1++; //Duty cycle keeps increasingif
(CCR1>=500) SpeedMode=1; //After reaching 100%, it switches to deceleration mode
}
if(SpeedMode==1) //In deceleration mode
{
CCR1--; //Duty cycle keeps decreasingif
(CCR1<=200) SpeedMode=0; //After reaching 40%, it switches to acceleration mode
}
}
}
|