Fascinating stuff, Julian ! Thank you so much. I've used the 12F683 in some of my projects - it's quite a nice microcontroller. Really looking forward to your solution. AND, I always learn something new from your videos.
That doesn't sound like a good idea to me. The voltage regulator will drift with age, temperature, load,... It will need recalibrating regularly. Why not use a purpose built voltage reference?
You don't need a switch at all; simply use the input voltage to enter the calibration routine and then to calibrate the unit: After manufacture power up the PWM5 with a sequence of 'unnatural' voltages e.g. 5V for 1s, 10V for 1s, 5V for 2s then finish on a voltage you would like to calibrate out e.g. 13.8V. Then use that measured ADC result and the error against the actual 13.8V to 'autocal' and set the calibration offset and store in EEPROM.
Why not use a LM4040 Voltage Reference? It would be simpler than your solution I reckon. But as a software guy, rather than hardware, I do admire your version.
Hi Julian, I've found that these 5V linear regulators tend to drift considerably with time and temperature. This means calibration would have to be done somewhat often. Have you had a look at the TL431 adjustable precision reference IC? From my experimenting, a stable and 1% accurate voltage reference can be achieved easily (and cheaply). I'm working on a precise LDO to source considerable amounts of current as well. If you don't need to do that though, you can just wire the output of the TL431 to the ADC reference pin.
Unfortunately, I've run out of pins on the 12F683. I suppose the uC could tolerate a slightly higher voltage on its Vref pin if Vdd were slightly less than 5V. Much testing would be needed.
Looking at a schematic of the PWM5, it seems that one source of the pin scarcity is that you use two of the eight pins to manage the charge pump. If you added an external inverter you could manage the charge pump with a single pin; if you added a dedicated charge pump IC you could save two. Then, you'd be able to have a dedicated voltage reference on the chip, either as VREF for the PIC itself or for periodic re-calibration.
Do pic micros not have band gap diodes to reference the ADC against? When ever I've used an ADC for low to medium applications the internal references have proven to be good enough eliminating the need for vcc ratiometric measurements. If you're working with things like thermistors in battery powered applications then ratiometric has a much better performance.
Pic is a pretty poor choice these days, they often have very few low functionality peripherals and are not as cheap as you'd imagine. Far East microcontrollers are often cheaper and have more rounded functionally, for example hdsc and paduk both make ranges of cortex m0+ micros some with specialised peripherals like 24bit ADCs while maintaining a very low price point.
Brilliant - simply brilliant, and so wonderfully complete. This has set me thinking, and the cat is standing by to be amazed... She won't be half as amazed as I will be, if I can do something similar with ATMega328!!!
Julian, what about a ATmega328. didn't you do a video about measuring it's own supply voltage, it could calibrate itself. you could also do temperate compensation with the on die sensor, I'm sure you did a video on that also.
@@motormadness9975 Yes just a bit, like 100 times. just depends on what you have, maybe a ATtiny5 @£0.26 or PIC10F222 @£0.36, will do the same thing, i
That's some interesting software gymnastics! :) I have to wonder though what the point of this type of calibration is (for this particular use-case) given that the end user won't have access to the 5v supply anyway? You'd be better off hard-coding in a value, seeing as only you will be able to calibrate them, and that's even putting the natural drift of the regulator over time as it ages.
instead of a button you can use the microcontroller to set these values. even dynamically. with some trickery the uC can sense its own vcc... a would recommend to not write the value to eeprom instantly and rather use the ram or some register to store the value and only write on power off and read on system boot. if you add a big enough cap across the supply rail you should have enough time to write to eeprom safely in tgese occasions.
Julian, Isn't a switch going to be the weak point on the design? ... or are you thinking of something like a hall effect detector and use a magnet to make the adjustments?
Instead of adding a button, why not just add pins or a socket to which a button can be attached? I doubt a button would survive long enough outdoors, even if potted/coated etc, to be used for more than one calibration.
I was really hoping you would have some novel way to do this without resorting to adding a button. I do like the comment about using a reed switch so it has a better chance at outdoor survival.
Voltage will fluctuate proportionally with incoming voltage, which is not what you want for a voltage reference if youre going to use it to monitor the incoming voltage itself. You want it to be as stable and accurate as possible, and a regulator will provide a (relatively) fixed output voltage independent of the input voltage, at least until its dropout voltage.
@@TomStorey96 I made a 12v battery capacity tester with an arduino basically sense voltage and run the load down to the cut off V . Cannot get it right! Ended up using 2 trim pots for voltage and current dividers and it worked great....until I put it on a different battery and it threw the readings out by about 0.5 v I would accept 0.1 ish. Is that a reasonable target without considering the many other variables of lead acid battery drop testing.
I wish there was something like an electronic component that can do that job. can someone try to invent a "voltage reference" or something of that nature?? 🤔
I would use the Forward Voltage Drop of a LED as your voltage Reference ? Sounds like that means would be more accurate then the one your using. A pile cheaper as well. My bet is the accuracy would be better then the seemingly low tolerances of those Voltage regulators. Using the LED looks like you could maintain a accuracy of like .08v over the LP2905's 0.15 tolerance. electronics.stackexchange.com/questions/77450/voltage-drop-assumption-on-diodes-leds-etc
Why not? Assembly is fun, and its more of a challenge than C so it gets your brain working harder which is a good thing! Im currently working on a Z80 based project and writing that in assembly. But I also write C for other projects. Each language has a time and a place depending on what youre trying to achieve.
Fascinating stuff, Julian ! Thank you so much. I've used the 12F683 in some of my projects - it's quite a nice microcontroller. Really looking forward to your solution. AND, I always learn something new from your videos.
That doesn't sound like a good idea to me. The voltage regulator will drift with age, temperature, load,...
It will need recalibrating regularly.
Why not use a purpose built voltage reference?
You don't need a switch at all; simply use the input voltage to enter the calibration routine and then to calibrate the unit:
After manufacture power up the PWM5 with a sequence of 'unnatural' voltages e.g. 5V for 1s, 10V for 1s, 5V for 2s then finish on a voltage you would like to calibrate out e.g. 13.8V. Then use that measured ADC result and the error against the actual 13.8V to 'autocal' and set the calibration offset and store in EEPROM.
Why not use a LM4040 Voltage Reference? It would be simpler than your solution I reckon. But as a software guy, rather than hardware, I do admire your version.
Or a REF5050. Or any other stable, precise regulator...
Hi Julian, I've found that these 5V linear regulators tend to drift considerably with time and temperature. This means calibration would have to be done somewhat often. Have you had a look at the TL431 adjustable precision reference IC? From my experimenting, a stable and 1% accurate voltage reference can be achieved easily (and cheaply).
I'm working on a precise LDO to source considerable amounts of current as well. If you don't need to do that though, you can just wire the output of the TL431 to the ADC reference pin.
Unfortunately, I've run out of pins on the 12F683. I suppose the uC could tolerate a slightly higher voltage on its Vref pin if Vdd were slightly less than 5V. Much testing would be needed.
I wonder how stable an AMS1117 is.
Looking at a schematic of the PWM5, it seems that one source of the pin scarcity is that you use two of the eight pins to manage the charge pump. If you added an external inverter you could manage the charge pump with a single pin; if you added a dedicated charge pump IC you could save two.
Then, you'd be able to have a dedicated voltage reference on the chip, either as VREF for the PIC itself or for periodic re-calibration.
Your videos make me want to PIC up Pic programming...
His videos make me want to never go down that rabbit hole :D
Do not fear the rabbit hole :)
@@benbaselet2026 :) take the blue pill then :)
@@none0049 STM32 is actually a very good option for someone wanting to upgrade from Arduino.
@@none0049 Yes, esp32 might be it :)
hi j,,i have microchip pic16c74b .its program for an inverter ,is there away to MCLR it to power up or need to write code.
You can use an external precise voltage reference for self-calibration after powered on.
a cool project for JLC PCB, your own lithium battery charging / protection board based on the TP4056!
You can get them prebuilt, with μUSB power connectors, at about 5 for a €$
i know, but wheres the fun in that? julian could've bought any solar charge controller online, but he chose to make his own, because why not!
Do pic micros not have band gap diodes to reference the ADC against? When ever I've used an ADC for low to medium applications the internal references have proven to be good enough eliminating the need for vcc ratiometric measurements. If you're working with things like thermistors in battery powered applications then ratiometric has a much better performance.
Checked, that pic doesn't not have a reference but this 8 pin pic micro does PIC16F15313
Some PICs do have a voltage reference of 1.024, 2048, 4096mV but not all of them.
Pic is a pretty poor choice these days, they often have very few low functionality peripherals and are not as cheap as you'd imagine. Far East microcontrollers are often cheaper and have more rounded functionally, for example hdsc and paduk both make ranges of cortex m0+ micros some with specialised peripherals like 24bit ADCs while maintaining a very low price point.
Dear what is the compiler has been used here?
Brilliant - simply brilliant, and so wonderfully complete.
This has set me thinking, and the cat is standing by to be amazed...
She won't be half as amazed as I will be, if I can do something similar with ATMega328!!!
Button or shorting pins will mess up your conformal coating. Use a voltage reference???
If you are worried about the conformal coating, red switches are a great solution.
@@randomelectronicsanddispla1765 Will blue switches work too? :P
@@randomelectronicsanddispla1765 maybe you mean reed switches?
Julian, what about a ATmega328. didn't you do a video about measuring it's own supply voltage, it could calibrate itself. you could also do temperate compensation with the on die sensor, I'm sure you did a video on that also.
oh fancy although the on board sensor is pretty darn bad. but maybe just good enough for the job
the 328 is complete overkill for such a rudimentary application
@@motormadness9975 Yes just a bit, like 100 times. just depends on what you have, maybe a ATtiny5 @£0.26 or PIC10F222 @£0.36, will do the same thing, i
@@urugulu1656 +3c +-2c better than nothing and better than spending extra on components if it's build in. really depends on how much you want to spend
That's some interesting software gymnastics! :)
I have to wonder though what the point of this type of calibration is (for this particular use-case) given that the end user won't have access to the 5v supply anyway?
You'd be better off hard-coding in a value, seeing as only you will be able to calibrate them, and that's even putting the natural drift of the regulator over time as it ages.
It is in effect hard coded.
instead of a button you can use the microcontroller to set these values. even dynamically. with some trickery the uC can sense its own vcc... a would recommend to not write the value to eeprom instantly and rather use the ram or some register to store the value and only write on power off and read on system boot. if you add a big enough cap across the supply rail you should have enough time to write to eeprom safely in tgese occasions.
Julian, Isn't a switch going to be the weak point on the design? ... or are you thinking of something like a hall effect detector and use a magnet to make the adjustments?
The switch will be used only during manufacture - then removed prior to the charge controller being sealed inside its casing.
Nice idea, or just plain old reed switch.
Instead of adding a button, why not just add pins or a socket to which a button can be attached? I doubt a button would survive long enough outdoors, even if potted/coated etc, to be used for more than one calibration.
Or a reed switch.
Why not use a PIC with an integrated voltage reference?
Good idea
Very interesting to see how the pic responds to these different events.
I was really hoping you would have some novel way to do this without resorting to adding a button. I do like the comment about using a reed switch so it has a better chance at outdoor survival.
Whats wrong with using a 28 turn pot as a voltage divider? instead of a fixed 5V Regulator.
Useful trimpot commentary - forum.allaboutcircuits.com/threads/trimpot-reliability.113915/ tldr - lots of downsides
Voltage will fluctuate proportionally with incoming voltage, which is not what you want for a voltage reference if youre going to use it to monitor the incoming voltage itself. You want it to be as stable and accurate as possible, and a regulator will provide a (relatively) fixed output voltage independent of the input voltage, at least until its dropout voltage.
@@CTCTraining1 thanks for the link I had a read through.
@@TomStorey96 I made a 12v battery capacity tester with an arduino basically sense voltage and run the load down to the cut off V . Cannot get it right! Ended up using 2 trim pots for voltage and current dividers and it worked great....until I put it on a different battery and it threw the readings out by about 0.5 v I would accept 0.1 ish. Is that a reasonable target without considering the many other variables of lead acid battery drop testing.
Voltage would vary with battery voltage.
I wish there was something like an electronic component that can do that job. can someone try to invent a "voltage reference" or something of that nature?? 🤔
these are actual pieces of hardware already. they are around for ages.
@@urugulu1656 well that flew right over your head
@@motormadness9975 dont know what you mean by that but maybe theR6565 meant that sorta ironic...
i used to use pic all the time, cant believe how they fell behind arduino and esp in the hobby world.
How are you going to ensure that the reset button isn't pressed accidetally?
It needn't be soldered in to calibrate the unit.
Interesting.
I would use the Forward Voltage Drop of a LED as your voltage Reference ? Sounds like that means would be more accurate then the one your using. A pile cheaper as well. My bet is the accuracy would be better then the seemingly low tolerances of those Voltage regulators. Using the LED looks like you could maintain a accuracy of like .08v over the LP2905's 0.15 tolerance. electronics.stackexchange.com/questions/77450/voltage-drop-assumption-on-diodes-leds-etc
Like other diodes, forward voltage is probably temperature dependent.
And for a LED, even the incident light is a factor.
@@ciano5475 Encapsulate. Solved.
Hi Julian. PIC & Atmel compiler: gcbasic.sourceforge.net/Typesetter/index.php/Home
This "Great Cow Basic" compiler is great and FREE!
Why program in asm when its 2k19 and u can do it in c
And it will also remove those "GOTO's" ;-)
I like to program the bare metal - C is for snowflakes ;)
Why not? Assembly is fun, and its more of a challenge than C so it gets your brain working harder which is a good thing!
Im currently working on a Z80 based project and writing that in assembly. But I also write C for other projects. Each language has a time and a place depending on what youre trying to achieve.
@@JulianIlett At least it's not Mark 1 Autocode! lol
@@JulianIlett "It was eventually realized that programming in assembly language required a great deal of intellectual effort." From Wiki!! lol
Blinkenlights :)
Maybe add a button lockout switch, to stop accidental pushes.