九齐单片机NY8B062E的ADC零点校准程序记录
2022/1/16 20:04:25
本文主要是介绍九齐单片机NY8B062E的ADC零点校准程序记录,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
最消费类的方案开发,一直用到九齐的片子,带AD的基本都是062D,但是后面推出了062E代替了D版,看资料,使用AD需要一个零点校准的初始化程序,刚开始也一脸懵逼,经过一番摸索有,在这里做一个记录,
//ADC初始化校准 ---------------------------------------------------------------------------------
//void F_ADJMD(void)
//void F_GND_Convert(char count)
//void ADC_Calibration_Pro(void)
void F_GND_Convert(char count)
{
char i;
ADMD = 0x90 | C_VSS; // Select (GND) pad as ADC input
CLRWDT(); //clear WDT, which is defined in NY8Common.h
delay(100); // Delay 0.56ms(Instruction clock=4MHz/2T) for waiting ADC stable
for(i=1;i<=count;i++)
{
ADMDbits.START = 1; // Start a ADC conversion session
while(ADMDbits.EOC == 0)
; // Waiting for ADC conversion complet
R_AIN_DATA_LB += ( 0x0F & ADR);
}
}
void F_ADJMD(void)
{
DISI();
ADMDbits.GCHS = 1; // Enable global ADC channel (SFR "ADMD")
F_GND_Convert(8); // executing GND ADC converting 8 times
R_AIN_DATA_LB >>= 3; // Only get Bit7~4
if(R_AIN_DATA_LB >= 2)
{
ADJMD = 0x00;
while(1)
{
CLRWDT();
R_AIN_DATA_LB = 0;
F_GND_Convert(8); // executing GND ADC converting 8 times
R_AIN_DATA_LB >>= 3; // Only get Bit7~4
if((ADJMD<0x1F) & (R_AIN_DATA_LB >= 2)){ADJMD++;}
else if(ADJMD == 0x1F){ADJMD = 0x00;break;}
else {R_AIN_DATA_LB = 1;break;}
}
}
if(R_AIN_DATA_LB == 0)
{
ADJMD = 0x20;
while(1)
{
CLRWDT();
R_AIN_DATA_LB = 0;
F_GND_Convert(8); // executing GND ADC converting 8 times
R_AIN_DATA_LB >>= 3; // Only get Bit7~4
if((ADJMD<0x3F)&(R_AIN_DATA_LB == 0)){ADJMD++;}
else if(ADJMD == 0x3F){ADJMD = 0x20;break;}
else {break;}
}
}
}
void ADC_Calibration_Pro(void)
{
//----- Initial ADC-----
ADMD = C_ADC_En | C_ADC_CH_Dis | C_VSS ; // Enable ADC power, Disable global ADC input channel. Select PA1 pad as ADC input (SFR "ADMD")
//----- ADC high reference voltage source select-----
// ADVREFH = C_Vrefh_VDD; // ADC reference high voltage is supplied by internal VDD (Note: ADC clock freq. must be equal or less than 2MHz @ VDD=5.0V)
// ADVREFH = C_Vrefh_4V; // ADC reference high voltage is supplied by internal 4V (Note: ADC clock freq. must be equal or less than 1MHz)
// ADVREFH = C_Vrefh_3V; // ADC reference high voltage is supplied by internal 3V (Note: ADC clock freq. must be equal or less than 500KHz)
ADVREFH = C_Vrefh_2V; // ADC reference high voltage is supplied by internal 2V (Note: ADC clock freq. must be equal or less than 250KHz)
delay(100); // 4M/2T , 0.56mS
//----- ADC clock frequency select----------------------------
// ADR = C_Ckl_Div1; // ADC clock=Fcpu/1, Clear ADIF, disable ADC interrupt
// ADR = C_Ckl_Div2; // ADC clock=Fcpu/2, Clear ADIF, disable ADC interrupt
ADR = C_Ckl_Div8; // ADC clock=Fcpu/8, Clear ADIF, disable ADC interrupt
// ADR = C_Ckl_Div16; // ADC clock=Fcpu/16, Clear ADIF, disable ADC interrupt
//----- ADC Sampling pulse width select-------------
ADCR = C_Sample_1clk | C_12BIT; // Sample pulse width=1 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 500KHz)
// ADCR = C_Sample_2clk | C_12BIT; // Sample pulse width=2 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1MHz)
// ADCR = C_Sample_4clk | C_12BIT; // Sample pulse width=4 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1.25MHz)
// ADCR = C_Sample_8clk | C_12BIT; // Sample pulse width=8 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 2MHz)
//--------------------------------------------------
ADJMD = 0x00;
F_ADJMD();
}
这篇关于九齐单片机NY8B062E的ADC零点校准程序记录的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16在电脑上怎么模拟手机的运行环境?-icode9专业技术文章分享
- 2024-11-16接收socket数据,莫名其妙socket就关闭了是怎么回事?-icode9专业技术文章分享
- 2024-11-16ts nightly是什么?-icode9专业技术文章分享
- 2024-11-16如何升级vscode版本?-icode9专业技术文章分享
- 2024-11-16如何设置vscode默认的node版本?-icode9专业技术文章分享
- 2024-11-16shell 如何创建一个文件夹?-icode9专业技术文章分享
- 2024-11-16useReducer案例详解:从零开始理解与应用
- 2024-11-15聊聊用LangChain4J构建聊天机器人的那些事儿
- 2024-11-15LangChain 和 LlamaIndex 在检索增强生成(RAG)中的大比拼:全面对比评测
- 2024-11-15平台工程不只是配置管理:超越CFEngine的方法