一、单端、全差分、伪差分
此部分转载https://www.cnblogs.com/alifpga/p/7976531.html
单端信号:
单端信号(single-end)是相对于差分信号而言的,单端输入指信号有一个参考端和一个信号端构成,参考端一般为地端。
差分信号:
差分(Differential)是将单端信号进行差分变换,输出两个信号,一个和原信号同相,一个和原信号反相。差分信号有较强的抗共模干扰能力,适合较长距离传输,单端信号则没有这个功能。
差分输入时,是判断两信号线的电压差。
伪差分输入:
为了既有差分输入的优点又有单端输入简单的优点,还有一种伪差分输入,通过把信号地连到ADCIN-端实现一种类似差分的连接。由于两线对“大地”阻抗不一致,所以抑制效果有限。
二、软件实现
硬件平台: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
", ADC16_GetChannelConversionValue(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP));
}