You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void analogReference(uint8_t mode)
{
// can't actually set the register here because the default setting
// will connect AVCC and the AREF pin, which would cause a short if
// there's something connected to AREF.
analog_reference = mode;
#if defined(__LGT8FX8E__) || defined(__LGT8FX8P__)
#if defined(__LGT8FX8E__)
if(analog_reference == INTERNAL2V56) {
VCAL = VCAL2;
} else {
VCAL = VCAL1;
}
#else
// set analog reference for ADC/DAC
if(analog_reference == EXTERNAL) {
DACON = (DACON & 0x0C) | 0x1;
if((PMX2 & 0x2) == 0x2) {
GPIOR0 = PMX2 & 0xfd;
PMX2 = 0x80;
PMX2 = GPIOR0;
}
} else if(analog_reference == DEFAULT) {
DACON &= 0x0C;
} else {
DACON = (DACON & 0x0C) | 0x2;
cbi(ADCSRD, REFS2);
if(analog_reference == INTERNAL2V048) {
VCAL = VCAL2; // 2.048V
} else if(analog_reference == INTERNAL4V096) {
sbi(ADCSRD, REFS2);
VCAL = VCAL3; // 4.096V
} else {
VCAL = VCAL1; // 1.024V
}
}
#endif
ADMUX = (analog_reference << 6);
#endif
}
dear friend,
I looked at this code,find that if I was 328d, there is a sentence on page 204,
使用内部基准(1.25V/2.56V)注意事项:
芯片上电后,默认将内部基准校准为 1.25V,用户如果使用 1.25V 的内部基准,可以直
接使用,无需其他操作。但如果需要使用 2.56V 的内部参考电压,需要自行更新内部基准的
校准值。 2.56V 的校准值在上电后被加载到寄存器 VCAL2(0xCE),在程序初始化时,将 VCAL2
的值读入并写入到 VCAL(0XC8)寄存器即完成 2.56V 的校准。
需要注意的是,当更新了 VCAL 寄存器后,会导致 VCAL1 即 1.25V 的校准值同时更新为
VCAL2,因此如果需要在后续使用过程中重新选择 1.25V 基准,需要提前将 VCAL1 的值保存
到变量中以供后续使用。
after power on, system set calibrate to 1v25 as default, no other operation needed. to using 2V56 as VCAL, need read calibrate value from VCAL2(0xce) and write to VCAL(0xC8). However when update the calibrate of VCL, the calibrate value in VCL1 will update to VCL2 simultaneously , so we must save calibrate of VCL1 in case we use 1v25 again after changing to 2V56.
so there seems a bug:
#if defined(__LGT8FX8E__)
if(analog_reference == INTERNAL2V56) {
VCAL = VCAL2;
} else {
VCAL = VCAL1; // if we use 1v25 again after changing to 2V56. VCAL1 store the calibrate value of 2V56
}
#else
To workout, I see in the main.cpp,GPIOR1 save the calibration,
BUGS!! in write_analogue.c
dear friend,
I looked at this code,find that if I was 328d, there is a sentence on page 204,
使用内部基准(1.25V/2.56V)注意事项:
芯片上电后,默认将内部基准校准为 1.25V,用户如果使用 1.25V 的内部基准,可以直
接使用,无需其他操作。但如果需要使用 2.56V 的内部参考电压,需要自行更新内部基准的
校准值。 2.56V 的校准值在上电后被加载到寄存器 VCAL2(0xCE),在程序初始化时,将 VCAL2
的值读入并写入到 VCAL(0XC8)寄存器即完成 2.56V 的校准。
需要注意的是,当更新了 VCAL 寄存器后,会导致 VCAL1 即 1.25V 的校准值同时更新为
VCAL2,因此如果需要在后续使用过程中重新选择 1.25V 基准,需要提前将 VCAL1 的值保存
到变量中以供后续使用。
after power on, system set calibrate to 1v25 as default, no other operation needed. to using 2V56 as VCAL, need read calibrate value from VCAL2(0xce) and write to VCAL(0xC8). However when update the calibrate of VCL, the calibrate value in VCL1 will update to VCL2 simultaneously , so we must save calibrate of VCL1 in case we use 1v25 again after changing to 2V56.
To workout, I see in the main.cpp,GPIOR1 save the calibration,
can we replace VCAL1 with GPIOR1 here to workout this problem?
or are there some other good way to work around? does GPIOR1 be overwritten by other program?
Thanks!
The text was updated successfully, but these errors were encountered: