An educational project using a PIC chip.
This is a future article for Elektor Magazine
To place an order, click: [Spin The Dice kit](mailto:colin@elechelp.com?Subject=Buying Spin the Dice kit&Body=Please e-mail the cost of sending Spin the Dice Kit by air mail to my country:**___**** and send details of how I can pay for it. My name is:____)**
You cannot beat toys for technology. They always offer the latest in design. They were the first to offer speech, LCD screens and movement, all at an unbelievably low price.
Technology has ridden on the back of toy manufacture. Toys have led the way to reducing the costs of manufacture and now we see things like gigabyte chips in hand-held devices for less than a day’s wage!
If you want to see technology in operation, just go to your local toy store. I did.
One toy that took my attention was a spinning top that produced a LED display. It detected the earth’s magnetic field to provide registration for the display and every time the top was spun, it produced a curved dot-matrix display “in the air.”
So the display appears at the same location on each revolution, a reference point must be generated. The circuit detects the earth’s magnetic field via an inductor to create this.
As it rotates, the voltage generated in the coil is passed to an op-amp. The voltage produced is very small and two stages are needed so the output will be high enough to trigger the input of a microcontroller.
This is only one feature of this project.
There are three features to be discussed.
Firstly the magnetic detection.
To prevent high frequencies being picked up by the coil, it has a large capacitor across it, so that only very low frequencies will be detected. The first op-amp will provide a very high amplification, but this will not be sufficient to trigger the micro.
It needs another stage with very high gain.
During quiescent conditions, the input voltage to the second op-amp will be the same and the output will be LOW.
When the output of the first op-amp rises, the voltage on the non-inverting input of the second op-amp will be slightly delayed by the action of the 1M and 10n capacitor and this will make the output go HIGH. The 10n will charge and cause the output to go LOW again. Thus a short pulse will be produced.
This project offers three areas for experimentation. It shows how the earth’s magnetic field can be detected electronically
It employs surface-mount technology and it covers writing a program for the simplest chip in the PIC series, the PIC12F629.
If you have ever wanted to start writing your own programs for a PIC microcontroller, this is the place to start.
The microcontroller is an 8-pin device with 5 input/output lines and one input only. The other two pins connect to the supply.
The chip has 1024 spaces to store a program and each space will store a single instruction. These spaces are also used to store data (also called variables) in the form of a table.
The micro acts on each instruction at the rate of one million instructions per second, when the clock frequency is 4MHz. An internal oscillator produces this frequency.
An instruction can be a simple task such as placing a number (called a literal) in the “working register” called register “W” or it can be a more-complex task such as testing a bit in a file and jumping over the next instruction if a bit in the file is set.
1024 lines of code may not seem very large but when you realise this project has 5 different games and uses only half the memory, you can see how efficient “machine code” programming is.
As an example, the first 3-level chess game was created in a 2k memory, for a “Chess Challenger” computer.
The program for this project has been written by hand using the set of approx 30 instructions for the chip.
These instructions consists of letters and numbers, with each letter taken from the first letter of a word such as Shift, Left, etc. The numbers represent the “file” or “register” where a “quantity” contained in the instruction, will be stored.
These instructions are assembled by and assembler called MPASM. The result is a list of hex numbers that are “burnt” into the chip using a programmer. All these programs and the programmer are covered on the authors website: talkingelectronics.com
A program for a PIC chip may look unusual at first, but the website explains all the terminology and takes you through each stage in the development of an idea.
Each instruction is called a mnemonic and this is a “half English, half xxxx” statement.
The secret behind an effective dice (singular die) is to produce a truly random number. This is very difficult to achieve with a micro as it has a very high “predictability.” The answer is to have a large table of values and cycle through the table. To prevent the micro starting at the top of the table each time it is turned on, a different starting-point is held in the EEPROM section of the micro. This effectively produces a very long table with no perceptible repetition.
This project offers a course in programming PIC chips. The 5 LEDs are capable of producing a dot-matrix display 5 pixels high by more than 60 pixels long. This will allow a number of letters to be produced or even animation.
When the project is first turned on, the LEDs run in sequence to show they are all operating and then the first LED illuminates to show the first program is active. By pressing the ON button repeatedly, the second, third, fourth or fifth program can be activated.
The chip comes pre-programmed with two programs and the course on the web shows how to write programs for the other areas.
au $59.50 plus $4.50 post
us $47.50 plus US$6.50 post
[Order kit](mailto:colin@elechelp.com?subject=Buying an PIR Camera kit&Body=Please e-mail the cost of sending kit by air mail to my country: **___**** and send details of how I can pay for it. My name is: ”)**
Quick Links
Legal Stuff
Social Media