Fibonacci Sequence Counter |
For information on the Fibonacci Sequence look here: http://en.wikipedia.org/wiki/Fibonacci_number If you have any questions or comments about this project or PIC's and electronics in general, please email me at cybrown@cp-tel.net More projects can be found at http://www.pasqualy.com |
Operation |
The unit has 16 LED's to display the Fibonacci numbers in binary. In the image above the MSB is on the right, and the LSB is on the left. There are two buttons on the device: As a side note, this project makes a pretty decent random bit pattern after the first 20 or so iterations if you set it to run over a delay instead of button presses. Once it is past the small numbers that can be represented with 16 bits you can get a nice light show by letting the program run past the overflow point. You can get an idea of how random the distribution is by setting the operation to run at a high rate and observing if all the LED's appear to have the same brightness. If one is dim, it means its not getting the same on time as the others over time. |
Code |
The entire project was written in assembly and compiled using MPLAB from microchip. I did test the circuit beforehand by using a simple test program written in PICBasic so that I could concentrate on debugging my code instead of debugging the code and hardware at the same time. The program consists 4 major parts:
The output works by setting the serial data out pin to the MSB of the desired byte to be output, setting the clock line high, then shifting the output byte to the left and setting the clock line low. This is repeated 7 more times to shift out an entire byte. The shifting is done between the clockout's high and low so that these instructions act as a sort of delay to make sure the shift registers have time to handle the input. As noted above your application might need more of a delay depending on what devices you are using etc.
fibmakerfinal.asm - Assembly code |
Circuit and Design |
The circuit uses a PIC12F683 which has 6 I/0 lines. The registers were TPIC6B595 8 bit shift registers that I picked up from sparkfun. I simply cascaded them so that they would share the same Serial Data, Data Clock, and Latch Clock lines. |
Images and Video |