Small, low cost Picaxe chips are ideal for developing or enhancing control system functionality.
Battery powered computer systems really need some warning when the supply is failing or lacks the level of charge required to safely start.
The low power consumption of an 8 pin Picaxe makes the 08M2 a good candidate for this task.
I included a Picaxe in this seasons bird box design to control powering on/off the Raspberry Pi, which is at the heart of the system. I now want to use more of the functionality of the 08M2 by using the analogue to digital converter (ADC) feature.
The bird box system uses a 12V lead-acid battery which supplies power through a silicon diode to provide protection, just in case I'm careless enough to connect it the wrong way around.
Scaling the input voltage
The Picaxe runs from 5V derived from a linear regulator. So the ADC input range must be limited to 0-5Volts. My basic circuit just uses a voltage divider, like this:-
This should give me:-
Vpin3 = (14-0.7) x 10k/(18k+10k) = 4.75Volts
...for a fully charged battery, where the 0.7V represents the volt drop across the silicon diode. As an additional precaution I could fit a protection diode between the ADC input pin on the Picaxe and +5Volts like this:-
Picaxe test code
My test program for the Picaxe is very simple:-
'read adc 10 bit value and send via serial link
SerOut 0,N4800,(#w1,10) '10bit adc value & <CR>
I can test this on my Picaxe/Pi test rig either using minicom or a simple program (e.g. written in Gambas, Python or whatever).
I went one stage further and modified my BirdBox2015 controller, so that I could test performance with the final hardware configuration.
Since this circuit is designed to power the Pi on/off, I had to fit a manual over-ride to keep the Pi running. As the ULN2003 drivers are open collector Darlingtons, I just needed a link from IC1b pin 15 to 0V.
|Varying the ADC input with a potentiometer|
I also wrote a test program in Gambas to display individual ADC readings, equivalent voltages, and an average based upon 10 readings. Although I initially calculated the ADC reading-to-voltage conversion factor, I tweaked this by making small changes to the value until I had a reasonably close result, when compared to my digital voltmeter readings.
Its noisy in here
The variations in single readings were quite high; about 200mV.
Since I'm looking for consistency of readings to better than (say) 100mV, this is not acceptable. Note that consistency of readings (repeatablity) is more important in this application than absolute precision.
However, the variation for my averaged readings display was much better; probably about 75mV.
This indicated that the variation was probably due to noise, so I added a capacitor to the ADC input (which just happened to be a 10uF) and the variation between readings dropped to around 20mV.
As I'm using the ADC input for a very slow rate of change signal (i.e. battery level) its not a problem to slow down the response time of the system by adding large capacitors to the input circuit and/or using relatively slow averaging techniques in the code.
The next step is to determine typical battery voltage levels for "charged", "running low" and "do not switch on the Pi".