Fix Incorrect Dac Calibration Algorithm #133

Merged
sb10q merged 1 commits from linuswck/thermostat:fix_incorrect_dac_cal into master 2024-09-25 17:18:33 +08:00
Owner

Description

Dac calibration should not be that long. That should be a fast binary search and should not take 1s to complete calibration for each channel.

Printing the readings out reveals the incorrectness. Here is a sample of log.

INFO - step: 17 start_value: 1 prev_value: 1, value: 1 best error: 100.0 m^2 kg^1 s^-3 A^-1 error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1
INFO - step: 17 start_value: 1 prev_value: 1, value: 131073 best error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 error: -0.0030000000000003357 m^2 kg^1 s^-3 A^-1
INFO - step: 16 start_value: 1 prev_value: 1, value: 1 best error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1
>>>>>> INFO - step: 16 start_value: 1 prev_value: 1, value: 65537 best error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1
INFO - step: 16 start_value: 1 prev_value: 65537, value: 131073 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: -0.004000000000000226 m^2 kg^1 s^-3 A^-1
INFO - step: 15 start_value: 1 prev_value: 1, value: 1 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1
INFO - step: 15 start_value: 1 prev_value: 1, value: 32769 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 1.1199999999999997 m^2 kg^1 s^-3 A^-1
INFO - step: 15 start_value: 1 prev_value: 32769, value: 65537 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1
INFO - step: 15 start_value: 32769 prev_value: 65537, value: 98305 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 0.37199999999999966 m^2 kg^1 s^-3 A^-1
INFO - step: 15 start_value: 65537 prev_value: 98305, value: 131073 best error: 0.37199999999999966 m^2 kg^1 s^-3 A^-1 error: -0.004000000000000226 m^2 kg^1 s^-3 A^-1 
...

Pay attention to "INFO - step: 16 start_value: 1 prev_value: 1, value: 65537 ..." The start value should have been changed to 65537. Thus, abnormal "linear search" can happen inside the incorrectly implemented binary search algorithm. In some marginal cases, "linear search" can take place starting from value 1 at step 8. This takes 3-4s+ to calibrate the Dac and thus watchdog is triggered indefinitely.

After this fix, Thermostat starts up instantly with no perceived waiting time. Removing read_dac_feedback_until_stable() fn remains necessary as it returns inconsistent value due to the lack of filtering.

This fix is tested on 1 v2.2.2 and 2 v2.2.1 Thermostat Board. Electrical Test(comparing Vref with Iset voltage after calibration) and functional tests are done.

Other Changes

Revert the watchdog interval from 2s back to 1s. See #132

# Description Dac calibration should not be that long. That should be a fast binary search and should not take 1s to complete calibration for each channel. Printing the readings out reveals the incorrectness. Here is a sample of log. ``` INFO - step: 17 start_value: 1 prev_value: 1, value: 1 best error: 100.0 m^2 kg^1 s^-3 A^-1 error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 INFO - step: 17 start_value: 1 prev_value: 1, value: 131073 best error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 error: -0.0030000000000003357 m^2 kg^1 s^-3 A^-1 INFO - step: 16 start_value: 1 prev_value: 1, value: 1 best error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 >>>>>> INFO - step: 16 start_value: 1 prev_value: 1, value: 65537 best error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 INFO - step: 16 start_value: 1 prev_value: 65537, value: 131073 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: -0.004000000000000226 m^2 kg^1 s^-3 A^-1 INFO - step: 15 start_value: 1 prev_value: 1, value: 1 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 1.4949999999999999 m^2 kg^1 s^-3 A^-1 INFO - step: 15 start_value: 1 prev_value: 1, value: 32769 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 1.1199999999999997 m^2 kg^1 s^-3 A^-1 INFO - step: 15 start_value: 1 prev_value: 32769, value: 65537 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 INFO - step: 15 start_value: 32769 prev_value: 65537, value: 98305 best error: 0.7459999999999998 m^2 kg^1 s^-3 A^-1 error: 0.37199999999999966 m^2 kg^1 s^-3 A^-1 INFO - step: 15 start_value: 65537 prev_value: 98305, value: 131073 best error: 0.37199999999999966 m^2 kg^1 s^-3 A^-1 error: -0.004000000000000226 m^2 kg^1 s^-3 A^-1 ... ``` Pay attention to "INFO - step: 16 start_value: 1 prev_value: 1, value: 65537 ..." The start value should have been changed to 65537. Thus, abnormal "linear search" can happen inside the incorrectly implemented binary search algorithm. In some marginal cases, "linear search" can take place starting from value 1 at step 8. This takes 3-4s+ to calibrate the Dac and thus watchdog is triggered indefinitely. After this fix, Thermostat starts up instantly with no perceived waiting time. Removing `read_dac_feedback_until_stable()` fn remains necessary as it returns inconsistent value due to the lack of filtering. This fix is tested on 1 v2.2.2 and 2 v2.2.1 Thermostat Board. Electrical Test(comparing Vref with Iset voltage after calibration) and functional tests are done. # Other Changes Revert the watchdog interval from 2s back to 1s. See #132
linuswck added 1 commit 2024-09-20 22:04:14 +08:00
680193b34b Fix incorrect dac calibration algo
- Fix abnormally long calibration time
sb10q merged commit 680193b34b into master 2024-09-25 17:18:33 +08:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/thermostat#133
No description provided.