Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Arduino Due ADC读取差分信号?_Arduino_Adc_Arduino Due - Fatal编程技术网

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

如何使用Arduino Due ADC读取差分信号?,arduino,adc,arduino-due,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 cl

我在配置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));
然后我得到一个(嘈杂的),但正确的值

请告诉我我做错了什么,或者告诉我一些示例代码的方向


谢谢。

您可以使用

i16Value = adc_get_latest_value(ADC);`
注:-噪声过滤需要外部去耦电容。(数据表第1317页)