Hi all:
我在使用MSP430FR2033时需要使用ADC测量一个电压,打算多次测量取平均值,发现采集的数据数量少于预期的数量,但单步调试是正常的,这有可能是什么问题呢?
代码如下:
1、调用:
unsigned int read_angle_value(void) {unsigned char i;unsigned char num = 10;unsigned int angle_temp = 0;//num = angle_num;// Configure ADC A9 pinSYSCFG2 |= ADCPCTL9;adc_repeat_single_channel_vcc(ADCINCH_9, 10, angle_value);for (i = 0; i < num; i++) {angle_temp = angle_temp + angle_value[i];}angle_temp = angle_temp / num;return angle_temp; }
2、ADC初始化程序:
unsigned int *ADC_Result; unsigned char ADC_Count; unsigned int read_angle_value(void) {unsigned char i;unsigned char num = 10;unsigned int angle_temp = 0;//num = angle_num;// Configure ADC A9 pinSYSCFG2 |= ADCPCTL9;adc_repeat_single_channel_vcc(ADCINCH_9, 10, angle_value);for (i = 0; i < num; i++) {angle_temp = angle_temp + angle_value[i];}angle_temp = angle_temp / num;return angle_temp; }
3、中断处理程序
// ADC interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=ADC_VECTOR __interrupt void ADC_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void) #else #error Compiler not supported! #endif {switch(__even_in_range(ADCIV,ADCIV_ADCIFG)){case ADCIV_NONE:break;case ADCIV_ADCOVIFG:break;case ADCIV_ADCTOVIFG:break;case ADCIV_ADCHIIFG:ADCIFG &= ~ADCHIIFG;// Clear interrupt flagP4OUT |= BIT3 | BIT4 |BIT5;P4OUT &= ~BIT3;break;case ADCIV_ADCLOIFG:ADCIFG &= ~ADCLOIFG;// Clear interrupt flagP4OUT |= BIT3 | BIT4 |BIT5;P4OUT &= ~BIT4;break;case ADCIV_ADCINIFG:ADCIFG &= ~ADCINIFG;// Clear interrupt flag*ADC_Result = ADCMEM0;adc_window_isr();P4OUT |= BIT3 | BIT4 |BIT5;P4OUT &= ~BIT5;//ADCCTL0 &= ~ADCENC;//__bic_SR_register_on_exit(LPM0_bits);// Clear CPUOFF bit from LPM0break;case ADCIV_ADCIFG:if (ADC_Count > 1) {*ADC_Result++ = ADCMEM0;ADC_Count--;break;} else {*ADC_Result++ = ADCMEM0;ADCCTL0 &= ~ADCENC;__bic_SR_register_on_exit(LPM0_bits);// Clear CPUOFF bit from LPM0break;}default:break;} }
Hao Mengzhen:
这个adc_window_isr(); 是什么函数?有可能是这个函数运行时间较长导致正常采样被延误
yanqing zhou:
回复 Hao Mengzhen:
这是一个空函数,窗口比较强处理函数,我没有使能窗口比较器中断
Loops:
回复 yanqing zhou:
你好. 建议你直接采用TI的示例程序. 你这种问题出现,你可以检查下采样间隔是否满足采样间隔的最小要求. 另外, 针对IFG等标志位是否得当.
灰小子:
建议先运行官网例程,在例程的基础上修改、添加功能