Following the wave generator calibration, I ran Ghidra again.
I found it effectively checks the eeprom if the calibration file couldn't be opened.
(I renamed the functions for easier reading)
void Read_AWG_calibration_file(void)
{
iVar1 = open("root/dds_calbration.dat",2,0x180);
if (iVar1 < 1) {
iVar1 = read_AWG_calibration_from_eeprom(&DAT_009e0f28);
if (0 < iVar1) {
regen_dds_cal_data();
return;
}
printf("[%s]open %s failed\n","dds_calibration_load","root/dds_calbration.dat");
}
else {
__fxstat(3,iVar1,&sStack112);
if (sStack112.st_size == 0x28) {
read(iVar1,&AWG_CAL_DATA,0x28);
}
else {
ftruncate(iVar1,0);
AWG_CAL_DATA = &DAT_00100010;
DAT_009e0f28 = 0;
DAT_009e0f2c = 0x3ff00000;
DAT_009e0f40 = 0;
DAT_009e0f44 = 0;
}
DAT_009e0f18 = (uint)(sStack112.st_size == 0x28);
close(iVar1);
}
return;
}
int read_AWG_calibration_from_eeprom(char **param_1,char **param_2)
{
...
(char *)read_eeprom(extraout_s0,__fd,&local_40,4,0xdc);
if (local_40 == 1) {
...
(char *)read_eeprom(pcVar4,__fd,__nptr,8,0xe0);
dVar5 = strtod((char *)__nptr,(char **)0x0);
...
(char *)read_eeprom(pcVar4,__fd,__nptr,8,0xe8);
dVar5 = strtod((char *)__nptr,(char **)0x0);
}
...
}
So there're 3 eeprom addresses:
0xDC-0xDF (4bytes). 0x01000000 (little endian) means there's awg calibration present in the eeprom.
0xE0-0xE8 (8bytes). First coefficient. Float represented as text string (ex. "0.818373")
0xE9-0xEF (8bytes). Second coefficient.
Very stupid, why not store the double float directly? Loses precision this way.
Sso far I haven't found the equation it uses.
I made a test:
cd /cache
mv dds_calbration.dat dds_calbration.bak
i2cset -y 0 0x50 0xdc 1 0 0 0 i
It worked, reading the data from eeprom I already had written using the calibration tool:
calibration_dds_result_read_eeprom,amp 0.833157,off 13.485450
On booting, it regenerated the dds_calbration.dat file, but the string conversion lost a digit. Not a big deal, but stupid programming.
Orig: 13.485453
New: 13.48545
Did we already see how terrible Hantek programmers are?
![Laughing :-DD](https://www.eevblog.com/forum/Smileys/default/smiley_laughing.gif)
Edit:
There's another calibration block, seems to be the ADC gain calibration.
- 0x19-0x1C (4-bytes). A value of 0x01010000 means there's calibration data.
- 0x28-D7. (176 bytes). The're 4 calibration blocks. Each has 11 4-byte integers (32-bit) .
Deleting cali.dat regenerates it from the eeprom (if present), but it's pretty useless, needs a new calibration anyways.
This is how data is stored:
EEPROM Cali.dat
0x28-0x53 0x4B0-0x4DB
0x54-0x7F 0x4E8-0x513
0x80-0xAB 0x1F0-0x21B
0xAC-0xD7 0x228-0x253
These areas in cali.dat don't change after calibrating the scope, but new ones appear.
Doesn't seem to be critical. I zeroed my eeprom, deleted cali.dat, rebooted and calibrated afterwards, the channels were fine!
Perhabs it's just the default calibration? (But doesn't mean it's accurate)
The eeprom contents vary a lot between devices, probably they added new features, so earlier scopes lack them.