Open Programmer, An Open Source USB Programmer For PIC, ATMEL AVR, I2C-SPI-MicroWire-OneWire-UNIO EEPROM
Open Programmer, An Open Source USB Programmer For PIC, ATMEL AVR, I2C-SPI-MicroWire-OneWire-UNIO EEPROM
Italian version
In the last few years, as serial and parallel interfaces have almost disappeared, electronics
enthusiasts find even more difficult to program microcontrollers; old time programmers don't work
any more; common solutions include using USB to serial adapters (which can't accept direct access
but only slow API calls), or add-on interface chips, like FTDIxxxx, which appear substantially as
serial interfaces and require custom or proprietary drivers.
So why not use PIC controllers and their native USB interface?
After searching a while I couldn't find an USB programmer which was at the same time functional,
free, and open source, so I decided to design one.
Open source means that all sources and schematics are given free of charge with the rights to
modify and release them.
Top
Quick facts
Another USB & HID firmware (v0.10.0)
programmer?
USB & HID In order to use the USB interface included in some PIC devices we need a firmware that
firmware implements one of the classes defined by the USB consortium or a new one; I opted for the HID
Control programs class, which is supported natively by all operating systems and so doesn't need any driver.
GTK graphical Maximum allowed speed is 64KB/s, although with my application I measured something in the
interface range 20-40 KB/s, certainly enough to program devices with memory of 100KB at most.
MFC GraphicalLike all USB devices this one too has a vid and a pid; these are usually obtained under payment; I
interface got a combination for free from pid.codes: 0x1209&0x5432; anyways it's possible to configure
Command-line both, so I leave the choice to the user.
interface The programmer appears to the system as a HID device that exchanges 64 bytes packets every 1
How to ... ms.
Supported devicesThe USB firmware comes from a nearly unknown open source project, written by Alexander
Communication Enzmann, which I modified and adapted to the MCC18 compiler.
protocol I wrote a brief guide on how to use it; to my knowledge this is the only open source firmware with
The circuit HID support and GPL license.
Voltage regulator My programmer code simply adds a command interpreter that drives the microcontroller's outputs
How to contribute according to a set of instructions.
Download The main control cycle waits for a packet from USB, then executes commands in sequence while
History managing communication tasks; at the same time a control function is called periodically by a timer
Links interrupt and keeps the DCDC regulator output voltage constant.
Contacts Building the project requires only free programs: MPLAB and MCC18 student version, which are
unfortunately only available for the windows (in)operating system.
It's certainly possible to compile with SDCC, but some changes are needed to the source code.
Everything is given under the GPL2 license.
Here is the complete MPLAB project, here the hex file only.
Here a version (0.8.0) for 18F2450 (with reduced functionality, see the circuit).
Control programs
I initially thought of modifying an existing software, for example winpic or picprog, but I found it
would be too difficult because I use packetized communications instead of serial; so I had to write
one (two) from scratch.
Unfortunately, or fortunately, since I'm not a professional programmer I kept features at minimum;
the result are very small but fast programs that don't use your CPU for nothing.
For most devices the code is verified while programming; for the others immediately following the
writing phase.
Ideally you should have the same version number for both software and firmware, except for the
last number which indicates minor changes and bug fixes; however I tried to keep the same
protocol with each release, so that apart from new features it is often possible to use new software
with older firmware and vice versa.
In case you wonder, the reason why it's not possible to program directly from MPLAB is not
technical: Microchip does not release specifications of how to interface with its program; if you
want them you have to be a commercial manufacturer and sign a non disclosure agreement, which
is clearly impossible for a GPL2 open source project.
On the contrary, integration with Piklab is possible and I hope will be done soon; right now the
custom programmer interface lacks some essential parameters, but whoever has the ability and time
can fix it for sure.
Top OPGUI uses the GTK libraries so under Windows it's necessary to install the GTK Runtime
Quick facts Environment.
Another A screenshot of Opgui:
programmer?
USB & HID
firmware
Control programs
GTK graphical
interface
MFC Graphical
interface
Command-line
interface
How to ...
Supported devices
Communication
protocol
The circuit
Voltage regulator
How to contribute
Download
History
Links
Contacts
A quick guide: buttons to read, write, load and save files are on the toolbar.
The "Data" tab shows what the programmer is doing.
On the "Device" tab it's possible to choose the device and modify some programming options, such
as writing ID and calibration words, using the eeprom etc.; only settings compatible with the current
device are considered.
Under "Options" are various general settings: USB connection, errors, log file, expansion boards;
using the "Hardware Test" function and a voltmeter is possible to check that the circuit is working.
The "I2C/SPI" tab is useful for communicating with generic I2C and SPI devices; in case of I2C it's
always necessary to specify the control byte (and address, if not zero); RW bit is handled
automatically.
For example, to write manually 3 bytes on a 24xx16 at address 64 write: A0 40 1 2 3
From version 0.7.10 it is included an ICD debugger, working more or less like pdb; in addition it
supports coff files.
The "I/O" tab allows to control individual I/O lines and the power supplies.
Under "Utility" there are functions to convert a single hex line to data and vice versa.
There is no installer since there aren't any libraries and the executable is very small.
The program accepts hex8 and hex32 files, and also binary files in case of serial memories.
Supported languages are currently English and Italian; to add other languages it's necessary to
generate the languages.rc file (-langfile option) and to modify it; the language id is before the
respective strings, enclosed in square brackets [].
The language is chosen at startup by matching the system language (it can also be forced with -
lang).
To enable access to the programmer under Linux see chapter Command line interface.
You can find more info on the OpenProg and Opgui user's guide or in the source code guide.
To compile the program from source (optional) you need to install the GTK libraries, GCC and the
maketools (MinGW/MSYS in Windows); then write:
> make
To install it under Linux(if you wish):
> make install
Download the compiled program ... or the sources.
Top
Quick facts Graphical interface for Windows (v0.9.1)
Another
programmer? OpenProg is a C++ application written with Visual C++ 6 and MFC.
USB & HID A screenshot of OpenProg:
firmware
Control programs
GTK graphical
interface
MFC Graphical
interface
Command-line
interface
How to ...
Supported devices
Communication
protocol
The circuit
Voltage regulator
How to contribute
Download
History
Links
Contacts Only the basic programming functions are implemented; it was the fist GUI of the project, but
currently development continues on OPGUI, so it may be dismissed in the future.
It has the advantage of working without any additional library.
Usage is the same as OPGUI; works with XP, VISTA, 7, 8.
Command-line options are:
-d <device> , selects a target
-r <file name> , reads the target and writes to file
-w <file name> , writes a file to the target
-gui , do not exit after writing or reading (only if -w or -r are specified)
You can find more info on the OpenProg and Opgui user's guide or in the source code guide.
It may be of interest the fact that the DDK (driver development kit) is not required for compilation;
I link explicitly to the system library hid.dll and manually load the functions needed.
Download application ... or sources (Visual Studio 6 workspace)
Download
How to ...
Erase a device: every device is erased before being programmed; however if you still need to
erase it it's sufficient to write a hex file with valid data (i.e. <0xFF) beyond the implemented
memory.
For example, for PIC12-16:
:020000040000FA
:0144010000BA
:00000001FF
And for PIC18:
:020000040002F8
:020000000000FE
:00000001FF
Change Configuration Word: Config words are usually specified in the hex file, but can be forced
for PIC 10-12-16-18 using the related device options (or via command line).
It's also possible to recompile sources, otherwise to change the hex file directly; in case of most
PIC16 the config word is at address 0x2007, which is stored at 0x400E; the last byte of the line is
a checksum, which can be calculated as the two's complement of the sum of all bytes in the line.
For example:
:02400E00xxxxCC , where xxxx is the new value and CC the checksum
Change configuration of Atmel AVR: unlike PICs, these devices do not map their configuration
Top words in the main memory area (so the hex files don't specify any configuration) and it's necessary
Quick facts to write the desired Fuse/Lock bytes in the device options; don't write anything in case the default
Another value is fine for the application.
programmer?
USB & HID Solve the "Synchronization error" with AVR devices: A possible cause is that the SPI speed
firmware is too high in relation to the CPU speed; the latter has to be > 4 x SPI speed.
Control programs There are many possible CPU speed configurations, so the (new) algorithm varies the SPI speed
GTK graphical automatically in order to enter Program Mode.
interface Obviously the lower the speed the longer it takes to read/write the device; in order to speed up
MFC Graphicaloperations you could write an empty file with a fast CPU configuration, then write the final file and
interface configuration at high speed.
Command-line Some devices include an extremely low speed setting (16 kHz), which is too low even for the
interface adaptive algorithm; in this case use "write Fuse Low @ 3 kHz" to change Fuse Low to a higher
How to ... speed setting, then write in the usual way.
Supported devicesAnother cause could be that the serial programming is disabled: this can be done only using a
Communication parallel programmer, and the same is necessary to enable it again.
protocol The third possibility is that the device is configured for external resonator but X2 cannot move; in
The circuit case you use the AVR expansion board make sure X2 is not tied to GND.
Voltage regulator
How to contribute Check that a device is blank: read it and look at displayed data; only lines with valid data are
Download displayed, so if there are none the device is blank.
History
Links Verify that a write was successful: all write algorithms implement write verification, either during
Contacts write or immediately after; if the program reports 0 errors it means that the code was succesfully
verified.
If you want to check again you can read the device and compare with the original data; keep in
mind that frequently not all bits are implemented; for example in PIC16 a data word is 14 bits long,
so even if the source data is 0xFFFF it will be written as 0x3FFF; also the Config Words usually
have some bits fixed at 0, which are not checked.
Read the reserved memory area: most PIC devices have a reserved area above the Config
Words which is used for test or calibration purposes; to see it use the relative option before read;
on PIC24-30-33 the executive memory is read as well.
Correctly use OscCal and other calibration words: some devices (eg. 12F5xx) store the
internal oscillator calibration value in the last address of program memory and in a backup location
past the ID words; after erasing all memory the control programs restore the calibration value
taking it from the backup location, unless specified otherwise; other options are: use the old value
(which should be the same as the backup, if none was changed before), use what is specified in the
.hex file.
Similarly it's possible to overwrite the backup value with the content of the .hex file, using option
"write ID and BKosccal"; in this case the ID locations will be written as well, if specified in the .hex
file.
To overwrite the other calibration values use option "write Calib1 and 2".
Supported devices
I tried this programmer with a small number of devices (those I own plus some tested by other
users) indicated in bold; the other devices are supported but not tested; however, considering that
for every device family at least one has been verified, all of them should work without problems.
Please let me know if you verify operation with the untested devices.
Also contact me if you need other algorithms or code new ones by yourself.
Take notice:
LF series PICs are used exactly as the F ones;
Top Atmel AVR devices with varius suffixes are grouped together whenever the programming algorithm
Quick facts is exactly the same, eg. ATmega8 and ATmega8A;
Another EEPROM memories comprise all versions with VDDmax=5V, eg. 242LC56, 24AA256, etc.;
programmer? 93x memories use 2 different algorithms, for the 93S series and for all the others, indicated with
USB & HID 93x (93xA have 8 bit organization);
firmware SPI Flash memories need a low voltage adapter (see the schematic diagrams).
Control programs
GTK graphical Devices supported for read and write:
interface 10F200, 10F202, 10F204, 10F206, 10F220, 10F222, 10F320, 10F322,
MFC Graphical12C508, 12C508A,12C509, 12C509A, 12F508, 12F509, 12F510, 12F519,
interface 12F609, 12F615, 12F617, 12F629, 12F635, 12F675, 12F683,
Command-line 12F752, 12F529T39, 12F529T48,
interface 12F1501, 12F1571, 12F1572, 12F1612, 12F1822, 12F1840,
How to ... 16F505, 16F506, 16F526, 16F527, 16F54, 16F57, 16F570, 16F59,
Supported devices16F610, 16F616, 16F627, 16F627A, 16F628, 16F628A, 16F630, 16F631, 16F636, 16F639,
Communication 16F648A, 16F676, 16F677, 16F684, 16F685, 16F687, 16F688, 16F689, 16F690,
protocol 16F707, 16F716, 16F72, 16F720, 16F721, 16F722, 16F722A, 16F723, 16F723A, 16F724,
The circuit 16F726, 16F727, 16F73, 16F737, 16F74, 16F747, 16F753, 16F76, 16F767, 16F77, 16F777,
Voltage regulator 16F785,
How to contribute 16F818, 16F819, 16C83, 16F83, 16F83A, 16C84, 16F84, 16F84A, 16F87, 16F870, 16F871,
Download 16F872, 16F873, 16F873A, 16F874, 16F874A, 16F876, 16F876A, 16F877, 16F877A,
History 16F88, 16F882, 16F883, 16F884, 16F886, 16F887,
Links 16F913, 16F914, 16F916, 16F917, 16F946,
Contacts 16F1454, 16F1455, 16F1459, 16F1503, 16F1507, 16F1508, 16F1509, 16F1512, 16F1513,
16F1516, 16F1517, 16F1518, 16F1519, 16F1526, 16F1527, 16LF1554, 16LF1559,
16F1574, 16F1575, 16F1578, 16F1579, 16F1613, 16F1614, 16F1615, 16F1618, 16F1619,
16F1703, 16F1704, 16F1705, 16F1707, 16F1708, 16F1709, 16F1713, 16F1716, 16F1717,
16F1718, 16F1719, 16F1782, 16F1783, 16F1784, 16F1786, 16F1787, 16F1788, 16F1789,
16F1823, 16F1824, 16F1825, 16F1826, 16F1827, 16F1828, 16F1829, 16F1847, 16LF1902,
16LF1903, 16LF1904, 16LF1906, 16LF1907, 16F1933, 16F1934, 16F1936, 16F1937,
16F1938, 16F1939, 16F1946, 16F1947,
16F18313, 16F18323, 16F18324, 16F18325, 16F18326, 16F18344, 16F18345, 16F18346,
18F242, 18F248, 18F252, 18F258, 18F442, 18F448, 18F452, 18F458, 18F1220, 18F1230,
18F1320, 18F1330, 18F13K22, 18F13K50, 18F14K22, 18F14K50, 18F2220, 18F2221,
18F2320, 18F23K20, 18F23K22, 18F2321, 18F2331, 18F2410, 18F24J10, 18F24J11,
18F2420, 18F24K20, 18F24K22, 18F2423, 18F2431, 18F2439, 18F2450, 18F24J50,
18F24K50, 18F2455, 18F2458, 18F2480, 18F2510, 18F25J10, 18F25J11, 18F2515,
18F2520, 18F25K20, 18F25K22, 18F2523, 18F2525, 18F2539, 18F2550, 18F25J50,
18F25K50, 18F2553, 18F2580, 18F25K80, 18F2585, 18F2610, 18F26J11, 18F26J13,
18F2620, 18F26K20, 18F26K22, 18F26J50, 18F26K50, 18F26J53, 18F2680, 18F26K80,
18F2682, 18F2685, 18F27J13, 18F27J53, 18F4220, 18F4221, 18F4320, 18F43K20,
18F43K22, 18F4321, 18F4331, 18F4410, 18F44J10, 18F44J11, 18F4420, 18F44K20,
18F44K22, 18F4423, 18F4431, 18F4439, 18F4450, 18F44J50, 18F4455, 18F4458,
18F4480, 18F4510, 18F45J10, 18F45J11, 18F4515, 18F4520, 18F45K20, 18F45K22,
18F4523, 18F4525, 18F4539, 18F4550, 18F45J50, 18F45K50, 18F4553, 18F4580,
18F45K80, 18F4585, 18F4610, 18F46J11, 18F46J13, 18F4620, 18F46K20, 18F46K22,
18F46J50, 18F46K50, 18F46J53, 18F4680, 18F46K80, 18F4682, 18F4685, 18F47J13,
18F47J53, 18F63J11, 18F63J90, 18F64J11, 18F64J90, 18F65J10, 18F65J11, 18F65J15,
18F65J50, 18F65J90, 18F65K80, 18F66J10, 18F66J11, 18F66J15, 18F66J16, 18F66J50,
18F66J55, 18F66J60, 18F66J65, 18F66J90, 18F66J93, 18F67J10, 18F67J11, 18F67J50,
18F67J60, 18F66K80, 18F67J90, 18F67J93, 18F83J11, 18F83J90, 18F84J11, 18F84J90,
18F85J10, 18F85J11, 18F85J15, 18F85J50, 18F85J90, 18F8520, 18F86J10, 18F86J11,
18F86J15, 18F86J16, 18F86J50, 18F86J55, 18F86J60, 18F86J65, 18F86J72, 18F86J90,
18F86J93, 18F8722, 18F87J10, 18F87J11, 18F87J50, 18F87J60, 18F87J72, 18F87J90,
18F87J93, 18F96J60, 18F96J65, 18F97J60,
Top 24F04KA200, 24F04KA201, 24F08KA101, 24F08KA102, 24F16KA101, 24F16KA102,
Quick facts 24FJ16GA002, 24FJ16GA004, 24FJ32GA002, 24FJ32GA004, 24FJ32GA102,
Another 24FJ32GA104, 24FJ32GB002, 24FJ32GB004, 24FJ48GA002, 24FJ48GA004,
programmer? 24FJ64GA002, 24FJ64GA004, 24FJ64GA006, 24FJ64GA008, 24FJ64GA010,
USB & HID 24FJ64GA102, 24FJ64GA104, 24FJ64GA306, 24FJ64GA308, 24FJ64GA310,
firmware 24FJ64GB002, 24FJ64GB004, 24FJ64GB106, 24FJ64GB108, 24FJ64GB110,
Control programs 24FJ64GC006, 24FJ64GC008, 24FJ64GC010, 24FJ96GA006, 24FJ96GA008,
GTK graphical 24FJ96GA010, 24FJ128GA006, 24FJ128GA008, 24FJ128GA010, 24FJ128GA106,
interface 24FJ128GA108, 24FJ128GA110, 24FJ128GA306, 24FJ128GA308, 24FJ128GA310,
MFC Graphical24FJ128GB106, 24FJ128GB108, 24FJ128GB110, 24FJ128GB206, 24FJ128GB210,
interface 24FJ128GC006, 24FJ128GC008, 24FJ128GC010, 24FJ128DA106, 24FJ128DA110,
Command-line 24FJ128DA206, 24FJ128DA210, 24FJ192GA106, 24FJ192GA108, 24FJ192GA110,
interface 24FJ192GB106, 24FJ192GB108, 24FJ192GB110, 24FJ256GA106, 24FJ256GA108,
How to ... 24FJ256GA110, 24FJ256GB106, 24FJ256GB108, 24FJ256GB110, 24FJ256GB206,
Supported devices24FJ256GB210, 24FJ256DA106, 24FJ256DA110, 24FJ256DA206, 24FJ256DA210,
Communication 24EP32GP202, 24EP32GP203, 24EP32GP204, 24EP32MC202, 24EP32MC203,
protocol 24EP32MC204, 24EP64GP202, 24EP64GP203, 24EP64GP204, 24EP64GP206,
The circuit 24EP64MC202, 24EP64MC203, 24EP64MC204, 24EP64MC206, 24EP128GP202,
Voltage regulator 24EP128GP204, 24EP128GP206, 24EP128MC202, 24EP128MC204, 24EP128MC206,
How to contribute 24EP256GP202, 24EP256GP204, 24EP256GP206, 24EP256MC202, 24EP256MC204,
Download 24EP256MC206, 24EP512GP202, 24EP512GP204, 24EP512GP206, 24EP512MC202,
History 24EP512MC204, 24EP512MC206,
Links 24HJ12GP201, 24HJ12GP202, 24HJ16GP304, 24HJ32GP202, 24HJ32GP204,
Contacts 24HJ32GP302, 24HJ32GP304, 24HJ64GP202, 24HJ64GP204, 24HJ64GP206,
24HJ64GP210, 24HJ64GP502, 24HJ64GP504, 24HJ64GP506, 24HJ64GP510,
24HJ128GP202, 24HJ128GP204, 24HJ128GP206, 24HJ128GP210, 24HJ128GP306,
24HJ128GP310, 24HJ128GP502, 24HJ128GP504, 24HJ128GP506, 24HJ128GP510,
24HJ256GP206, 24HJ256GP210, 24HJ256GP610,
30F1010, 30F2010, 30F2011, 30F2012, 30F2020, 30F2023, 30F3010, 30F3011, 30F3012,
30F3013, 30F3014, 30F4011, 30F4012, 30F4013, 30F5011, 30F5013, 30F5015, 30F5016,
30F6010, 30F6011, 30F6012, 30F6013, 30F6014, 30F6015,
33FJ06GS101, 33FJ06GS102, 33FJ06GS202, 33FJ12GP201, 33FJ12GP202,
33FJ12MC201, 33FJ12MC202, 33FJ16GP304, 33FJ16GS402, 33FJ16GS404,
33FJ16GS502, 33FJ16GS504, 33FJ16MC304, 33FJ32GP202, 33FJ32GP204, 33FJ32GP302,
33FJ32GP304, 33FJ32GS406, 33FJ32GS606, 33FJ32GS608, 33FJ32GS610, 33FJ32MC202,
33FJ32MC204, 33FJ32MC302, 33FJ32MC304, 33FJ64GP202, 33FJ64GP204,
33FJ64GP206, 33FJ64GP306, 33FJ64GP310, 33FJ64GP706, 33FJ64GP708, 33FJ64GP710,
33FJ64GP802, 33FJ64GP804, 33FJ64GS406, 33FJ64GS606, 33FJ64GS608, 33FJ64GS610,
33FJ64MC202, 33FJ64MC204, 33FJ64MC506, 33FJ64MC508, 33FJ64MC510,
33FJ64MC706, 33FJ64MC710, 33FJ64MC802, 33FJ64MC804, 33FJ128GP202,
33FJ128GP204, 33FJ128GP206, 33FJ128GP306, 33FJ128GP310, 33FJ128GP706,
33FJ128GP708, 33FJ128GP710, 33FJ128GP802, 33FJ128GP804, 33FJ128MC202,
33FJ128MC204, 33FJ128MC506, 33FJ128MC510, 33FJ128MC706, 33FJ128MC708,
33FJ128MC710, 33FJ128MC802, 33FJ128MC804, 33FJ256GP506, 33FJ256GP510,
33FJ256GP710, 33FJ256MC510, 33FJ256MC710,
33EP32GP502, 33EP32GP503, 33EP32GP504, 33EP32MC202, 33EP32MC203,
33EP32MC204, 33EP32MC502, 33EP32MC503, 33EP32MC504, 33EP64GP502,
33EP64GP503, 33EP64GP504, 33EP64GP506, 33EP64MC202, 33EP64MC203,
33EP64MC204, 33EP64MC206, 33EP64MC502, 33EP64MC503, 33EP64MC504,
33EP64MC506, 33EP128GP502, 33EP128GP504, 33EP128GP506, 33EP128MC202,
33EP128MC204, 33EP128MC206, 33EP128MC502, 33EP128MC504, 33EP128MC506,
33EP256GP502, 33EP256GP504, 33EP256GP506, 33EP256MC202, 33EP256MC204,
33EP256MC206, 33EP256MC502, 33EP256MC504, 33EP256MC506, 33EP512GP502,
33EP512GP504, 33EP512GP506, 33EP512MC202, 33EP512MC204, 33EP512MC206,
33EP512MC502, 33EP512MC504, 33EP512MC506,
Top AT90S1200, AT90S2313, AT90S8515, AT90S8535, ATmega48, ATmega8, ATmega88,
Quick facts ATmega8515, ATmega8535, ATmega16, ATmega164, ATmega168, ATmega32, ATmega324,
Another ATmega328, ATmega64, ATmega644, ATmega1284,
programmer? ATtiny11, ATtiny12, ATtiny13, ATtiny2313, ATtiny24, ATtiny25, ATtiny26, ATtiny261,
USB & HID ATtiny4313, ATtiny44, ATtiny45, ATtiny461, ATtiny48, ATtiny84, ATtiny85, ATtiny88,
firmware ATtiny861,
Control programs 2400, 2401, 2402, 2404, 2408, 2416, 2432, 2464, 24128, 24256, 24512, 241024, 241025,
GTK graphical 25010, 25020, 25040, 25080, 25160, 25320, 25640, 25128, 25256, 25512, 251024,
interface 95010, 95020, 95040, 95080, 95160, 95320, 95640, 95128, 95256, 95512, 95M01, 95M02,
MFC Graphical251005, 252005, 254005, 258005, 251605, 25X05, 25X10, 25X20, 25X40, 25X80, 25X16,
interface 25X32, 25X64, 25X128, 25Q40,
Command-line 93S46, 93x46, 93x46A, 93S56, 93x56, 93x56A, 93S66, 93x66, 93x66A, 93x76, 93x76A,
interface 93x86, 93x86A,
How to ... DS2430, DS2431, DS2433, DS28EC20, DS1820,
Supported devices11010, 11020, 11040, 11080, 11160
Communication
protocol devices supported for read only:
The circuit 12C671, 12C672, 12CE673, 12CE674
Voltage regulator
How to contribute Important!! Don't use 3.3V devices without the 3.3V expansion boards, otherwise permanent
Download damage may occur; the software verifies that such adapters are present before starting to program,
History but obviously you need to select the proper device; the 3.3V devices are:
Links 12F1xxx,16F1xxx,18FxxJxx,18FxxKxx,24Fxxx,24Hxxx,33Fxxx.
Contacts Some of them have 5V variants; if you need to program at 5V you can select the option "Don't
require LV boards". Also don't put any 24F-33F on the 30F socket, which works at 5V.
Communication protocol
To design a communication protocol we must take into account some often contrasting
requirements:
transfer speed and efficiency, code size, adaptability and expandability.
Differently from serial links, USB is packet based; a packet is received altogether, but HID devices
can only exchange them every ms, so it is out of question to manage timings directly as with serial
ports.
It's necessary to introduce synthetic commands that the microcontroller can use to recreate the
proper waveforms.
Furthermore, one objective of a reliable programmer is to be independent from the host speed and
CPU occupation, so the task of generating waveforms would anyways be given to the
microcontroller.
In general we can find two types of programmers: simple serial programmers only take commands
to change voltage levels; host software manages both timings and programming algorithms but
needs all the CPU time and is dramatically affected by other processes running on the system.
At the other extreme are "smart" programmers, which autonomously manage timings and
algorithms, but must be updated to support new devices and tend to require much memory to store
code.
I chose a combination of both: ICSP (In Circuit Serial Programming) commands are implemented
in firmware, but the host software manages the algorithms.
In order to increase speed and efficiency some instructions correspond to sequences of frequently
repeated commands, such as sequential reads.
The advantage of this approach is that timings are very precise, while the extreme variety of
algorithms does not increase the firmware code size.
Another advantage is that once the basic commands are verified the development of algorithms is
done on the PC, without the need for frequent firmware updates.
For example, this is the sequence used to enter program mode for 16F628 and read DevID:
Top
SET_PARAMETER //set delays to be used by other instructions
Quick facts SET_T1T2 //T1 & T2
Another 1 //T1=1us
programmer? 100 //T2=100us
USB & HID EN_VPP_VCC //Vpp & Vcc = 0
0x0
firmware SET_CK_D //Clock and Data as output and 0
Control programs 0x0
GTK graphical EN_VPP_VCC //Vpp enabled
interface 0x4
NOP //small delay
MFC Graphical EN_VPP_VCC //Vdd+Vpp enabled
interface 0x5
Command-line NOP //small delay
interface LOAD_CONF //program counter to 0x2000
0xFF //fake config
How to ... 0xFF //fake config
Supported devices INC_ADDR_N //increment address by 6
Communication 0x06
protocol READ_DATA_PROG //read DevID
...
The circuit
Voltage regulator
In addition to ICSP commands other instructions manage the programmer, control programming
How to contribute
voltages, execute precise delays, communicate via I2C or SPI bus.
Download
Every instruction is executed in at least 40 us, due to the interpreter loop execution time.
History
ICSP commands use T1 or T2 as values for delays; all instructions return an echo, with the
Links
exception of FLUSH, which immediately sends the output buffer and stops the execution of current
Contacts
packet.
In case an instruction doesn't have enough parameters it returns an error (0xFE) and the execution
of current packet is halted.
The state of USB connection is signaled by LED2: it blinks at 4 Hz during enumeration, at 1 Hz in
normal operation.
LED1 shows when there are instructions being executed.
Following is the list of all instructions:
The project is based on a 28 pin 18F2550; about 8.5 KWords are used, so it will fit confortably
into the smaller 2455.
The 2458 and 2553 have a 12 bit ADC, so only recompilation is required.
Up to version 0.8.0 I adapted the code to the 2450; since this model lacks the MSSP module I
used a software implementation of I2C and SPI; it also lacks the second PWM channel, therefore
it can't generate the clock for Atmel chips (for those that are configured with external clock); in this
case RB3 can be used to turn on an external oscillator (which would be inserted in a modified
Atmel expansion board).
The use of the corresponding 40 pin devices (4450, 4455, 4458, 4550, 4553) requires
modification of the PCB.
In order to implement an USB pheripheral with a PIC micro we need very few components: the
main microcontroller, a quartz, some capacitors, and a USB type B receptacle, exactly as written in
application notes from Microchip.
To be able to program PIC devices we need two digital lines for clock and data and two supply
voltages, VCC and VPP, which are controlled using three transistors; VPP comes from a switching
voltage regulator formed by Q4, L1, D3 which is described later.
Top
Quick facts Schematic diagram of main module:
Another
programmer?
USB & HID
firmware
Control programs
GTK graphical
interface
MFC Graphical
interface
Command-line
interface
How to ...
Supported devices
Communication
protocol
The circuit
Voltage regulator
How to contribute PCB of main module:
Download
History
Links
Contacts
Many components are optional, are only needed to program some types of devices or for future
applications: expansion connectors CONN2-3, protection resistors R11:23 (considering their cost
why not use them?), I2C pull-up resistors R26-27, S1 switch, ICSP-IN CONN4 (right now it's
used to program the main microcontroller without extracting it).
The pcb was optimized to fit the solder side, however a few jumpers are needed on the component
side; if you want you can avoid that by using a double side pcb.
Pay attention to the orientation of transistors: Q1's emitter to the left, Q2 up, Q3 and Q4 right.
Once connected to the PC, a working circuit blinks D2 at 4Hz until the enumeration is completed,
then at 1Hz.
To verify that everything is working correctly use the "Hardware Test" function in the control
program: in this mode, to be executed without target devices, all the outputs (CK, D, PGM,
VDDU, VPPU, which can be reached on pins 14-15-12-1-4 of U3, with respect to GND, pin 5)
are activated in various combinations; if the measured voltages correspond to what is presented on
screen then the hardware is correctly assembled.
Top VPP voltage could be different from the set value by up to 1V; this is due to the fact that the
Quick facts DCDC converter takes VCC as reference voltage; the latter comes from the USB cable and can
Another vary from 4.75V to 5.25V; in addition the feedback voltage divider (R1-R2) can introduce another
programmer? 5% of error.
USB & HID The most common causes of malfunction are:
firmware incorrect orientation of transistors,
Control programs incorrect inductor value,
GTK graphical pcb defects like shorts or opens,
interface unsoldered capacitors,
MFC Graphicalmain microcontrollorer not programmed or incorrectly programmed (with LVP option).
interface
Command-line Component list:
interface U1 12Mhz quartz (also 4, 8, 16, 20; reconfiguration of input divider options is required)
How to ... U2 18F2550 (also 2450,2455,2458,2553,4450,4455,4458,4550,4553)
Supported devicesU3 20p socket.
Communication U4 8p socket.
protocol Q1-2 BC557 (or any PNP, pay attention to polarity)
The circuit Q3-4 BC547 (or any NPN, pay attention to polarity)
Voltage regulator D1-2 LED
How to contribute D3 1N4148 (or any diode, better if Shottky)
Download L1 100uH resistor type or other
History R1 22K
Links R2 12K
Contacts R3 100K
R4:6 10K
R7 1M
R8-9 2.2K
R10 10K
R11:23 100
R24-25 330K
R26-27 10K
C1 22-100uF 25V
C2-3 22pF
C4 >= 220nF
C5 100nF
C6 10uF
C7-8 100nF
CONN1 USB type B
CONN2-3 10 pin female stripline
CONN4 5 pin stripline
How to use
The basic circuit can host PIC devices with 8, 14, 18, and 20 pins (except 10Fxxx); they should be
inserted in U3 with alignment to pin1:
Top
Quick facts
Another
programmer?
USB & HID
firmware
Control programs
GTK graphical
interface
MFC Graphical
interface
Command-line
interface
How to ...
Supported devices
Communication I2C and UNIO memories go in U4.
protocol One-Wire devices in TO92 package can also be connected on U4: GND lead goes to RB1 (pin
The circuit 6), IO lead to RB0 (pin 5).
Voltage regulator I plan to make an adapter for 10Fxxx with 6 or 8 pins; in the meantime it's possible to get by using
How to contribute wires.
Download Other devices can be programmed using expansion boards plugged to connectors CONN2-3 (but
History they're not required for basic operation):
Links
Contacts 28-40 pin PICs + ICSP connector
8-20 pin PICs (same as main board, but there's more space for a ZIF socket) + ICSP conn.
3.3V PIC16-18 + ICSP conn. (this board has also a 3.3V regulator)
PIC24-30-33 + ICSP conn. (this board has also a 3.3V regulator)
I2C, SPI, uW memories and I2C-SPI conn.
3.3V SPI memories (this board has also a 3.3V regulator)
8-14-20-28-40 pin ATMEL micros and I2C-SPI conn
Components for the expansion boards are indicated in the schematic diagram; diodes can be of any
kind; TBD resistors should not be mounted.
In assembling the adapters I suggest to insert the expansion connectors from the component side,
and keep their plastic spacer on that side; this improves the solder strength, especially during
extraction.
In case of 3.3V devices, the presence of a 3.3V adapter (which has RB1 and RB0 shorted) is
checked by the software in order to avoid irreversible damage.
The 16F1xxx could be programmed also without such adapter (only the 16LF1xxx need it), but the
check is present for both so there is no chance of confusion.
Due to the impossibility of erasing dsPIC30 protection registers at 3.3V, these devices are now
powered at 5V; who already made the adapter (prior to v. 1.7) can easily modify it.
The following images show how to insert various target devices in the expansion boards:
Top
Quick facts
Another
programmer?
USB & HID
firmware
Control programs
GTK graphical
interface
MFC Graphical
interface
Command-line
interface
How to ...
Supported devices
Communication
protocol
The circuit
Voltage regulator
How to contribute
Download
History
Links
Contacts
Top
Quick facts
Another
programmer?
USB & HID
firmware
Control programs
GTK graphical
interface
MFC Graphical
interface
Command-line
interface
How to ...
Supported devices
Communication
protocol
The circuit
Voltage regulator
How to contribute
Download
History
Links
Contacts
Smaller devices have to be aligned to pin 1 of the respective socket, for example 8 pin PICs in the
20p. socket, or the ATTiny2313 in the 28p. socket.
Target chips can also be programmed in circuit by routing ICSP signals
(VPPU,VDDU,ICD,ICK,GND) to the application board; these signals are present in the main
module expansion connectors or in some expansion boards as a discrete connector; note that low
voltage devices require ICSP signals from a low voltage expansion board.
The ICSP-IN connector is used to program the main micro without extracting it, by means of
another programmer.
ATTENTION: the ATMEL AVR board up to version 1.7 has a bug that prevents 28 pin devices
(eg. ATMega8) from entering program mode when they are not configured with the internal
oscillator.
In order to share the same socket with 20 pin devices (eg. ATTiny2313), pin 10 is forced to VSS;
but this pin corresponds to X2 in the bigger devices, and has to be floating when the oscillator is
external.
To fix the bug it's sufficient to keep X2 floating, in one of the following ways:
a) bend pin 10 outwards on the target device so that it stays out of the socket.
b) cut the trace between pin 10 and VSS, but reconnect it when using 20 pin devices.
Top
Quick facts
Another Version 1.8 includes a jumper to short pin 10 to VSS; unfortunately the pcb is not yet updated.
programmer?
USB & HID Pin mapping of various connectors in the main and expansion boards:
firmware
Control programs
GTK graphical
interface
MFC Graphical
interface
Command-line
interface
How to ...
Map of resources used:
Supported devices
Communication
protocol Various I2C- SPI- SPI- uW-
Pin ICSP OneWire/UNIO
The circuit functions EEPROM EEPROM ATMEL EEPROM
Voltage regulator RB7 PGM
How to contribute
ICSP
Download RB6
History clock
Links ICSP
RB5 A2 W (6)
Contacts data
RB4 A1 HLD S (1)
Device
RB3 A0 CS PRE (7)
clock
RB2 expansion
RB1 Clock Clock SPI Clock Clock
Data out Data out
RB0 Data Data out Data IO
(MISO) (MISO)
Data in Data in
RC7 Data in
(MOSI) (MOSI)
RC6 WP WP RESET
RC5 USB D+
RC4 USB D-
DCDC
RC2
PWM
RC1 controls
VDD
controls
RC0
VPP
RA5 expansion
RA4 expansion
RA3 expansion
RA2 LED 2
RA1 LED 1
ADC for
RA0
Top regulator
Quick facts RE3 S1 switch
Another
programmer?
USB & HID
The schematic diagram was drawn with KiCad (it was originally created with Gschem, an open
firmware source program that comes with GEDA suite).
Control programs PCBs were drawn with PCB; I will eventually convert this to KiCad as well.
GTK graphical
With a little effort the circuit can also be mounted on experimental boards, without pcb.
interface
MFC GraphicalSchematic diagram of base module and expansion boards: Pdf, KiCad, Gschem
interface
Pcb of main module: .pdf, .png; main module + expansion boards: .pdf (also mirrored), .png;
Command-line everything in PCB format: Oprog.pcb
interface
Complete archive, includes sources, gerber, pdf, png
How to ...
Supported devices
How to program the main micro the first time?
Communication
protocol
This is an interesting problem: a new device can't work as programmer, so it must be programmed
The circuit
in some way.
Voltage regulator
Apart from asking someone else to do it for you, my advice is to build one of those serial
How to contribute
programmers, like JDM, to do the job the first time.
Download
It may seem strange to use a programmer to build another one, but there is no way to interface
History
USB without firmware; I think the effort is worth it because serial programmers are not very
Links
reliable, are slow, and of course not portable to new computers that lack serial ports.
Contacts
Make sure you program the device correctly and do not enable the LVP bit (low voltage
programming); this reserves RB5 for program mode entry and RB6-RB7 for communication, and
the result is a non functioning programmer.
It would also be a good idea to buy a backup micro, in order to program it with updated firmware
versions.
The main circuit and some expansion boards (28-40p PIC, 8-20p PIC with ZIF, 3.3V PIC16-18,
3.3V PIC24-30-33, EEPROM, ATMEL):
Top
Quick facts
Another
programmer?
USB & HID
firmware
Control programs
GTK graphical
interface Expansion board connected to the main circuit:
MFC Graphical
interface
Command-line
interface
How to ...
Supported devices
Communication
protocol
The circuit
Voltage regulator
How to contribute OneWire device in TO92 package:
Download
History
Links
Contacts
It seems that the system, in closed loop, would be stable even by itself; however it would have a
steady state error of 1/DCgain.
It's better to use a controller with a pole on the origin and a zero to stabilize everything, for example
the following controller:
D 0.25 (s + 50)
C = --- = -------------
err s
Since the hardware works with 10 bit digital data we can go from D/err to pwm/[err]:
[err]=err*1024/5
pwm=D*1024
D pwm/1024 pwm C1' - C2'z-1
C'= --- = ------------ = ------- = ------------
err [err]/1024*5 [err]*5 1 -z-1
It's clear that integer multiplications can't be used with these coefficients; the easiest solution is to
work with fractional values (i.e. divide output by 2N and multiply coefficients accordingly);
considering that pwm output is 10 bits wide and left-aligned, we can easily work with values
divided by 64.
For all calculations I used Octave, an open source mathematical modeling tool; version 3 has just
been released, and it can be used also under the famous windows (almost)operating system.
If someone is interested these are the modeling scripts I used.
The real code for the control function was written in assembly; this is necessary for performance
reasons.
In fact our C compiler calls a library function to perform multiplications, so it has to save many
variables on the stack causing a delay; in this case the resulting execution time had reached 50 us,
which is a significant fraction of the sampling period.
Instead, by avoiding function calls and manually coding the 16x8 bit multiplication (see k1 & k2),
the execution time is down to 12 us.
Step response to set point change (from 11,5 to 12,5 V), 50 ms/div
How to contribute
The best way to contribute to this project is to build it, use it, and report bugs or suggestions.
Also there are still many devices to test; check the list in supported devices.
Whoever has the know-how and patience can also expand support to other devices.
Or if you have a device that is not supported you can send it to me so that I can work on it.
If you find this project useful write me a couple of lines: , and if you
modified it show me your work.
On SourceForge you can find some forums where you can discuss about this project; you could
also recommend it or write a (hopefully positive) review.
Downloads
Contacts
Thanks
I'd like to thank all the people that contributed to the growth of this project, in particular: Anselmo
for helping with linux/git, Sandro for the highly professional PCBs, Alessandro for testing many
devices, Ken for testing many AVR devices, Luigi for testing OneWire memories, Mihaly for testing
SPI Flash memories.
Top