Microchip PIC® 8-bit microcontrollers are quite popular amongst hobbyists, and I’ve used them for a long time in several of my projects. They are very cheap, use only 35 assembly instructions that are easy to learn, and most importantly they use flash memory, which gives you the possibility to program the device virtually as many times as you want during your experiments. Up until now I’ve used a simple serial interface and picprog to program them under Linux, but sadly the trend is not to include a serial port anymore on new computers/laptops. Of course there are USB programmers on the market, but quite often their price exceeds 30€ and not all of them work well on Linux. Also a commercial programmer usually supports hundreds of different chips, while all I needed was a simple and cheap way to program, say, the four chips I work with most of the time. So, with the introduction of the Raspberry Pi, and the possibility to control external hardware through its GPIO connector, I thought it would be worth spending some time to design a simple interface and write a software to program some PICs. The result of about a week of work is rpp – a Raspberry Pi PIC Programmer that uses the GPIO connector.
These are the basic operations you can perform with rpp:
- Bulk erase the chip
- Read the chip and save its memories content to a Intel HEX 16-bit file
- Write a program to the chip. The location to be written are read from a Intel HEX 16-bit file
At the moment this program supports only 11 different devices (basically the ones I had here and could test) but I plan to add support for other devices in the future
rpp is free software and it is released under the GNU GPLv3 license.
PICs are programmed using a serial method. You need a VPP of 12V to 14V to enter in Programming/Verify mode, and then the communication is done serially using a CLOCK line and a DATA line (which is bidirectional). The hardware interface is purposely simple (and as a consequence, cheap) and uses only 14 resistors, 2 capacitors and 6 bjts, plus a voltage regulator to derive the 5V from the 12V supply. Since the average current required to program a PIC is low, you can use a 78L05 instead of a standard 7805. In fact I tested the programmer with the 78L05 and it didn’t even get warm during programming.
The terminals on the top of the schematic, labeled T1-T4, go to the Raspberry Pi GPIO connector. Of course you also need to connect the ground of the Raspberry Pi (pin P1-06 on the GPIO connector) to the ground of the programmer. If you want to use different GPIO pins on the Raspberry Pi, all you need to do is modify the defines at the beginning of the source file (rpp.c).
The terminals labeled T5-T7 are the signals that go to the PIC microcontroller for serial programming (CLOCK, DATA, and VPP programming voltage), and again, you need to connect 5V and ground to the PIC too.
For those of you interested, this is how it works: the stage composed by the npn and pnp transistors (Q1 and Q2) acts as a level shifter (since the GPIO connector of the Raspberry Pi works at 3.3V) and at the same time avoids drawing too much current from the GPIO pins. A high level on T1 (GPIO4) makes Q1 go into saturation (easy to see: assuming a VCEsat of 0.1V, we have Ic = 42uA, and Ib = 26uA >> (Ic/β)), effectively connecting to ground the lower terminal of R3, given that VCEsat is less than 100mV typically. This turns on Q2 and pulls T5 (CLOCK) high. When a low level is present on T1, both transistors are off, and T5 is pulled down by R4. The resistor R2 make the transistor Q2 turn off faster (otherwise, the charge stored in the base of Q2 has nowhere to go when Q1 goes from on to off, and this results in a longer storage time. This problem is not present on Q1 since the GPIO pins can sink current).
The stage composed by Q3/Q4 works pretty much in the same way. When T2 (GPIO7) is high both transistors are on, and we have VDD*((R9+R10)/(R8+R9+R10)) = 4.7V on T6 (DATA), neglecting VCEsat. When they are off, again T6 is pulled low by (R9+R10). When DATA becomes an output on the PIC, we switch Q3 and Q4 off in software (effectively disconnecting R8), and we use the voltage divider made up by R9 and R10 to transform 0/5V voltage levels in 0/3V (the divider’s voltage ratio is R10/(R9+R10)=0.6, VDD*0.6=3V) before feeding this signal to the GPIO.
Lastly, Q5/Q6 pull T7 (VPP) to 12V when on, making the PIC enter Program/Verify mode.
Despite the working of this interface being pretty simple, I have ran a simulation on it using ngspice.
Note 1: this interface does not support In-Circuit Serial Programming (ICSP) at the moment, but I plan to work on one that does.
Note 2: someone on hackaday suggested the use of a SN74LVC245A octal transceiver for simplyfing the interface. After looking at the datasheet I don’t think that could work, because when programming the PIC, CLOCK and DATA have Schmitt Trigger inputs, and they need a minimum input high level of 0.8*VDD, that is 4V. If you operate the 74LVC245 at 3.3V, the VOH of this transceiver (3.3V at best) isn’t enough to be recognized as a valid high level from the PIC.
About the 78L05 regulator: it was added because I didn’t want to draw any current from the RPi, apart from that needed to drive the bases of the switching transistors. Think of it as an additional “protection” for the Raspberry Pi: if they chip you’re programming is faulty or shorted, the worst it can happen is that the regulator will activate its thermal or short circuit protection, saving the RPi.
I agree that it’s possible to build an interface with a lower number of parts, but as it is now its cost is probably under 2€, you can use any type of equivalent npn/pnp pair (like bc547/bc557) and it’s something a beginner could solder easily as a first project.
For more detail: rpp – Raspberry Pi PIC Programmer using GPIO
Current Project / Post can also be found using:
- https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1823 h-XajW7e7dLjP85ieQ4rmWf7xBNxwBZUurmf95UBn7EyavKcrnUTPpI5QH8MTIyy 136b742623afe3bb2b872c331a28c537f2c62135&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme