On our company's Christmas celebration (December 2013) all employees got a small present: A Raspberry Pi. This was the initial event for me to investigate what (internet of) things can be done driven by this tiny computer.

This blog is to document my findings and to share what others shared with me.

Freitag, 14. Februar 2014

PIC - LVP

After reading the post-title you might ask yourself: What does PIC mean and what LVP? I can give you no answer - at least for "PIC". I can tell you what a PIC is: It is a microcontroller produced by Microchip (see https://www.microchip.com/pagehandler/en-us/products/picmicrocontrollers) and it seems that nobody knows what PIC stands for. But I have to admit that I did not search very long for an answer. Before I explain what LVP means I want to explain what a microcontroller is: It is a programmable chip (IC).
At some point in time you will see that building complex functionality by an electronic circuit is (nearly) impossible. Or from another point of view: Before I knew about microcontrollers and I saw a tiny circuit board which did complex things and was built only on top of couple of ICs I asked myself how this could work. Or "Do they build an IC for every possible problem?" - of course not. These boards are driven by microcontrollers.
A microcontroller is a tiny computer: A tiny EPROM to store the program, a little bit of RAM, sometimes an additional flash to store states and a tiny CPU (usually a RISC-unit) specialized to the skills of each type of microcontroller. I will use a PIC 12F1840 which knows 49 instructions - this is really a ReductionInstructionSetComputer!

At the moment I will not talk about how programs can be developed or by using which programming language. I will write about this in another post. I want to tell you how to transfer a given program into the microcontroller. This is usually done by a "programmer" which can be bought from $25 to $100 (and of corse: open end). When I realized that I also will have to use microcontrollers for at least one feature of my mowing robot I started to read up on what programmer I will need and which type of microcontroller I want to use. After a short while my head was full of questions: Which type should I use? Will I need more than one type? Even within the family of a specific type usually a programmer is not able to burn all chips of that family, so what programmer would be the best choice? At the end I did not know what to do or what to buy. Another aspect is that I didn't want to buy another gadget because my budget decreases rapidly. Suddendly I come up with the idea of that maybe it is possible to burn a microcontroller using the Raspberry Pi! And indeed: It is possible!

Asking Google I found a couple of projects. The complexity of the underlying circuits where quite different. The reason for this is, that usually microcontrollers are burned using "high voltage" which is about 9V-12V. Computers work at 5V so either there has to be an external power supply or there has to be a step-up module. Addtionally all signals has to be level-shifted (I will write a separate post about level shifting because we will need this, too) which also blows up the circuit.
But there where also easy circuits and then I found it: The easiest circuit!


If you take a closer look you will see that the chip is wired to the Raspberry Pi's 3.3V-pin. And here is LVP: Low Voltage Programming. There are microcontrollers which do not need high voltage for burning a program.

As it is so easy and the 12F1840 microcontroller is sufficient for my needs I went to the next electronic store, bought the chip (€ 1.41) and wired up the Raspberry Pi as shown in the drawing. I downloaded the package (https://github.com/danjperron/A2D_PIC_RPI) and tried to burn the program. Guess what: It worked!

pi@raspberrypi ~/burnLVP-master $ sudo ./burnLVPx.py A2D_PIC_RPI-master/RpiA2D.hex
File " A2D_PIC_RPI-master/RpiA2D.hex " loaded
Scan CPU
Check PIC12/16...
CpuId: 0x0
Cpu Id = 0x0
Revision = 0x5
Found PIC12F1840 from Cpu Family PIC12/16
Cpu Id: 0x1b80 revision: 5
Bulk Erase Program , Data. .... done.
Program blank check................................Passed!
Data Blank check........Passed!
Writing Program................................Done.
Program check ................................Passed!
Writing Data.Done.
Data check .Passed!
Writing Config......Done.
Config Check......Passed!
Program verification passed!


An image of my Raspberry Pi wired to PIC 12F1840 as shown in the drawing above


In an upcoming post I will tell you what can be done by using the RpiA2D program and the 12F1840. So stay tuned...

UPDATE:
You will need to install the Python-lib intelhex to run burnLVP:

wget "http://www.bialix.com/intelhex/intelhex-1.5.zip"
unzip intelhex-1.5.zip
cd intelhex-1.5.zip
sudo python setup.py install
sudo ./burnLVPx.py