Monday, March 9, 2009

PIC 16F628A based POV toy

I can't remember where I got turned on to the idea in the first place, I likely was linked to Ladyada's bike POV from Hackaday or something. I figured it would be a nice introduction to working with the microcontrollers, maybe lead into more interesting and hopefully more difficult projects (it hasn't yet). Have a better idea of something fun to make with a microcontroller? Let me know :-).
Using the educational version of the Microchip C compiler (C18). While it would have been easy to do such a small project in Assembly, I don't have much interest in machine level code and prefer the readability of C.
I have never been much of a hardware guy. I can do Ohm's law, parallel and series circuits and at one point could do capacitance charge and discharge calculations, but that has left me. So I try to stick with the basics. Run the power to the PIC, use it to turn on and off the LEDs. Just need a small battery pack, a resistor and a handful of LEDs.
So here it is set up in my breadboard, seems to be working OK.




And in this picture I have it set up in its final form, blinking away. That little jumpered header is the on off switch for it. Crude but functional.
And here it is attempting to work. I made the mistake of using cheap LEDs that I had laying around to make this. I think they have a 10 degree viewing angle or something crappy like that. Wide viewing angle LEDs would have made it look better, though my timing still wasn't perfect with it.

You can make out most of my name. I have it attached to a bike wheel and am spinning at different rates. I was considering making a longer strip of LEDs and attaching it to my car wheel or something, but that would have required a Hall effect sensor to test timing and I just didn't feel that ambitious at the time.

The code is pretty simple:

#include // for TRISB and PORTB declarations
#include // for 'Delay10KTCYx'


// Set configuration bits for chip
// - set HS oscillator
// - disable watchdog timer
// - disable low voltage programming
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF

#define TEXT_SIZE 40
const rom unsigned char text[TEXT_SIZE] =
{ 255, 137, 129, 0, 255,
128, 128, 0, 129, 255,
129, 0, 241, 137, 135,
0, 252, 18, 252, 0,
255, 137, 118, 0, 255,
137, 129, 0, 1, 255,
1, 0, 255, 16, 255,
0, 0, 0, 0, 0 };

int val, binaryOut;
void main (void)
{
// length of bits in order to make string
// put numerical version of hex value into constant "text"
// will need to put this into EEPROM and allow to be updatable

TRISB = 0; // configure PORTB for output
for (val = 0; val < binaryout =" text" portb =" binaryOut;" portb =" 0;">
}