我在配置 Arduino Due ADC 以读取差分信号时遇到了一些困难。我已将正极端子连接到引脚 A1(CH6),将负极端子连接到引脚 A0(CH7)。共模电压为 3.3V/2。
初始化代码是
pmc_enable_periph_clk(ID_ADC); // Enable the peripheral clock.
// Initialize the ADC.
adc_init(ADC, // Pointer to an ADC.
sysclk_get_cpu_hz(), // Master clock frequency.
2 * ADC_FREQ_MIN, // The ADC frequency.
8); // The startup time.
// Enable individual settings for the input channels.
adc_enable_anch(ADC);
adc_configure_timing(ADC, // Pointer to an ADC.
2, // Tracking time.
ADC_SETTLING_TIME_3, // Settling time.
1); // Data transfer time.
// Configure the conversion resolution.
adc_set_resolution(ADC, // Pointer to an ADC.
ADC_MR_LOWRES_BITS_12); // Use 12-bit resolution.
// Enable the input channels.
adc_enable_channel(ADC, ADC_CHANNEL_6); // Pin A1.
adc_enable_channel(ADC, ADC_CHANNEL_7); // Pin A0.
// Configure channels as differential input.
adc_enable_channel_differential_input(ADC, ADC_CHANNEL_6); // Pin A1. CH6+.
adc_enable_channel_differential_input(ADC, ADC_CHANNEL_7); // Pin A0. CH6-.
// Configure how the ADC conversion process is triggered.
adc_configure_trigger(ADC, // Pointer to an ADC.
ADC_TRIG_SW, // Use software triggering for conversion.
1); // Free-running mode (no trigger is required for conversion).
// Start the ADC.
adc_start(ADC);
我正在尝试使用读取值
int16_t i16Value;
i16Value = (int16_t) adc_get_channel_value(ADC, ADC_CHANNEL_6);
但这给了我共模电压加上一半的差分电压。如果我手动将值计算为
int16_t i16Value;
i16Value = (int16_t) ((adc_get_channel_value(ADC, ADC_CHANNEL_6)
- adc_get_channel_value(ADC, ADC_CHANNEL_7));
然后我得到一个(嘈杂的)但正确的值。
请任何人都可以告诉我我做错了什么,或者指出一些示例代码的方向。
谢谢。