对于 选择参考REF,是内置参考电压,还是选择外置参考电压。
我想到一种方法就是都选,而且确保内部外部参考电压一样,通过内外采集的转换的结果比较,看看偏差么样,如果是自己给的一个固定的被采样的电压之,那就更好,可以通过此方法确定,内外采样的准确度。
// SD24_init(SD24_BASE, SD24_REF_INTERNAL);
// SD24_init ( (SD24_BASE,SD24_REF_EXTERNAL );
//这里假设给定一个被采样的电压为1.5V
#define RealResults (1.5)
unsigned long SD24_Conversion_Results(uint8_t referenceSelect);
void mian(void)
{
unsigned long results1,results2;
results1=SD24_Conversion_Results( SD24_REF_INTERNAL);
results2=SD24_Conversion_Results( SD24_REF_EXTERNAL);
//后面就是简单的比较转换后与实际的值的偏差
// 当然需要多长测试比较,才好确定
}
unsigned long SD24_Conversion_Results(uint8_t referenceSelect)
{
SD24_init(SD24_BASE, referenceSelect); // Select internal REF
SD24_initConverterAdvancedParam param = {0};
param. converter = SD24_CONVERTER_2; // Select converter
param. conversionMode = SD24_SINGLE_MODE; // Select single mode
param. groupEnable = SD24_NOT_GROUPED; // No grouped
param. inputChannel = SD24_INPUT_CH_ANALOG; // Input from analog signal
param. dataFormat = SD24_DATA_FORMAT_2COMPLEMENT; // 2’s complement data format
param. interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT; // 4th sample causes interrupt
param. oversampleRatio = SD24_OVERSAMPLE_256; // Oversampling ratio 256
param. gain = SD24_GAIN_1; // Preamplifier gain x1
SD24_initConverterAdvanced(SD24_BASE, ¶m);
delay cycles(0x3600); // Delay for 1.5V REF startup
SD24_startConverterConversion(SD24_BASE,SD24_CONVERTER 2); // Set bit to start conversion
// Poll interrupt flag for channel 2
while( SD24_getInterruptStatus(SD24_BASE, SD24_CONVERTER_2,SD24_CONVERTER_INTERRUPT) == 0 ); results = SD24 getResults(SD24_BASE,SD24_CONVERTER_2); // Save CH2 results (clears IFG)
return results;
}
|