各位老师,前辈好,我想请问一下,我现在用的是MSP430F5529,我现在想要实现的功能是不断采样电压值,根据电压值输出不同占空比的PWM波,但是由于输出pwm我学例程时都是最后让CPU处于低功耗模式,无法进行第二次采样,请问有什么办法吗.谢谢,(我将__bis_SR_register(LPM0_bits); 删去时,示波器上就无法显示pwm波)
unsigned int myvolt,peried_on;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P6SEL|= 0x01;
REFCTL0 &= ~REFMSTR;
ADC12CTL0 = ADC12ON+ ADC12SHT0_8+ADC12REFON+ADC12REF2_5V;
ADC12CTL1 = ADC12SHP+ ADC12CONSEQ_2;
ADC12MCTL0 = ADC12SREF_1+ADC12INCH_0;
__delay_cycles(100);
ADC12CTL0 |= ADC12ENC;
while(1)
{
ADC12CTL0 |= ADC12SC; // Start convn - software trigger
myvolt=ADC12MEM0;
peried_on=PID_volt(myvolt);
Input_PWM();
}
}
void Input_PWM(unsigned int peried_on)
{
P2DIR |= BIT0; // P2.0 and P2.1 output
P2SEL |= BIT0; // P2.0 and P2.1 options select
TA1CCR0 = 540; // PWM Period
TA1CCTL1 = OUTMOD_7; // CCR1 reset/set
TA1CCR1 =peried_on ;
TA1CTL = TASSEL_2 + MC_1 + TACLR;
P1DIR|=0X01;
TA0CCTL0=CCIE;
TA0CCR0=5;
TA0CTL=TASSEL_2+ MC_3 + TACLR;
__bis_SR_register(LPM0_bits); // Enter LPM0
} |