ClemensElflein / OpenMower

Let's upgrade cheap off-the-shelf robotic mowers to modern, smart RTK GPS based lawn mowing robots!
Other
4.64k stars 274 forks source link

Improve ADC accuracy #75

Open olliewalsh opened 1 year ago

olliewalsh commented 1 year ago

Use the charge current ADC when undocked to determine ADC offset, tweak the resistors values, and disable SMPS powersaving during ADC.

With this I get v_battery pretty close to the measured value

olliewalsh commented 1 year ago

Note: I'm using a picow, interested in feedback from someone using a pico as the 3.3v supply is slightly different

ClemensElflein commented 1 year ago

Thank you for the PR! Looks good!

olliewalsh commented 4 months ago

Thank you for the PR! Looks good!

  • Should we use the "raw" voltage for battery overvoltage protection instead of the corrected one? I'm thinking about what happens if the offset is "wrong" (e.g. is at 3V) and breaks overvoltage shutdown. For the overvoltage shutdown the noise and offset don't really matter I think
  • Do you know what the average error is you get? I assume it's <1V. Should we lower the 3V check?

Replaced the logic to check the high-level mode && GPS to determine that it's mowing, ensures it doesn't try to adjust the offset while docking. Switched to v_charge instead of charge_current adc as current is affected by regen AFAICT while v_charge is not (behind a diode). Limited offset to +-3% to ensure it's sane

pelle-c commented 3 days ago

I haven't tested this PR in my mower, but I did some measurements to see if it could work since I thought it was a great idea to have self calibration.

My 0.13.2 mb is somewhat modified since I had issues getting stable readings - I now have a capacitor over 3.3V and an "external" voltage reference to ADC_VREF. When my mower is not connected to the charger, the reported charge voltage is ~0.45V. If I short the related pin to GND, I get ~0.13V. If I understand this PR correctly, the charge voltage is measured and "averaged" while mowing. This value is then used to offset the measured voltages. In my case, that would mean that the voltage was offset with -0.45 instead of -0.13, which would lead to readings that are ~0.3V off from the real value.

From reading PRs here, and postings on discord, I've got the impression that you have some variations in the ADC errors. Like for me on this one, does the same apply for all boards or is just on 0.13.2, or only mine? Guess it's hard to tell without gathering info from users.