在用msp430做开关电源的时候一直没明白 ad采样送给单片机,ad怎么和pwm比较调节占空比的,有程序更好了应该在中断里加什么程序?
#include <msp430f5529.h>
void adc12()
{
//WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON + ADC12MSC+ADC12REF2_5V; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_3; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
P6SEL |= BIT0; // P6.0 ADC option select
P1DIR |= BIT0; // P1.0 output
/*while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
//__no_operation(); // For debugger
}*/
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
#include <msp430f5529.h>
void pwm()
{
//WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT2+BIT3; // P1.2 and P1.3 output
P1SEL |= BIT2+BIT3; // P1.2 and P1.3 options select
TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0 = 512-1; // PWM Period
TA0CCTL1 = OUTMOD_7; // CCR1 reset/set
TA0CCR1 = 160; // CCR1 PWM duty cycle
TA0CCTL2 = OUTMOD_3; // CCR2 reset/set
TA0CCR2 = 160; // CCR2 PWM duty cycle
TA0CTL = TASSEL_1 + MC_1 + TACLR; // ACLK, up mode, clear TAR
//__bis_SR_register(LPM0_bits+GIE); // Enter LPM3
//__no_operation(); // For debugger
}
此帖出自
小平头技术问答
根据你的描述,初步认为,需要用ADC采样你的输出电压,来控制PWM的大小,产生一个反馈,来控制电源输出,得到你实际需要的电压。具体怎么计算获取的ADC与PWM关系,由你的硬件设计电路决定。
一周热门 更多>