Upload hex to a PIC16F628

Using an Arduino Uno, I want to program a PIC16F628 to blink an LED. To do this, I have built a shield for the Arduino to communicate with the PIC as found on this page http://rweather.github.io/ardpicprog/pic14_zif_circuit.html: . A sketch has been uploaded to the Arduino to communicate with the PIC [url https://github.com/rweather/ardpicprog/blob/f5ddf24341587013b5027f7951c72064df63f8b2/ProgramPIC/ProgramPIC.pde[/url] Elsewhere, the hex instructions for the PIC to blink an LED have been obtained and are waiting to be banged into the PIC.

The shield is on a breadboard and resembles that of the diagram except the ICSP header is excluded and 12V is applied to Q1, rather than 13V (an extra volt can be found if necessary). Since the 16F628 has 18 pins, D2 is connected to pin 14 on the PIC.

So far, all I can say is the reset button works. The red LED glows but the yellow LED doesn't show any activity when I upload the sketch to the Arduino. Assuming everything's the way it should be, except possibly the 12V/13V issue, how do I get the sketch to reference the hex code? Can I paste the code in the sketch (where?) or in a .h file and modify the sketch to reference it?

The reason I want to do it this way (from Arduino 1.01 IDE) is the programpic IDE (for Linux in my case) doesn't seem to be available to download. https://freecode.com/projects/ardpicprog

This is the circuit. Have tried the following from an Ubuntu Linux terminal:echo "Hello microcontrollers!" > /dev/ttyACM0
which makes the Arduino RX and TX LEDs flash.
Also did this: (see code below) echo "CMD_LOAD_CONFIG 0x00" > /dev/ttyACM0 This goes to the Arduino, but does it reach the Pic? Seems there's a dearth of info out there on how to use such shields. Again, the goal is to get the Intel HEX into the Pic's PROGMEM.

// Pin mappings for the PIC programming shield.
#define PIN_MCLR A1 // 0: MCLR is VPP voltage, 1: Reset PIC
#define PIN_ACTIVITY A5 // LED that indicates read/write activity
#define PIN_VDD 2 // Controls the power to the PIC
#define PIN_CLOCK 4 // Clock pin
#define PIN_DATA 7 // Data pin

#define MCLR_RESET HIGH // PIN_MCLR state to reset the PIC
#define MCLR_VPP LOW // PIN_MCLR state to apply 13v to MCLR/VPP pin

// All delays are in microseconds.
#define DELAY_SETTLE 50 // Delay for lines to settle for reset
#define DELAY_TPPDP 5 // Hold time after raising MCLR
#define DELAY_THLD0 5 // Hold time after raising VDD
#define DELAY_TSET1 1 // Data in setup time before lowering clock
#define DELAY_THLD1 1 // Data in hold time after lowering clock
#define DELAY_TDLY2 1 // Delay between commands or data
#define DELAY_TDLY3 1 // Delay until data bit read will be valid
#define DELAY_TPROG 4000 // Time for a program memory write to complete
#define DELAY_TDPROG 6000 // Time for a data memory write to complete
#define DELAY_TERA 6000 // Time for a word erase to complete
#define DELAY_TPROG5 1000 // Time for program write on FLASH5 systems
#define DELAY_TFULLERA 50000 // Time for a full chip erase
#define DELAY_TFULL84 20000 // Intermediate wait for PIC16F84/PIC16F84A

// Commands that may be sent to the device.
#define CMD_LOAD_CONFIG 0x00 // Load (write) to config memory
#define CMD_LOAD_PROGRAM_MEMORY 0x02 // Load to program memory
#define CMD_LOAD_DATA_MEMORY 0x03 // Load to data memory
#define CMD_INCREMENT_ADDRESS 0x06 // Increment the PC
#define CMD_READ_PROGRAM_MEMORY 0x04 // Read from program memory
#define CMD_READ_DATA_MEMORY 0x05 // Read from data memory
#define CMD_BEGIN_PROGRAM 0x08 // Begin programming with erase cycle
#define CMD_BEGIN_PROGRAM_ONLY 0x18 // Begin programming only cycle
#define CMD_END_PROGRAM_ONLY 0x17 // End programming only cycle
#define CMD_BULK_ERASE_PROGRAM 0x09 // Bulk erase program memory
#define CMD_BULK_ERASE_DATA 0x0B // Bulk erase data memory
#define CMD_CHIP_ERASE 0x1F // Erase the entire chip

The Arduino IDE is used only for uploading the ProgramPIC.pde sketch to the Arduino. This allows the Arduino with the shields to act as a PIC programmer.

You then need to use a different host program, a PIC programming software to talk to the Arduino acting as a PIC programmer.

blesbok:
The shield is on a breadboard and resembles that of the diagram except the ICSP header is excluded and 12V is applied to Q1, rather than 13V (an extra volt can be found if necessary). Since the 16F628 has 18 pins, D2 is connected to pin 14 on the PIC.

That would be enough to prevent the chip from entering programming mode, in my opinion.

Thanks afremont; that's relatively easy to rectify. A 1.5V cell in series with the 12V battery I have provides well over 13V.

Thank you, hiduino. As far as I can make out, such a program would not have to be very advanced. For me, though it's out on a limb, since Arduino and PIC are relatively new ventures. Linux? Think I know most of the basics but not much experience with devices. Have glanced at notes about the USB standard...

Ah, it's here:
https://github.com/rweather/ardpicprog/archive/master.zip :smiley:

The circuit was built and tested. The yellow led flashes for activity and the PIC can be read. However, a write failed message resulted when attempting a burn. The problem seems to be the 13V programming voltage being too low-- 9V.

This gets me thinking, the A5 pulse from the Arduino is probably good-- but what about its ground? The Arduino ground on the digital side is connected, i.e. right hand if USB and power jack face away from you.

Beside the Atmel's pin 20 a GND can be seen. Should I be using more than the above-mentioned ground?

Further investigation of the setup reveals

  1. Programming voltage will be provided when A1's voltage is LOW.
  2. If A1 is low enough, transistor Q1 will turn off and there will be 0V voltage drop across the 10K resistor and thus 13V at MCLR.
  3. Short of Q1 turning off, the voltage drop across that 10K resistor will be about 4V.
  4. A1's voltage measures 0.6V, whether at the terminal or on the base of Q1.
  5. Above-mentioned 0.6V prevents Q1 from turning off. However, it is present even with only the high voltage (13V) connected.
  6. There seems to be inadequate isolation between the two circuits, i.e. 13V circuit and 5V circuit.

Any comments, folks? javascript:void(0);

You should be able to block that .6V with a silicon diode in series.

  1. Short of Q1 turning off, the voltage drop across that 10K resistor will be about 4V.

How do you figure that? If Q1 is OFF, you should get about 13V at VPP. If Q1 is ON, you should see about Vcesat for that transistor; typically 0.4V or less. (12.6 V drop across the resistor.)

  1. A1's voltage measures 0.6V, whether at the terminal or on the base of Q1.

It should be 0.6V or less at the base, but closer to 0V or 5V at A1. You should not probably allow the base to float (be connected to an arduino pin with the default "input" configuration.)

  1. There seems to be inadequate isolation between the two circuits, i.e. 13V circuit and 5V circuit.

It's a pretty standard voltage-switching ciruit; no current should flow from collector to base, so the "isolation" should be fine.
Are you sure you have the correct transistor installed correctly? There's a lot of variation in transistor pinout; while you should be able to use pretty much any general purpose NPN transistor here, "generic" transistors are common with both EBC ("american pinout") and ECB ("japanese pinout") layouts, and it looks like a REAL BC548 has the less common CBE pinout.

Reply #8 on: June 01, 2013

You should be able to block that .6V with a silicon diode in series.

Good tip. Connecting the anode to A1, I got 0V on VPP when it was supposed to be that.

Reply #7 on: June 01, 2013

  1. Short of Q1 turning off, the voltage drop across that 10K resistor will be about 4V.

Reply #9 on: June 02, 2013

How do you figure that? If Q1 is OFF, you should get about 13V at VPP. If Q1 is ON, you should see about Vcesat for that transistor; typically 0.4V or less. (12.6 V drop across the resistor.)

The voltmeter read 4V across 10K resistor. Ohm's Law then points to 0.4mA flowing through that resistor-- and the Collector-Emitter junction and therefor Q1 is ON. Vc = 0.011V -- Vcesat for the range you give. Vb = 0.7V. The only conclusion I can reach is Q1 is partially on.

Reply #9 on: June 02, 2013

It should be 0.6V or less at the base, but closer to 0V or 5V at A1

That's what I'm getting since adding that diode.

Reply #9 on: June 02, 2013

It's a pretty standard voltage-switching ciruit; no current should flow from collector to base, so the "isolation" should be fine.
Are you sure you have the correct transistor installed correctly? There's a lot of variation in transistor pinout; while you should be able to use pretty much any general purpose NPN transistor here, "generic" transistors are common with both EBC ("american pinout") and ECB ("japanese pinout") layouts, and it looks like a REAL BC548 has the less common CBE pinout.

Correct transistor? Yes, BC548 as bought over the counter. Installation? Base definitely at middle pin with diode test 700mV for pin in Emitter positionand 697mV to pin in Collector position. (Looking at breadboard like a book from above with emitter at the bottom of the page, the transistor's flat side is on the right hand.) It doesn't work the other way round and I haven't flipped the new BC548 that's in now. What I also tried was changing the 10k resitor to 100k. That boosted the VPP to 10.84V but 200k gave no further improvement.

Hi all, I just want to say that I achieve success from the first attempt using the ArdPicProg (the refered site: Ardpicprog: Main Page )
My experiment was a 100% follow on the instructions on the site, hardware and software, and leads me to success from the first attempt. I have tested 16F628A, 12F629, 12F675, also with success from the first attempt…

By adding only 2 lines on the Arduino Sketch (ProgramPIC) I was able to also program 16F886 and 16F887 at the first attempt…

I did the compilation for Windows (Cygwin) and I am using the Windows-Cygwin-Windows binary (you can also compile Win-Cygwin-Posix Mode)…

For transistor, I am using 2SC1815 instead, since BC548 is difficult to find where I live.
My DC source is a notebook power supply, 19 Volts DC…

In my point of view the ArdPicProg is a wonderful soft/hard design with very well documented website, it’s really a nice project.
Now I decide to use the ArdPicProg in a project that I am doing (Moleculine Project), since it is very good and well documented.
I did a webpage with photos and diagrams, showing the experiment:

I will write another separated post specifically to comment about the ArdPicProg and also to announce my little Moleculine Project. I did post it here as a testimony of my experience with ArdPicProg.

[My Moleculine Project Documentation Website]

Regards all,
Valter Fukuoka

Hi, just want to say that I also succeed testing more different MCUs (12F1822/1840, 16F1823/25/27/28/29, 16F1938/39)...
And currently testing with success a DCStepUP circuit that uses Arduino 5Volts and creates 8V ~ 13V levels needed for MCLR/Vpp..., so that it is an alternative to the use of external source for 13V Vpp.

The new MCUs, 1xF18xx requires Vpp between 8Volts and 9Volts, so the DC Step Up circuit is adjustable...

The current prototype is shown in the picture below. "Molec" is just a project I am working that uses the above mentioned PIC MCUs... as stated on the previous post.

The changes in the code should appear on the ArdPicProg soon

Regards,
Valter