如何使用Arduino Due ADC读取差分信号?

时间:2016-05-10 14:31:15

标签: arduino adc arduino-due

我在配置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));

然后我得到一个(嘈杂的)但正确的值。

任何人都可以告诉我我做错了什么,或者指出一些示例代码的方向。

感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用

读取值
i16Value = adc_get_latest_value(ADC);`

注: - 噪声滤波需要外部去耦电容。(数据表第1317页)