各位師傅,前輩好,我想請問一下,我現在用的是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
}
|