WiSPCaR – Wifi Station Power Controller And Reporter

It’s amazing what you can do with a 70 cent computer. Actually it’s amazing that there are 70 cent computers! The PIC12F510 is a complete computer – flash program memory, RAM, GPIO pins, internal clock and two A/D converter inputs in a tiny 8 pin chip. All for just 70 cents (Qty 100) from Digikey!

I am using a PIC microcontroller to help Yahel from AirJaldi monitor remote Wifi stations. You see AirJaldi runs a network of Wifi stations (access points and backbone links) in Northern India. Some of these are rather remote, like sitting on top of a temple half way up a mountain.

They have several problems:

  1. Electricity may not be available, so they use solar panels with back up batteries. Even when mains is available, it is of varying quality (brown-outs, surges, and blackouts).
  2. If the router hangs, it may take days for some one to get out there and reset it.
  3. If a battery is dying, or a solar panel stops working, it would be nice to know before the system fails entirely.

So Yahel and I have have designed a small micro controller based device called WiSPCaR – Wifi Station Power Controller And Reporter.

Here is what is does:

  1. Measures voltage (5-60V) and current (0-5A) of the wifi station power supply.
  2. A Watchdog Timer resets the Wifi station if Wispcar does not receive a certain code every 3 minutes. To reset the Wifi station Wispcar shuts off the power for 5 seconds.
  3. Sleep function – a command line “sleepXXXX” sent to Wispcar will put the power supply to sleep for XXXX seconds. This can dramatically reduce the cost of the power supply (e.g. solar panel and battery) by cutting off power when not needed at night. Yahel suggested we could wake up the Wifi Station every 15 minutes, look around for any traffic, then put it back to sleep again if it’s quiet. This way emergency late-night traffic could still get through.
  4. Current consumption (estimated) will be around 10mA, so Wispcar will not affect battery life or dimensioning of the power system. Most of this (8mA) is in the 5V regulator needed for Wispcar, the actual PIC draws only 0.25mA!
  5. We would like to run Wispcar from 8-60VDC, to cater for power supply systems like Power Over Ethernet (PoE) which are nominally 48V, down to solar power systems with nearly flat batteries.

In practice the Wifi station consists a router (like a WRT54G or Mikrotik board). They generally have some sort of RS232 (console) port available, although you may need to solder a few wires to the motherboard to get to it. Another alternative is Ethernet, however this requires a fancier micro controller, pushing the Bill of Materials (BOM) cost up significantly.

So Wispcar connects to the RS232 port of the router. Every 1 second Wispcar send lines like this:
040 029 032 004 000 0 000 w
040 029 032 003 000 0 000 w
040 029 032 002 000 0 000 w

Which means:
| Isense
| | Last char received (ASCII)
| | | Last char received (decimal)
| | | | Watchdog timeout counter
| | | | | Watchdog fire counter
| | | | | | Sleep state machine state
| | | | | | | Sleep timeout counter
| | | | | | | |
040 031 032 012 000 0 000 w---reason for last restart
b - Wispcar (re)booted
w - watchdog timer fired
s - we went to sleep

This information can be parsed by the router, logged, emailed off the the Network Operations Centre (NOC) etc. After a few seconds we get something like:
040 029 032 004 000 0 000 w
040 029 032 003 000 0 000 w
040 029 032 002 000 0 000 w
040 029 032 001 000 0 000 w
040 008 032 000 005 0 000 w
040 008 032 000 004 0 000 w
040 008 032 000 003 0 000 w

You can see the watchdog count down to zero, and cut off the power (dropping the current to near zero). The voltage and current readings are 8 bit numbers from the PIC A/D converter. You need to scale them to get the actual Volts and Amps. Here is a plot of the A/D converter output code against actual measured current:


The breadboarded prototype has been running for several days without incident, controlling power to a dummy load (20 ohm, 5W resistors).

Next, I will build a soldered version and set it up with a solar powered Wifi station in my back yard. The software is largely complete with all 4 functions working.

We have set up a Wispcar SVN repository containing the software, schematic, and some documentation.

The Wispcar source code is all in assembler. This wasn’t too hard until I started writing string handling functions (to make the PIC parse the sleepXXX command)! Any PIC gurus out there – pls feel free to suggest improvements!

Lots more to do – for example we need to test Wispcar with “dirty power”, make sure it keeps working with voltage spikes, lightning etc.

Neat features

  1. Yahel suggested we don’t use line drivers for RS232 between the router and the PIC, just 3V3 levels.
  2. Software UART implemented in PIC assembler.
  3. 31 cent high-side current sensor based on this design.
  4. The power switch is designed to be “normally closed”, so that if the PIC hangs power will continue to be supplied to the Wifi station.
  5. Very Cheap – parts cost of around $2 (Qty 100 from Digikey) – ideal for the developing world.
  6. Wispcar can be built using through-hole parts, and for a circuit so simple even a PCB is optional. It could be locally assembled by anyone with a soldering iron, maybe even creating a micro-business in developing world communities who need community Wifi.


Thanks to Tim Ansell (aka Mithro) for supplying me with his PIC collection and programmer.

20 thoughts on “WiSPCaR – Wifi Station Power Controller And Reporter”

  1. Hello David,
    Linear Technology Design Note 1007
    and Design Note 301
    cover wide Range ( 8 to 60 V ) switched power supply’s.
    Unfortunately they will cost considerably more than the rest of your circuit. I don’t think that you can get a complete PSU for under $5-10.

    Regarding a hanging PIC, i would suggest that you use the watchdog timer of the PIC.

    Klaus Leiss

  2. Thanks Klaus, yes I was intending to switch on the PIC’s watchdog, and possibly add some external reset circuitry to protect against brown-outs.

  3. Hello David,
    given that you probably don’t use much of the performance of the micro you could probably do a switched power supply with the micro. The problem I have is, how do you start the system up? You need something like a second low power PSU for the micro alone that you can disable afterwards. No good idea here at the moment.

    Klaus Leiss

  4. Hi Klaus,

    You know I did find just such a PIC based switch-mode power supply somewhere on the web, but can’t recall where. It used a simple Zener regulator to boot-strap, which was shut down when the switcher started.

    Given the tiny currents involved (250uA), other clever approaches might be possible, like switched capacitor techniques.

    – David

  5. Hi David,
    I have seen one with such a Zener regulator for startup.
    But if it had a means to shut down this startup circuit i have overlooked it. The current through the Zener is always there and if you try for a wide range of input voltages the current for the higher voltages is not small. Maybe a combination of a low power reset circuit and a trickle charged capacitor ( goldcap ) is a solution. Slowly charge a capacitor with a small current until the voltage is high enough to start the switcher, then release reset. If you use a goldcap you can probably put the MCU to sleep with a disabled switcher.

    Klaus Leiss

  6. There are app notes from many small MCU makers about using their PWM features to make switch mode supplied. Certainly MicroChip have them. Search their web siir.

  7. The quiescent current of the cheap 78L series of linear voltage regulators is 6 mA maximum according to the data sheet. The input voltage is limited to 30 volts at 3.3-9 volt output, but the limiting factor should be the heat that has to be dissipated at maximum current, rather than the voltage. In doubt add a zener diode in series with the regulator. Or build a discrete regulator on your own – this way you can control the quiescent current, if you don’t have to source more than a few milliamperes it can be very low.

  8. Hi Elektra. I think you are right about the limiting factor being power dissipation, 30V dropped at 10mA is 300mW which might be a lot for a TO-92 package.

    A discrete regulator is a good idea – and we have 3 op-amps spare.

    A DC-DC converter would be ideal. Wouldn’t have to be very fancy if just 10mA is required. Maybe even built out of the spare op-amps, rigged up as a PWM generator.

  9. I’m just thinking about a simple linear regulator, utilizing one of the free OP-Amps. Does it have to be temperature compensated? How much drift is allowed? I wonder whether a supply voltage drift at the PIC would spoil the accuracy of the measurements you’re doing.

    I guess it is hard to design a switched mode converter to achieve very low quiescent current. Oscillator, PWM and driving the switch will consume power as well.

    The LM324 is low power, using a 2x Op-Amp instead of a 4 x Op-Amp could also save a bit of power.

  10. Re drift and temperature compensation the A/D reference is based on the Vcc rail so we probably need reasonable accuracy.

    For example one application will be detecting when a lead acid battery is discharged, so voltage sensing to +/- 100mV accuracy across temperature, time, humidity variations would be useful.

    I don’t really know how well the current circuit performs in this regard – I need to work up a test plan based on developing world conditions.

  11. David, you mention the information can be sent over RS232 and parsed by the router then sent via email etc… however I imagine this requires support from the router firmware. I would love to see your design adapted for use over ethernet! Yes it would push cost up, but would yield a simple to use system that can be just plugged into a port on the router. This would be perfect for use here in rural Australia (where I am): there are many solar-powered wireless repeaters, and a simple plug-and-play addon not requiring risky changes of the existing router firmware would be perfect.

  12. I think so – the link says it can handle 12C5XX chips. I use a commercial programmer (ASIC Presto) but it would be nice to try a low cost programmer with this project.

  13. Have you designed a PCB layout for this circuit?

    If not, would it be helpful if a design could be made “open source” hardware.

    I’m thinking about making several of these devices.

  14. Hi Janish,

    No, not yet. It would be great to make that step. The firmware works well but I think the current detector needs a little more work – I would like to make it bi-directional so it can measure battery charge and discharge.



  15. Greetings- have just found this while on another quest! The UK sourced PICAXE micro family are made for this sort of application, with code a high level breeze. The editor is free, chip prices start ~US$3, & there are now 16 PICAXEs are in the family- all based around MicroChip offerings.

    I once used a simple 08M’s READADC feature & the old “voltage drop across a very low value resistor” trick to good effect to monitor PV Ah delivery. Others have utilised this for insights into electric bike energy storage etc, with read out onto a cheap bike computer LCD. This shows Amps as speed, while Ah is distance. See numerous PICAXE resources => http://www.picaxe.com Stan ( of “wokfi” fame TCV- Nov. 2006)

Comments are closed.