picture home | pixelblog | qt_tools

omino code blog

We need code. Lots of code.

Item 1. PIC12F509 is a fun/funny little chip.

The PIC12F509 truly embodies all that is great about our current state of technological development. It’s an 8-pin package that can store a kiloword of code and has a handful of bytes of RAM. It has 5 I/O pins and one input-only pin, and power and ground. Needs no other components; has a built-in 4MHz oscillator.

Costs about $1.

I mean really, if nothing else, it’s a fine replacement for your default 555 square wave generator, right? It costs about the same, and doesn’t need any external resistor or capacitor.

I jest of course, reminiscing about saving my pocket money in the late 70’s to buy a few more 7404’s at Radio Shack on the way home from school. Today those 5 I/O pins are about blinking the LEDs.

Oh, and the PIC12F509 has some of the requisite quirks that make it a joy to use. We don’t want things to be too easy, we want arbitrary challenges to sweeten the success.

  • Of the 1k program space, the CALL instruction can only access the first and third quadrants… and the third only if you are very careful.
  • Of the 1k program space, the GOTO (jump) instruction can only access the first 512 words unless you are very careful.
  • The RAM is bank switched in the most delightful way.
  • There’s a timer, but no interrupts! Ha!
  • The call stack is two, count ’em, two levels deep.

So this all means you have to be… how to say… “clever” in your programming, especially for a realtime LED blinker. Count those cycles and loops, friends. A joy.


[stop][go][-][+]

Item 2. Powering the LEDs from a cheap solar garden light.

Making blinking toys is fun, but there’s always the question of how best to power them.

Today at Home Depot I picked up a box of 10 solar-powered rechargeable garden lights. Each one has a white LED and a single 600 mAH NiCd rechargeable battery. $39.95 for the whole box and you can’t beat that.

I’ve had some success with other lamps, hacking them to power EL wire. (EL wire draws a lot of power, and they only last the first hour of evening, alas.) We got this latest box for our burning man camp, but also I had to try something.

Inside, the tiny circuit board apparently uses some kind of voltage multiplier circuit. One side has a diode and a capacitor or two, the other has a half dozen minuscule surface mount parts. A quick test confirms that the voltage across the LED is 3v. The PIC12F509 runs fine on 2v to 5v. Splendid!

Removing the LED and attaching two wires in its place seems like just the thing…


note — 3v label incorrect, see edit below

An LED usually draws about 20mA. The NiCd battery is rated 600mAH at 1.2v, which would be 240mAH at 3v, or 12 hours at 20mA on a full charge. Perfect for planet Earth: the average length of night turns out to be 12 hours. (Estimates based on optimistic assumptions: perfect charge, 100% efficient voltage-multiplier. Of course, you probably bought your solar garden light in the summer, when the nights are short. And in the winter, who’s checking?)

A PIC12F509 itself draws less than 1mA at 4Mhz, 3v. That means that, assuming our blinker averages less than 1 LED on at a time — a pretty safe average, if the blinking pattern uses partial-brightness — then the blinker should run all night. Joy.

Further experiments to follow.



Item 3. Edit. Later that same day. Whoops. Caution.

Ah. Well. Experiments followed, with cautionary results.

1. Measurement across output terminals under no-load conditions.
Sensor in sunlight (“lamp off”): 1.3v
Sensor in darkness (“lamp on”): 20.75v !

2. Measurement across output terminals while blinker operating: Varying from 3.5v to 4.5v, or so.

3. During the course of connecting/disconnecting the blinker from the output terminals, somehow I fried the PIC12F509. Replacing it with a fresh one worked fine. (They’re $1 each… I have a handful of these fine little computers.)

Hypotheses. The voltage multiplier is some kind of free-running unregulated bugger. With no load the voltage can climb pretty high. The device is designed for a particular load (a 3v 20mA white LED). In normal operation the device starts pumping its capacitor while there’s a load. I probably attached the blinker while the storage capacitor was peaked at 20v, letting it run through the load suddenly, and that fried the PIC chip.

Speculation. To avoid sending spikes through the replacement load, don’t connect it while the output terminals are live. Do it in the sunlight, or remove the battery first. And touch the leads together to discharge it. It may be prudent to program the blinker patterns such that there’s some LED load at all times. It may be prudent to seek more expert advice about voltage regulation and maintaining a load in some electricity-savvy manner. I’m just a software guy.

More to come.

4 comments
Yong // Mon 2007.06.18 09:099:09 am

David, you are a true geek. Thanks for sharing.

Kero Kero Keroppi // Mon 2007.06.18 17:495:49 pm

Good and honorable stuff. Inspired by your effort, I’ve started writing up my own current project. Have look!

http://www.antfarm.org/blog/aaronf/

David Van Brink // Mon 2007.06.18 21:049:04 pm

Yay Aaron!
(And looks v. groovy so far.)

Kerry Veenstra // Mon 2007.06.18 22:3910:39 pm

Yes, I’ve seen that unregulated-supply thing, too. I have an old weather satellite receiver (which is sort of unnecessary now with the WWW). It wants 12 VDC. If you buy a Radio Shack 12V power supply, it will drive the receiver with about 16 V! If you buy a Radio Shack *Regulated* 12 VDC power supply, you’ll pay twice as much, and the receiver will be driven with 12 V, and one of channels will be not be fried.

oh, i dont know. what do you think?



(c) 2003-2011 omino.com / contact poly@omino.com