Closed hubertushirsch closed 9 months ago
Hi Hubert, thank you for the fixes. Well spotted. I noticed the 'ER: cal offset failed' error before and was going to look at it eventually. You fixed it already, so that's great.
What should actually happen if the b command is called without -co?
I agree, when the calibration offset is not set (-co is not passed as an argument) the calibration offset should be set to 0. That way it is more clear what is going on..
Thank you for your commits in your merge request, I'll merge it manually by using git (not by using the github's interface).
Your code fixes have been merged to master. See the master branch. Thanks.
Thanks to you too. What I didn't consider: When I use an Arduino that has calibration data from a previous use in the EEPROM, the stored calibration offset is always used. If I do a calibration from the scratch,
./afterburner s
from the PC or the t command on the serial console, different values shown depending on whether the Arduino has already been used for Afterburner or is fresh out of the box.
I tested version 0.5.6. It works as expected.
Regarding the problem of complete recalibration when using the same Arduino. This may be necessary if changes or repairs have been made to the Afterburner circuit board.
I would then do the following (possibly include it in the setup instructions):
Pot R9 in the middle position ./afterburner b ; Clears the calibration offset (0.00V), ignore all command outputs. ./afterburner s ; Continue as in the original setup instructions
Note: Use b -co 0 on program version 0.5.5 or earlier to clear the calibration offset.
There are bugs in the Arduino sketch and in the PC software for this function. Both must be fixed together. I made a fork on February 2nd, 2024 to test the fix. https://github.com/hubertushirsch/afterburner // the unchanged fork of the master branch https://github.com/hubertushirsch/afterburner/tree/hubertushirsch-afterburner-B9-fix
afterburner.ino The offset range -20 to 25 (-co X) is transposed by the PC software into the range 0..9 and transmitted to the Arduino as command B0..B9. In the Arduino, however, the value 9 is not in the evaluated range, so the calibration around 0.25V can never take place.
You can see it when you send B9 to Afterburner on the serial terminal.
In addition, there is a typo in the explanation of the values 1:-1.5V ==> -0.15V
afterburner.c If this bug is fixed, a bug in the PC program afterburner.c still needs to be fixed. When the PC software is started, the global variable calOffset is initialized.
What does 0xFFFF mean? This is compiler dependent. In an architecture where int is set to 16-bit, this would be -1, which is a valid calibration offset value in the range -20..25. Probably nobody has this architecture anymore today. In a 32- and 64-bit PC architecture compiler, int is set to be at least 32 bits, so 0xFFFF is a large positive number (65535). This is (for now) outside the valid offset range -20..25.
But what does the parsing of the command line do in afterburner.c? If there is a -co option on the command line, the value is read. If it is outside -20...25, a warning message appears.
Some lines later the values are corrected if they were outside the range.
However, this occurs outside the -co condition, so that calOffset then has a valid value in any case. If the -co option is missing, this corrects 0xFFFF (which is greater than 25) to 25.
What is the consequence: With every b command from the PC software to the Arduino, a calibration offset is transmitted, regardless of whether a -co option is specified or not. Without -co option 0xFFFF => 25 => B9 is transmitted. A Verbose output confirms this.
Just because the unfixed Arduino program ignores the value at B9, the error in the PC program has no effect. If afterburner.ino is already fixed, the calibration offset is set to 0.25V instead. See my fixed branch for changes in arduino.c.
As last: What should actually happen if the b command is called without -co?
Let's say I'm repairing the Afterburner hardware (pot or something) and need to recalibrate according to the instructions. Step 1: R9 in middle position Step 2: ./afterburner s Step 3: ./afterburner b What happens, there is an old offset in the Arduino EEPROM? I get incorrect values. Step 4: ./afterburner m ./afterburner b -co X