This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
我的项目有两个模拟输出。 我使用 MSP430G2253微控制器来执行两个 ADC 转换。 我没有得到正确的 ADC 转换值。 请帮帮我。
代码:
void main()
{
xxxxxxxxxx
XXXXXXXX
xxxxxxxxx
while (1)
{
adc_temp();
CALC_TEMP_();
_DELAY_CYCLES (50000);
adc_signal ();
CALC_VALUE ();
_DELAY_CYCLES (50000);
}
}
void adc_temp ()
{
ADC10CTL0 &=~ENC;
ADC10CTL0 = ADC10ON + ADC10SR + ADC10SHT_0 + SREF_0;
ADC10CTL1 = CONSEQ_0 + ADC10SSEL_0 + ADC10DIV_0 + SHS_0 + INCH_4;
ADC10CTL0 |= ENC;
}
void adc_signal ()
{
ADC10CTL0 &=~ENC;
ADC10CTL0 = ADC10ON + ADC10SR + ADC10SHT_0 + SREF_0;
ADC10CTL1 = CONSEQ_0 + ADC10SSEL_0 + ADC10DIV_0 + SHS_0 + INCH_5;
ADC10CTL0 |= ENC;
}
Calc 温度()
{
ADC10CTL0 |= ENC + ADC10SC;
TEMP_VALUE = ADC10MEM;
_delay_cycles (5000);
xxxxxxxxx;
xxxxxxxxx
xxxxxxxxx
}
CAL_VALUE ()
{
ADC10CTL0 |= ENC + ADC10SC;
signal_value = ADC10MEM;
_delay_cycles (5000);
xxxxxxxxx;
xxxxxxxxx
xxxxxxxxx
}
您好 Jace、
感谢您的回复。 我想使用两个外部 ADC (将来可能是三个 ADC)。
在您的函数中、
您正在启动 ADC 转换、但即使在采样和转换完成之前也会读取采样值。
要获得有效的采样和转换、您必须使用忙等待循环或使用 ADC10中断(ADC10IE)。
CALC_TEMP_()和 CALC_VALUE (),
如下所示、
忙等待循环:
CALC_TEMP(){ ADC10CTL0 |= ENC + ADC10SC; while (ADC10CTL1 & ADC10BUSY); temp_value = ADC10MEM; __DELAY_CYCLLES (5000);//除非您将其用于 ADC 用途 以外的其他用途,否则不需要此操作}
或
中断:
init(){;; ADC10CTL1 |= ; ADC10AE0 |= ; }calc_temp (){ ADC10CTL0 |= ADC10IE;//启用 ADC 中断 ADC10CTL0 |= ENC + ADC10SC; } _interrupt void ADC10_ISR (void) { temp_value = ADC10MEM; }
关于您的评论"P1.1和 P1.2用于 UART 通信"、
您可以通过 PxSEL 和 PxSEL2寄存器重新配置这些通道。