VDD monitoring must be such a common requirement - battery powered or even solar ... obvious question - is there enough power to run ?
PIC people seem to advocate / suggest measuring using ADC and a voltage reference, even going as far as using an FET to switch on local VRef sources to minimize power drain ... and then there's an analogue comparator.
In my case, the PIC is running some low power house keeping stuff and if there's enough accumulated power then do some other things - WiFi for example.
What is the "best / easiest" way to keep an eye on power status - say accumulated voltage in a solar charged super capacitor ?
There seems to be little comment / suggestion around on the internet so I was working along a solution when I found Microchip's TC54 application notes.
I'm confused, a most fundamental parameter is that of operating voltage and all PICs seem to make measuring VDD complicated yet it seems the most logical thing to do - get the PIC to work it out ... and then, here's Microchip advocating the use of a dedicated power monitoring chip.
Practical / constructive comment would be great and much appreciated - what's best practice ?
Thanks
Andrew
Last edit: Andrew Jameson 2021-04-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have used the internal FVR for ADC measurements with good success. Using it for decision making on my solar charged LIFEPO4 powered flashlight, as seen in my icon for years.
IfFVR1024<71Then'73 by inspection, OVLO(1.024V/3.65V)*255 = 72'Battery voltage high Burn some ma'sandcheckagainOverVolt=Truesavebat=FalseEndIfIfFVR1024>99Then'UVLO(1.024/2.7V)*255 = 97'Battery voltage low so wait for charge from PVOverVolt=Falsesavebat=trueEndIfIfFVR1024<=99ANDFVR1024>=71Then'Battery voltage good so continueOverVolt=Falsesavebat=FalseEndIf
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have actually used something similar to that to show when a 12V lead acid battery was losing charge. I had a 10V zener in series with an LED and low value current limiting resistor. The 10V dropped by the zener and the 1.8V (or so) dropped by the LED meant that if the battery voltage fell much below 12V the LED faded. For a battery with a full charge voltage of just under 14V this worked very well. Once the LED faded it was time to charge the battery.
This was one of the very first "things" I designed from scratch, a satellite dish alignment meter. I was so proud of it! It worked well, we'd bought an expensive one at work that was impossible to use. Not only did it need constant adjustment while setting up the dish but it was so wideband in it's frequency range that on one very memorable occasion we kept pointing the satellite dish at the sun as it was in close position with the satellite. We had to wait for over an hour for the sun to move before we managed to align the dish. The second problem with the bought unit was that it relied on the cable and receiver to be in place as this provided power to the alignment meter. One major downside being that if the position of the dish/house/wall/satellite was marginal to allow a clear view of the satellite, you didn't find out if the dish would actually see the satellite, until the wire had been installed and dish screwed to the wall. If it didn't work, you would have to start again, and the customer left with holes in the wall.
The meter I designed had a sound decoder built in so it was definite when alignment was {almost} correct as you would be able to hear Sky News, point it at the sun and you'd only hear hiss! Being battery powered allowed you to hold the dish in hand in the garden and aim it at the satellite allowing the angles to be judged before putting the dish on the wall or running any wires. We used that meter daily from the day I finished soldering it. Never used the bought one again. It was used right up until Sky started installing dishes below cost. We even used it for installing digital dishes, the sound didn't work on the digital channels, but the rest of the meter still worked for aligning the dish.
The design earned me almost £200 as it was printed in Television Magazine. In true Lincolnshire dialect, "I were reet pleased wi' me'sen!" A slap up meal at Mrs Miggins followed!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had this problem some time ago. I was using a LCD that needed the contrast adjusting according to the battery level. The way to do it is to use Vdd and Vss as the references and the fixed voltage reference as the input to the ADC. At the time this was not possible in GCB so I wrote it in assembly and why not also do the ADC conversion in ASM as well. This is using a 16F18326. The voltage level is stored in BAT2 as a 16 bit word.
I modified it only to reference the 16F1829. I'm using the complete code in a Li-Ion clock, it shows the battery status on the LCD and once the battery goes below a measured 3.3 volts puts the processor into a deep sleep to try to prevent severe discharge of the battery.
So far this has worked well enough to alert me to the battery level as I'd hoped.
SubGetBattery'1) Enable and set the FVR (fixed voltage reference) register for 2.048V setting.'2) Enable and read the A-D FVR ;This is an internal register'3) You now know what the battery voltage is at that time according to:''2.048V / BatVolts = A-D FVR / 255 ;(8 bits is close enough)';Promote values by 100'BatVolts = 52224 / A-D FVR ;A-D FVR reading should be around 175 at 3VLetRefVolts=AD16F1829(FVR)'internal a-d of FVRLetBatVolts=52224/RefVoltsEndSubFunctionAD16F1829(INadport)' If adport < 5 Then ANSELA = adport + 1 'turn off digital input ANSA2' If adport >= 5 & adport < 12 Then ANSELB = adport + 1' If adport > 11 Then' ANSELA = 0 'internal FVR, DAC, or Temp Indicator conversion' ANSELB = 0' end ifrotateadportleftsimplerotateadportleftsimpleADCON0=adport'adportADON=1'ENABLE ADC AND START CONVERSIONWait10usADGO=1'need 200us min for temp moduleADCPOLL:BTFSCADCON0,ADGOGotoADCPOLLADCON0=0ANSELA=0'Shut down adc moduleAD16f1829=ADRESHEndFunction
The code looks very similar in principle to David's above.
A quick update.
I was testing a project that I'd used this on with a 18F15Q40. Of course it didn't work.
As it took me a while to get this to work I thought I would make a note. It may help others and it will certainly help me.
'The FVR register or location must be changed.#DefineFVR=62'was 31 for 16F1829
SubGet_Battery'1) Enable and set the FVR (fixed voltage reference) register for 2.048V setting.'2) Enable and read the A-D FVR ;This is an internal register'3) You now know what the battery voltage is at that time according to:''2.048V / BatVolts = A-D FVR / 255 ;(8 bits is close enough)';Promote values by 100'BatVolts = 52224 / A-D FVR ;A-D FVR reading should be around 175 at 3VDoRefVolts=ADFetch(FVR)'internal a-d of FVRBatVolts=52224/RefVoltsEndSubFunctionADFetch(INadport)' If adport < 5 Then ANSELA = adport + 1 'turn off digital input ANSA2' If adport >= 5 & adport < 12 Then ANSELB = adport + 1' If adport > 11 Then' ANSELA = 0 'internal FVR, DAC, or Temp Indicator conversion' ANSELB = 0' end if'no rotate needed...FVREN=1ADPCH=ADPort'adportADON=1'ENABLE ADC AND START CONVERSIONWait10uSADGO=1'Start conversionADCPOLL:BTFSCADCON0,ADGOGotoADCPOLL'name of function has been changed so the'return reflects the new function nameADFetch=ADRESH'Read resultEndFunction
Last edit: mkstevo 2022-03-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your comments - they've been very helpful. It's much as I thought and it's very strange to realize how such a fundamental requirement has not been addressed and featured within the operation of a PIC. Microchip advocate the use of dedicated power monitoring chip whilst not considering how a PIC might embody that function.
I like the Zener / LED solution - my initial idea was to use the ADC ... for me it's an early learning adventure and it's clear that, even today, there is much to explore anew.
I'll probably order a range of TC54s too.
Again thank you for your input.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I guess that using a dedicated power monitor has the advantage of accuracy. As the supply to the PIC drifts, so must the accuracy of the reference that is used to measure the supply could be their thought process?
For roughly obtaining an indication of the state of charge, using the internal ADC is probably "good enough" for most non critical applications.
An external monitor might have the capability to isolate the supply to the processor once the supply reaches the minimum level, with minimal drain on the supply once this has been done to prevent total discharge and potential permanent damage to the battery.
And I don't doubt MicroChip have some lovely supply monitoring chips that they would love to sell to you...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Zenner diodes are a rough and ready solution to getting a voltage reference. I would imagine that the FVR in PICs is a little more sophisticated (like a LT1009 or equivalent) so is much less susceptible to changes in voltage with load and supply voltage (as zenners are). So I would use the FVR and the ADC rather than buy an extra chip as it may be equally as good.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
you could use the millis function to take adc reading and then periodically and check battery for rapid going low voltage.
like if you measured the battery and stored its volts then periodically then if the last measurement drop was beyond a value then the battery is going dead soon...not an expert.
Last edit: stan cartwright 2021-04-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many PIC 18F chips have a programmable HLVD peripheral module. When enabled, it can set a flag or trigger an interrupt when Vdd falls below a programmed threshold voltage. Not available on 16F Chips but is included on the new 14 and 20 pin 18F Q40 and Q41 chips as well as many, many other 18F Microcontrollers. Like most if not all K40, K42, Q10, Q41, Q43 and so on
Should make Vdd Monitoring very simple unless you are committed to PIC 16F/12F chips.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
VDD monitoring must be such a common requirement - battery powered or even solar ... obvious question - is there enough power to run ?
PIC people seem to advocate / suggest measuring using ADC and a voltage reference, even going as far as using an FET to switch on local VRef sources to minimize power drain ... and then there's an analogue comparator.
In my case, the PIC is running some low power house keeping stuff and if there's enough accumulated power then do some other things - WiFi for example.
What is the "best / easiest" way to keep an eye on power status - say accumulated voltage in a solar charged super capacitor ?
There seems to be little comment / suggestion around on the internet so I was working along a solution when I found Microchip's TC54 application notes.
I'm confused, a most fundamental parameter is that of operating voltage and all PICs seem to make measuring VDD complicated yet it seems the most logical thing to do - get the PIC to work it out ... and then, here's Microchip advocating the use of a dedicated power monitoring chip.
Practical / constructive comment would be great and much appreciated - what's best practice ?
Thanks
Andrew
Last edit: Andrew Jameson 2021-04-08
I have used the internal FVR for ADC measurements with good success. Using it for decision making on my solar charged LIFEPO4 powered flashlight, as seen in my icon for years.
Coild a zener diode be output high if battery ok?
I have actually used something similar to that to show when a 12V lead acid battery was losing charge. I had a 10V zener in series with an LED and low value current limiting resistor. The 10V dropped by the zener and the 1.8V (or so) dropped by the LED meant that if the battery voltage fell much below 12V the LED faded. For a battery with a full charge voltage of just under 14V this worked very well. Once the LED faded it was time to charge the battery.
This was one of the very first "things" I designed from scratch, a satellite dish alignment meter. I was so proud of it! It worked well, we'd bought an expensive one at work that was impossible to use. Not only did it need constant adjustment while setting up the dish but it was so wideband in it's frequency range that on one very memorable occasion we kept pointing the satellite dish at the sun as it was in close position with the satellite. We had to wait for over an hour for the sun to move before we managed to align the dish. The second problem with the bought unit was that it relied on the cable and receiver to be in place as this provided power to the alignment meter. One major downside being that if the position of the dish/house/wall/satellite was marginal to allow a clear view of the satellite, you didn't find out if the dish would actually see the satellite, until the wire had been installed and dish screwed to the wall. If it didn't work, you would have to start again, and the customer left with holes in the wall.
The meter I designed had a sound decoder built in so it was definite when alignment was {almost} correct as you would be able to hear Sky News, point it at the sun and you'd only hear hiss! Being battery powered allowed you to hold the dish in hand in the garden and aim it at the satellite allowing the angles to be judged before putting the dish on the wall or running any wires. We used that meter daily from the day I finished soldering it. Never used the bought one again. It was used right up until Sky started installing dishes below cost. We even used it for installing digital dishes, the sound didn't work on the digital channels, but the rest of the meter still worked for aligning the dish.
The design earned me almost £200 as it was printed in Television Magazine. In true Lincolnshire dialect, "I were reet pleased wi' me'sen!" A slap up meal at Mrs Miggins followed!
I had this problem some time ago. I was using a LCD that needed the contrast adjusting according to the battery level. The way to do it is to use Vdd and Vss as the references and the fixed voltage reference as the input to the ADC. At the time this was not possible in GCB so I wrote it in assembly and why not also do the ADC conversion in ASM as well. This is using a 16F18326. The voltage level is stored in BAT2 as a 16 bit word.
I took the code supplied by @kent_twt4 in this thread: https://sourceforge.net/p/gcbasic/discussion/579126/thread/810b24c927/#5d2d
I modified it only to reference the 16F1829. I'm using the complete code in a Li-Ion clock, it shows the battery status on the LCD and once the battery goes below a measured 3.3 volts puts the processor into a deep sleep to try to prevent severe discharge of the battery.
So far this has worked well enough to alert me to the battery level as I'd hoped.
The code looks very similar in principle to David's above.
The full code showing the battery monitoring in action is in my beeping clock thread:
https://sourceforge.net/p/gcbasic/discussion/projects&guides/thread/02b26cce7f/#cc1a
A quick update.
I was testing a project that I'd used this on with a 18F15Q40. Of course it didn't work.
As it took me a while to get this to work I thought I would make a note. It may help others and it will certainly help me.
Last edit: mkstevo 2022-03-03
Thank you for your comments - they've been very helpful. It's much as I thought and it's very strange to realize how such a fundamental requirement has not been addressed and featured within the operation of a PIC. Microchip advocate the use of dedicated power monitoring chip whilst not considering how a PIC might embody that function.
I like the Zener / LED solution - my initial idea was to use the ADC ... for me it's an early learning adventure and it's clear that, even today, there is much to explore anew.
I'll probably order a range of TC54s too.
Again thank you for your input.
I guess that using a dedicated power monitor has the advantage of accuracy. As the supply to the PIC drifts, so must the accuracy of the reference that is used to measure the supply could be their thought process?
For roughly obtaining an indication of the state of charge, using the internal ADC is probably "good enough" for most non critical applications.
An external monitor might have the capability to isolate the supply to the processor once the supply reaches the minimum level, with minimal drain on the supply once this has been done to prevent total discharge and potential permanent damage to the battery.
And I don't doubt MicroChip have some lovely supply monitoring chips that they would love to sell to you...
Zenner diodes are a rough and ready solution to getting a voltage reference. I would imagine that the FVR in PICs is a little more sophisticated (like a LT1009 or equivalent) so is much less susceptible to changes in voltage with load and supply voltage (as zenners are). So I would use the FVR and the ADC rather than buy an extra chip as it may be equally as good.
you could use the millis function to take adc reading and then periodically and check battery for rapid going low voltage.
like if you measured the battery and stored its volts then periodically then if the last measurement drop was beyond a value then the battery is going dead soon...not an expert.
Last edit: stan cartwright 2021-04-10
Many PIC 18F chips have a programmable HLVD peripheral module. When enabled, it can set a flag or trigger an interrupt when Vdd falls below a programmed threshold voltage. Not available on 16F Chips but is included on the new 14 and 20 pin 18F Q40 and Q41 chips as well as many, many other 18F Microcontrollers. Like most if not all K40, K42, Q10, Q41, Q43 and so on
Should make Vdd Monitoring very simple unless you are committed to PIC 16F/12F chips.