Introduction: PURPIC, the Wearable PICkit2 Clone
One of my very first Instructables was a stripped down PIC programmer based on a design by David Tait using through hole transistors and resistors glued to a piece of cardboard. Oh, how times have changed. And as usual, I'm still 7* years behind those changed times. My latest project is a remake of today's hottest 7-year-old PIC programmer, the PICKit2!
Step 1: An Extremely Brief History of the PICkit2
Microchip launched the PICkit2 in 2005. It is a hugely popular device that programs and debugs a wide array of PIC microcontrollers and EEPROMs. Even though it has long been superceded by the PICKit3 and the ICD3 programmers, there are still a variety of features which make the PICKit2 quite useful (and cheap) for specific applications.
In addition to working with Microchip's MPLAB IDE as both a programmer and debugger, Microchip also created a nifty standalone software for the device which is very easy to use. There is a Widows GUI version and also a command line version of the programming software. The engineers even added a "programmer-to-go" functionality, which allows the PICKit2 to burn chips with no computer at all. So even though the PICKit2's MPLAB debugger is painfully slow, all those other features are quite useful for low volume batch programming on a budget. So even though I celebrated the PICKit2's 7th* birthday by buying an ICD3, it will never make my PICKit2's obsolete.
Step 2: An Extremely Brief History of PICKit2 Clones
Some years ago, Microchip decided to release the firmware and schematics of the PICKit2. Not long after that, the first of countless clones was born.
Many hobbyists stripped down the programmer to the bare essentials. Other commercial variants were made with robust ABS cases and a more secure RJ-12 connector. One version looks more or less exactly like the original from the outside, and it sells today for around 20 dollars!
The schematic is viewable at this link. Scroll down to page 81-82, or click on "Appendix B: Schematic"
Step 3: Enter PURPIC - Video in Action
The 4 main features of my PURPIC clone are
1. Integrated li ion battery charger. Whenever the device is plugged into a USB port, it charges the battery with a controlled charge rate of 85mA.
2. DC-boost circuit provides 5V from any lithium battery or a possibly out-of-spec USB port/hub. The boost circuit is good for over 500mA, so it can deliver the goods.
3. The Program button is ported out to the ICSP header, to allow access to Programming-to-Go via your programming interface of choice.
4. Even with the added circuity and the extra large toner transfer-friendly vias, the area of the PCB is still 25% smaller than the PICKit2, making the programmer light enough to stick on the end of a pogo pen interface or to even wear on your wrist, utilizing the Programmer-to-Go function.
I haven't done extensive testing, yet, and I've already found one shortcoming. The real PICKit2 detects a short circuit between Vdd and ground, shuts off power, and displays a Vpp error. When connected to the computer, my clone doesn't detect a short fast enough. It will brownout and lose communication with the computer. Or worse, it may even trip the USB port to shutdown, which (if you have a battery connected) leaves the device locked up in brownout, with output still (trying) to power the short.**
*Edit: I found a simple solution for short-detection is to add a 5 ohm resistor in series with the Vdd line on my pogo pen. Yea! All of the Vpp errors are now detected. A 5 ohm series resistor is obviously not an ideal solution, because it will result in significant voltage drop if your programmer is ever called upon to drive a significant load, so some careful selection and experimentation with different FETs might be warranted. I checked the specs on the P-FETs I'm using, and they have much faster rise/fall times and a significantly lower RDSon resistance than the one in the dual FET that the schematic calls for. Of course you still have some extra power draw from the DC boost, which is unavoidable. But I'd think a slower Vdd P-FET could alleviate or solve the problem. I updated the PDF images. The new revision has a space for a 0805 series resistor on the output of the Vdd P-FET. If you were to end up having short-detection issues, you could put a small resistance here. If not, you could just bridge it with a 0R resistor. I also updated the PURPIC layout to include a pad big enough for a 10uF ceramic cap (probably couldn't fit the better-at-this-frequency tantalum variety, but I'm using all ceramic, and everything looks good even without this cap, at all) on the source of this P-FET as per the original schematic. So now the PURPIC layout is quite faithful to the original schematic other than a missing decoupling cap on the opamp, an extra optional cap footprint or two on the +5V rail, the smaller Vpp pump cap substitution, and the space for the series resistor on the Vdd output. (I did not update the PICZYL pcb with the Vdd P-FET 10uF cap pad; I never changed this version's Vpp pump cap from the 47uF tantalum to the 22uF ceramic, so there's no space for this.)
**Update 3.11.15 - First off, yes. I am still using these programmers. Secondly, I was mistaken about the brownout/lockup. The BATTERIES I am using have their own short circuit detection, and that was what was kicking in. So yeah, the short circuit detection is too slow, but no, this probably won't cause a brown-out/lock-up.
Here are some links of the action:
Here I'm wearing the programmer on my wrist
But in reality, it's light enough to just stick on the end of a pogo pen.
Step 4: Schematic and Board Layout
Now I'm not going to be super smug about this clone. Anyone with some CAD PCB software could make a PICKit2 clone. The DC boost circuit is also a basic cut-n-paste, straight from the Linear Technologies LT1308 datasheet. The lithium charging is performed by Microchip's MCP73811. All I added was the extra Program button header pin, the Schottky diodes that make the charger and USB port work together. and a microcontroller to control power and perform low battery shutdown.
The 12F508 I put in there is wired to a push button switch, an LED, and a P-FET. The push button switch toggles battery output on/off via the P-FET, and the LED indicates the status. It also receives input from the LT1308's low battery detector output, and when the voltage drops to 2.9 volts a fancy-pants shut-down sequence is started. The LED blinks increasingly fast for 1 minutes until unity is reached. Then the LED slowly fades out over the next 3 seconds before everything shuts down. If the voltage goes back up to 3V in the interim, the sequence is aborted. Or you can switch it off, of course. The key thing here is that this chip protects the battery from over-discharging and becoming damaged, but it still gives you the last say. Instead of cutting out, unexpectedly, it gives you a full minute to finish what you were doing, and you can flip it off/on to reset the 1 minute timer as many times as you dare.
The PICKit2 schematic is viewable an Microchip's website. Scroll down to page 81-82, or click on "Appendix B: Schematic"
Linear technologies LT1308 boosts the li ion battery output to 5V. Datasheet is viewable here.
The lithium ion battery charging is handled by the MCP73811. This nifty SOT-23 5 pin IC requires just 2 1uF capacitors to work.
The firmware and pinout for the 12F508 will be posted shortly. But basically, put these three schematics together with a few diodes, and there's the schematic. USB +5 is in continuity with the li ion charging IC input. Then 2 diodes go from that main +5V rail. 1 diode goes from there to the the PICKit2. And another diode goes to the input of the DC boost circuit, to bring the voltage of the PICKit2 back up to 5V. A third diode goes between the battery and the DC boost input.
Sorry to disappoint, but there' no silkscreen, and I have no plans to add one. There's not enough room, and I've already spent too much time on this. A BOM in the form of a Mouser project/cart might be forthcoming, but I can't guarantee the accuracy, since I am using so many parts I already had on hand.
Step 5: PIC 12F508 Annotated Source Code; If Anyone Has a Problem Assembling As Posted, Please Comment
list p=12F508 ; list directive to define processor
#include ; processor specific variable definitions
__CONFIG _MCLRE_OFF & _CP_ON & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
;pin 1 is power
;pin 8 is ground
;pin 5 is not connected
button equ 3 ;pin 4, to the button. internal pullup is set
output equ 4 ;pin 3, to the P-FET; there's no internal pullup on this pin.
;I should have put a physical pullup on the P-FET gate,
;in case the PIC were to brownout or otherwise malfunction.
LED equ 1 ;pin 6, ;Hi = on, Lo = off
LBI equ 5 ;pin 2, Low battery indicator output of the LT1308 goes here.
;If you set the biasing resistors to 825K and 67K
;the setpoint is 2.9V. See LT1308 datasheet for the details.
;this pin also does not have an internal pullup. I did remember to put this on the pcb. :)
ORG 0x3FF ; processor reset vector
; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
;7:lo_enable wake-up;6:lo_enable weak pullups;5:lo_timer clock source is internal
;4:hi_timer clock source enabled on falling edge;3:lo_prescaler select timer (vs WDT)
call clear ;set tristate and output of I/O pins to default/OFF state
btfss GPIO,button ;check state of button
goto On ;if pressed, goto On
sleep ;if not, goto sleep
bsf GPIO,LED ;turn on LED
bcf GPIO,output ;turn on P-FET
call DD ;Debounce Delay
btfss GPIO,button ;check button state
goto $-1 ;wait till it's released before continuing to main loop
btfss GPIO,LBI ;this checks the Low Battery Indicator
goto LB_shutdown ;if pulled low, then goto Low Battery shutdown
btfsc GPIO,button ;as long as the button isn't pressed, the PIC stays in "loop."
shutdown ;if the button is pressed, everything turns off and the PIC goes to sleep.
;This device starts at the beginning of the code when it wakes up, FYI
call clear ;
return ;this device doesn't actually have a "return" command.
;This is a pseudo-command, which is actually assembled as the "retlw 0" command.
;Which just means it places literal 0 into the W accumulator when it pops.
LB_shutdown ; this is the fancy-pants shutdown sequence
goto $+1 ; just some extra delay
DLB ;Delay Low Battery Routine
btfss GPIO,button ;constantly check the status of the button
retlw .1 ;if it's pressed, then immediately pop with literal .1 in the accumulator,
;so we know that the button
;was pressed and the delay was exited early... so we can turn off
;the power instead of continuing the fancy pants blinky light shut down routine.
shutdown_kewl ; fade out the LED, instead of just turning it off
END ; directive 'end of program'
Step 6: Programming Interfaces for a 1-man PIC Factory.
Here's my collection of programming devices. All are homemade.
Step 7: No Case? No Problem. Meet the Holy Trinity of the Lazy Modder.
Mr Packing Tape. Mistress Stretch Plastic. And Lord Hotmelt Glue. If you don't got e'm, get 'em!
Step 8: Simple Tips for Working With SMD Stuff
Check the pics
Step 9: The End
Participated in the
Make It Real Challenge