1、單端、全差分、僞差分 html
此部分轉載https://www.cnblogs.com/alifpga/p/7976531.htmlide
單端信號:函數
單端信號(single-end)是相對於差分信號而言的,單端輸入指信號有一個參考端和一個信號端構成,參考端通常爲地端。ui
差分信號:spa
差分(Differential)是將單端信號進行差分變換,輸出兩個信號,一個和原信號同相,一個和原信號反相。差分信號有較強的抗共模干擾能力,適合較長距離傳輸,單端信號則沒有這個功能。debug
差分輸入時,是判斷兩信號線的電壓差。code
僞差分輸入:htm
爲了既有差分輸入的優勢又有單端輸入簡單的優勢,還有一種僞差分輸入,經過把信號地連到ADCIN-端實現一種相似差分的鏈接。因爲兩線對「大地」阻抗不一致,因此抑制效果有限。blog
2、軟件實現 ip
硬件平臺:NXP的FRDM-KV31F樣板
注:此樣板集成了OpenSDA OpenSDA is an open-standard serial and debug adapter.
軟件平臺:IAR
寄存器:
SC1[DIFF]:
差分模式選擇:0 單端模式 1差分模式
程序代碼:
#define ADC_SC1_DIFF_MASK (0x20U)
#define ADC_SC1_DIFF_SHIFT (5U)
#define ADC_SC1_DIFF(x) (((uint32_t)(((uint32_t)(x)) << ADC_SC1_DIFF_SHIFT)) & ADC_SC1_DIFF_MASK)
SC1[ADCH] :通道選擇
#define ADC_SC1_ADCH_MASK (0x1FU)
#define ADC_SC1_ADCH_SHIFT (0U)
#define ADC_SC1_ADCH(x) (((uint32_t)(((uint32_t)(x)) << ADC_SC1_ADCH_SHIFT)) & ADC_SC1_ADCH_MASK)
ADC Data Result Register (ADCx_Rn) :數據結果
/*! * @brief Gets the conversion value. * * @param base ADC16 peripheral base address. * @param channelGroup Channel group index. * * @return Conversion value. */ static inline uint32_t ADC16_GetChannelConversionValue(ADC_Type *base, uint32_t channelGroup) { assert(channelGroup < (uint32_t)FSL_FEATURE_ADC16_CONVERSION_CONTROL_COUNT); return base->R[channelGroup]; }
初始化:
adc16ConfigStruct.referenceVoltageSource = kADC16_ReferenceVoltageSourceVref;
adc16ConfigStruct.clockSource = kADC16_ClockSourceAsynchronousClock;
adc16ConfigStruct.enableAsynchronousClock = true;
adc16ConfigStruct.clockDivider = kADC16_ClockDivider8;
adc16ConfigStruct.resolution = kADC16_ResolutionDF16Bit;
adc16ConfigStruct.longSampleMode = kADC16_LongSampleDisabled;
adc16ConfigStruct.enableHighSpeed = false;
adc16ConfigStruct.enableLowPower = false;
adc16ConfigStruct.enableContinuousConversion = false;
adc16ChannelConfigStruct.enableDifferentialConversion = true;
主函數:
while (1) { GETCHAR(); ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct); while (0U == (kADC16_ChannelConversionDoneFlag & ADC16_GetChannelStatusFlags(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP))) { } PRINTF("ADC Value: %d\r\n", ADC16_GetChannelConversionValue(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP)); }