Add offset to reported Vin similar to M912
-
Short version........Is there, or could there be, a way to calibrate the Vin reading in a similar manner to M912 which adds an offset to the MCU temperature reading?
Longer version .........According to my multi-meter, the displayed Vin from DWC is about 0.3v low so I'd like to add an offset. I'm more inclined to believe my multi-meter unless someone can convince me that the reported Vin from the Duet board is more accurate. The reason why this is important is that I have a DC UPS and when power fails, the machine runs on battery power. From what I have read, for a 12V battery, a safe discharge level is about 50% which equates to a voltage of 12.2V. As I have two batteries in series, this would equate to 24.4V as being a safe minimum discharge value. I have an under voltage cut off device which will kill battery power at around 24.2V. So ultimately, I'd like to do a controlled pause and resume of any print that might be in progress when the voltage drops below 24.4V (say to 24.3V), which is awkward when Vin is being reported as 0.3V lower. I could of course do that pause when Vin shows 24.0v (because that relates to a true value of 24.3) but it would be a lot more elegant if the reported Vin was consistent with other measuring devices.
-
@deckingman I'm sorry, we don't provide a mechanism to calibrate the VIN reading.
The error in the VIN reading will be made up of various components:
- Error in the 3.3V supply that is used as the voltage reference. This should be no worse than +/-2% but it will generally be lower.
- Error in the voltage divider that feeds he ADC. Again, no worse than 2%, typically lower.
- Error in the ADC itself. Should be less than 1% in the mid-range that is used to measure VIN.
So the worst-case error should be +/- 5% but you would be very unlucky to have an error as large as this.
-
@dc42 said in Add offset to reported Vin similar to M912:
@deckingman I'm sorry, we don't provide a mechanism to calibrate the VIN reading.,,........
I know you don't, which is why I posted this request under the firmware wish list category. Would it be difficult to do? I'm not talking about anything complicated - just a simple offset.
In my case, the error is only 1.1 % but if I used the Duet Vin reading to shut down my printer when it's running on battery power and when those batteries reach 50% depletion, then in the event of a power fail, the run time would be circa 10 minutes, rather than circa 60 minutes.
As it happens, I've now added another external ESP32 with a voltage divider and trim pot that I can use to calibrate the measured Vin and get it reading the same as my multimeter. When the esp detects the voltage as being below 24.4 (24.1 according to DWC) then it switches a gpio high. This gpio is connected to a Duet gpio and I use an external trigger to sense that low to high transition and take the necessary action.
It works but it would have been nice not to have to jump through all those hoops. I guess I could have used a variable and meta commands but that would have meant running daemon.g which I'm trying to avoid because of the frequent writes to the SD card.
-
@deckingman as it's a one-off machine, what's wrong with adjusting the threshold voltage to account for that 1.1% error?
-
@deckingman said in Add offset to reported Vin similar to M912:
It works but it would have been nice not to have to jump through all those hoops. I guess I could have used a variable and meta commands but that would have meant running daemon.g which I'm trying to avoid because of the frequent writes to the SD card.
That's an interesting point. Does having a daemon.g cause writes to the SD card? I wouldn't have thought it would unless either the code in it generates a write or RRF updates the access time (not sure if it does).
-
@gloomyandy Dunno. I thought I read somewhere that it does but maybe not?
-
@dc42 said in Add offset to reported Vin similar to M912:
@deckingman as it's a one-off machine, what's wrong with adjusting the threshold voltage to account for that 1.1% error?
Nothing apart from the fact that it's compensating for something that isn't as accurate as it could be. By the same token, what's wrong with adding a simple offset to calibrate Vin in just the same way that you've implemented a simple offset to calibrate MCU temperature using M912?
I guess your answer will be that nobody else has requested it. In which case I'm minded to remember many years ago when I worked in the automotive industry and we required a part from Bosch. Their response was that they didn't stock it and couldn't order it because their system wouldn't allow parts to be ordered if none had ever been sold - catch 22. In this case, nobody else is calibrating Vin because there is no mechanism to do it.
If there is a case for calibrating the MCU temperature and that has been implemented, then I would have thought there is also a case for calibrating Vin.
But hey, it's clear that you aren't going to do it so I'll not waste any more of my time requesting features.
-
@deckingman said in Add offset to reported Vin similar to M912:
Nothing apart from the fact that it's compensating for something that isn't as accurate as it could be. By the same token, what's wrong with adding a simple offset to calibrate Vin in just the same way that you've implemented a simple offset to calibrate MCU temperature using M912?
If we implemented it in a similar way to M912 then you would have to add a command in config.g to specify the correction. But if you are going to do that, surely it's just as easy to define that correction in a variable, and then use that variable in the calculation of the M911 parameter?
If there is a case for calibrating the MCU temperature and that has been implemented, then I would have thought there is also a case for calibrating Vin.
The reason we allow MCU temperature to be calibrated is that on the SAM3X MCU used on the Duet 06/085, the uncorrected temperature can be off by a huge amount: up to 15% of the actual absolute temperature, i.e. +/-44C @ temperature 20C. Having the MCU temperature read -24C or +64C when it should read 20C is definitely unacceptable; whereas having VIN read e.g. 24.5V when in reality it is 24.0V is IMO acceptable in most applications. I appreciate that it may not be good enough if you are trying to manage a LiIon battery.
-
@deckingman said in Add offset to reported Vin similar to M912:
@gloomyandy Dunno. I thought I read somewhere that it does but maybe not?
Just reads. By default only every 10 seconds. If you need more, use a loop within. You'd have to get pretty crazy to cause a performance issue.