Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I would like to know if there is a way to program a PIC for the first time (write in Flash) through an FPGA card.

The PIC is already soldered to the FPGA and I can't remove it. No bootloader exists on the PIC. Thus I need to program it in USART / SPI / I2C mode with a bootloader so that it can receive data from the FPGA.

I know that normally I have to unsolder it, connect it to a hardware programmer like PICKit and program it with a software on the computer like MPLAB, but I cannot afford that.

I can generate the bootloader with MPLAB, which is a .hex file, but how can I transfer it to the FPGA and then to the PIC through the FPGA pins?

PIC used is Microchip PIC12F1822.

share|improve this question
2  
Just checking: can you reprogram the FPGA (ie you have all the tools necessary to do this)? –  pjc50 Jun 18 at 12:44
    
This this some kind of development board? –  Matt Young Jun 18 at 12:49
    
Yes, I have all the tools necessary to reprogram the FPGA (it's connected to the computer through standard usb). –  Myst Jun 18 at 13:03
1  
No, they were blamed because they did not make this effort. Actually, I am on an internship and I found that very unprofessional. Though I still need to fix the problem. I really can't see a way to reprogram this PIC with other ways than an external programmer which I cannot use because the package is already done. –  Myst Jun 18 at 13:30
2  
Is there no way to solder some jumper wires to either traces or pins on the PIC in order for you to program it through an external programmer? Trying to do it through the FPGA sounds like a graduate thesis project. –  horta Jun 18 at 15:22

2 Answers 2

No, you don't need to, in fact you can't, use SPI, UART, or I2C to program the PIC. The only way to get a new program into a PIC that doesn't have special code loaded for that purpose (a bootloader) is to use the external hardware programming interface. Electrically, this means connecting to Vss, MCLR, PGC, and PGD. It can be useful to have the programmer also connected to Vdd, but not necessary for this chip as long as the Vdd level is known and the programmer adjusted accordingly.

The low level hardware interface is quite simple. PGD is the data line, which is sampled by the PIC on the falling edge of PGC (the clock line). To get the PIC into programming mode in the first place, a special 32 bit key is clocked in relative to specific edges on MCLR (although see note below regarding high voltage programming).

The higher level protocol gets more complicated. Most things are done with 6 bit commands, some of which are followed by 14 bit data words. You have to read the programming spec carefully. Note that the programming spec is a separate document from the datasheet. Go to the product page for your particular PIC on the Microchip web site, and you will find a link to the programming spec in the documents section.

Added about high voltage programming

These kinds of PICs have two ways to enter programming mode, high voltage (HVP) and low voltage (LVP). The high voltage method requires raising MCLR to between 8 and 9 volts and to keep it there during programming. This method always works, regardless of any possible data programmed into the PIC.

The low voltage method of entering programming mode starts by driving MCLR high, then low, then clocking in a special 32 bit key sequence using PGC and PGD normally. The part will enter programming mode upon the correct key sequence, and will stay in programming mode as long as MCLR is held low.

The low voltage method can be disabled by one of the config bits. However, the erased state of the config bit allows low voltage programming, it is shipped from the factory that way, and this config bit can only be set to disallow LVP if programming was entered with the high voltage method. Therefore, for LVP to not be enabled, all the following have to be true:

  1. The PIC was last programmed with a HVP-capable programmer, and the HVP program entry mode was used.

  2. The HEX file programmed into the PIC deliberately sets the LVP bit in config word 2 to the non-erased state.

Since disabling LVP pretty much requires a deliberate action and the right programmer, it is likely still enable. If it was deliberately disabled for some strange reason, then you have to supply 8-9 V on MCLR to get the PIC into programming mode at least long enough to perform a bulk erase (which re-enables LVP).

share|improve this answer

Programming a PIC requires a high voltage. Yes, it is possible to switch a PIC into "LVP", or Low-Voltage Programming mode, but you need a high voltage programmer in order to do this.

If your PIC has already been put into LVP mode then yes, you can easily program the PIC from the FPGA. The dataheets all contain the programming waveforms needed to program the chip, so it would be a case of building your own PIC programmer device in the FPGA.

However, if the PIC hasn't been put into LVP mode, you will need to generate a high voltage (typically 10V) and apply it to the MCLR pin at the right time to enter programming mode. If you don't have this kind of hardware already on your board then it would require additional hardware that is ultimately controlled by the FPGA as to when it is triggered.

Most PIC programmers include a small boost regulator (voltage doubler) to take the provided 5V up to 10V using a PIC onboard to manage the voltage regulation. They often use PWM from the PIC and an ADC input on the PIC as a simple boost regulator.

You should take a look at the publicly available PICkit2 schematics.

share|improve this answer
1  
No, quite likely no high voltage is required. Most of the newer parts, including all of the 12F1xxx/16F1xxx series, can use a key sequence to enter programming mode. This sequence doesn't require high voltage. This can be disabled in the configuration, but the part comes from the factory with the key method enabled. Unless someone deliberately disabled key sequence program mode entry, it should still be available. If it is disabled, then yes, you have to raise MCLR to 8-9 V to get into programming mode. –  Olin Lathrop Jun 18 at 14:42
    
Key programming mode is LVP mode. It relies on LVP=1 in the config. It looks like that chip defaults to LVP=1, but IS it =1 on that specific chip, or has it been programmed with LVP=0 already? Who knows? Like I said - IF it is in LVP mode then you don't need the HV, otherwise you do. –  Majenko - not Google Jun 18 at 14:51
    
So in order to program in LVP Mode, I need to implement some "digital" PIC programmer (VHDL) into my FPGA ? I really cannot think of a way of doing that. Could you help me to build it ? –  Myst Jun 20 at 12:46
    
No, I can't. You have the schematics for the pickit2 available, so you know what signals are needed. You have the source for the pickit2 firmware available, so you know how to communicate. You have the programming data sheets available, so you know what instructions to send and how to send them. How you communicate the firmware to the PIC from your computer is entirely up to you. How much intelligence do you want in your FPGA, and how much at the PC end? –  Majenko - not Google Jun 20 at 12:50
    
Ok, thank you. In the first place, I am going to try to program the PIC directly with the PICKIT 3. Regarding the PICKIT (that my firm has bought for the purpose), I am afraid to connect it directly to the pins of the PIC since these are also connected to the FPGA. I am concerned that some voltage may go through the turned off FPGA and do some damage. Is that a justified concern ? –  Myst Jun 20 at 12:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.