Summary of A new multi-function power supply unit for my Embedded Lab using PIC16F689
This article describes a multifunction lab power supply that provides fixed ±5 V plus an adjustable 1.25–9 V output, with integrated voltage, current monitoring and a frequency counter. A PIC16F689 measures the variable output voltage and load current via ADC (using a voltage divider and shunt plus op-amp), and Timer0 in counter mode measures external signal frequency (pre-amplified by a BF199 transistor). LM7805/LM7905 provide fixed rails; LM350 provides the adjustable output. The author notes software compensation for voltage drop across the shunt and plans future features using spare PIC I/O.
Parts used in the Multi-function Power Supply Unit for Embedded Lab:
- PIC16F689 microcontroller
- LM350 adjustable voltage regulator IC
- LM7805 voltage regulator IC
- LM7905 voltage regulator IC
- Center-tapped transformer (12 V AC rectified)
- Diodes for rectification
- 4700 µF filter capacitors
- Voltage divider resistors (for ADC scaling)
- Shunt resistor 0.286 Ω (made from 5 ft 22 AWG copper wire)
- Operational amplifier (for current-sense amplification)
- BF199 RF transistor (pre-amplifier for frequency counter)
- LCD display
- Miscellaneous passive components (resistors, capacitors)
- Wiring and connectors
One important parameter in embedded system designing is power consumption. This parameter is directly related to the battery lifetime, if the system is to be powered from a battery. In order to determine the power rating of your designed system, you need to know how much current the system draws from the source at a given voltage. While working on my projects, I usually measure current by placing an external ammeter in series with the current’s return path. This is not always convenient to do, and so I thought of making a special power supply unit for my lab that would display both voltage and current information on a LCD screen while prototyping my circuit. This way I can continuously monitor how much power my test circuit is drawing at a specific operating voltage.
This power supply unit provides fixed ±5 V as well as a variable dc voltage ranging from 1.25 V to 9 V. A PIC16F689 microcontroller is embedded into the power supply unit to measure the adjustable output voltage along with the load current. Besides, this unit also has a built-in frequency counter to measure the frequency of an external signal. The range is over 50 MHz. However, it has been tested up to 20.0 MHz, and works fine. There are still few I/O ports of PIC16F689 that are not used. So I am thinking about adding one or more features (like capacitance meter) to it. But that would be on my second version.
Theory
The fixed ±5 V power supplies are derived using LM7805 and LM7905 regulator ICs. A 12 V rectified output from a center-tapped transformer provides the dc inputs to these regulator ICs. For the variable dc output, a LM350 IC is used. LM350 is an adjustable 3-terminal positive voltage regulator that is capable of supplying in excess of 3A over a 1.2V to 33V output range. It requires only 2 external resistors to set the output voltage. Since my dc input is only 12 V (rectified output from the transformer), the regulated output from the LM350 IC would go up to 9 V (3 V less than the input, as specified in the datasheet). In order to obtain the full range of output voltage (up to 33 V) from LM350, you need a transformer with a higher output voltage. I rarely use power supply above 5 V in my projects, and therefore, a variable voltage source up to 9 V is good enough for me.
Next comes PIC16F689 microcontroller that measures the LM350 output voltage and current. You are right, I am implementing voltage and current measurement only to the LM350 output. The principles of voltage and current measurements using microcontroller were discussed in two of my posts: PIC-based digital voltmeter and How to measure dc current with a microcontroller. I am not going to repeat the details here. Both the parameters can be measured with built-in ADC channels of PIC16F689. Since the output voltage from LM350 could go higher than 5 V (up to 9 V in this situation), it is not directly measurable from an ADC channel. A simple voltage divider network using two resistors is incorporated to scale down the output voltage to the safe ADC input range (0-5 V). On the other hand, the current to be measured must be first converted into voltage so that it could me measureable too with the ADC channels. The current to voltage conversion can be done by placing a small value resistance (shunt) in series with the current path. The voltage drop across the resistance will then vary linearly with the current. I am using a 0.286 Ω resistor (Rs) made by myself by coiling a 5 ft long 22 AWG solid copper wire that has a plastic insulation on its outer surface (see the picture below).
Since this resistance is so small in value, the voltage drop across won’t be very high for small currents. Even for 1 A of current, the voltage drop across it would be only 0.286 V. To improve the resolution (and hence accuracy) of current measurement, this voltage must be amplified before the AD conversion process. An operational amplifier with a suitable gain can do this task. The figure below shows how this whole technique works.
An interesting thing to be noted here is that the output voltage across the load (Vo) is actually the measured voltage (Vm) minus the voltage drop across Rs (Vs). For small load current, the difference between Vm and Vo won’t be very much, but it could be significant for higher current. For 1 A of load current, the output voltage across the load is 0.286 V less than the measured output voltage from LM350. This error will be corrected later in the software part by subtracting Vs from Vm.
The frequency counter uses Timer0 module in counter mode to measure the frequency of an external signal. A single transistor preamplifier stage is used to boost the low amplitude signals before they are sent to the Timer0 module for counting. An easily available BF199 RF transistor is used for this purpose.
Circuit Diagram
As mentioned earlier, two linear regulator ICs (LM7805 and LM7905) are used to derive fixed ±5 V supply. A center-tapped transformer output is rectified (using diodes) and filtered (using 4700 µF capacitors) to obtain unregulated ±12 V dc that serve as inputs to both the regulator ICs. The circuit diagram below shows all the components and their connections required for the fixed power supply.
For more detail: A new multi-function power supply unit for my Embedded Lab using PIC16F689
- What voltage ranges does this power supply provide?
It provides fixed ±5 V and an adjustable dc output from 1.25 V to 9 V with the given 12 V input. - Which microcontroller is used to measure voltage and current?
PIC16F689 is used to measure the LM350 output voltage and load current via its ADC channels. - How is the adjustable output voltage limited to 9 V?
Because the LM350 requires about 3 V dropout from the 12 V rectified input, limiting the regulated output to about 9 V. - How is the output voltage measured by the PIC if it can exceed 5 V?
A simple voltage divider scales the LM350 output down to the ADC safe range of 0–5 V. - How is current measured in this design?
Current is measured by a 0.286 Ω shunt in series with the return, converting current to a voltage which is amplified before ADC conversion. - How does the design compensate for voltage drop across the shunt?
The software corrects the output voltage by subtracting the shunt voltage drop Vs from the measured voltage Vm. - What is the frequency range of the built-in frequency counter?
The frequency counter range is over 50 MHz, tested up to 20.0 MHz in practice. - How is the external signal prepared for frequency counting?
A single-transistor preamplifier (using BF199) boosts low-amplitude signals before feeding Timer0 in counter mode. - Which regulators provide the fixed ±5 V rails?
LM7805 provides +5 V and LM7905 provides −5 V, fed from the rectified center-tapped transformer outputs.
