Generate Vpp for PIC on Raspberry Pi HAT efficiently - Page 1
Forum section: electronics / general

author: technix
author_rank: Super Contributor
timestamp: May 04, 2015, 06:17:25 pm
content: As implied in the title, this is about building a Raspberry Pi microcontroller HAT.My first microcontroller HAT was based on ATmega328P and AVR ICSP made an almost perfect fit to the Raspberry Pi system - it is just SPI, using the same data pins as the ones used in programs in the chip, but using the Reset line as chip select. This made an "almost perfect" fit as the AVR poses as a SPI device with 2 possible chip selects (nSS for program running it, and nRESET for ICSP) and Raspberry Pi happen to have 2 chip selects from its SPI bus. Throw in another GPIO line for interrupt and the system is complete.Now I want to design a similar one for PIC. Obviously the ICSP is different so one CS line is liberated. PGC and PGD signals can be GPIO on Pi so one of them can double as the interrupt line (or both can, allowing two different interrupts to me sent to the Pi) Now the issue is Vpp.What is a better solution in terms of efficiency: chaining two ICL7660 into quadrupling the 3.3V rail, givin to a 13.2V Vpp, or use an MC34063 to derive this 13V Vpp from 5V?Or, since the AVR seemed to make a better fit, scrap this idea and roll with AVR?

author: 22swg
author_rank: Frequent Contributor
timestamp: May 04, 2015, 06:47:52 pm
content: It just early generation of PIC's that need the 13v Vpp. Your HAT is like adding a steam engine on top of an electric car ....

author: Christopher
author_rank: Frequent Contributor
timestamp: May 04, 2015, 06:51:56 pm
content: Yes, you can program atmega thru SPI using avrdude.Does a similar thing exist for microchip PICs? I thought only for old workhorses like the venerable 648a

author: Stupid Beard
author_rank: Regular Contributor
timestamp: May 04, 2015, 07:20:04 pm
content: I would just hack up an SPI or I2C bootloader for the PIC and do it that way. It will be a lot quicker and easier than trying to implement ICSP on the pi. There's probably an app note for one, if not it would be simple to adapt the UART bootloader app note(s).If you really want to go the ICSP route then pretty much all PICs also support a low voltage programming mode which you could use instead of having to generate the high voltage Vpp. If you dont want to use LVP then just use a boost converter to get Vpp.

author: oPossum
author_rank: Super Contributor
timestamp: May 04, 2015, 07:27:48 pm
content: You can use LVP on the older parts, but you loose a pin for the LVP enable.Really best to go with a modern part that can enter programming mode with no high voltage or LVP pin.For a reasonably complete list of 8 and 16 bit parts see here:http://www.embedinc.com/products/lprog/index.htm(scroll down to supported PICs list)Also all PIC32 parts. I would recommend using PIC32MX230F064B, PIC32MX250F128B or PIC32MX270F256B. Those are 28 pin parts that start at about the price of the atMEGA328, but are much more capable.

author: technix
author_rank: Super Contributor
timestamp: May 04, 2015, 09:17:26 pm
content: Quote from: Stupid Beard on May 04, 2015, 07:20:04 pmIf I am to use an SPI boot loader, is it possible to implement it without using more pins than the AVR solution (6)? Obviously the 4-wire SPI and the interrupt line is still there, but is it adequate just wire another Pi GPIO to nRESET?Also how does the PIC interact with the Pi to allow both code updating and application communication? Is checking if SPI slave select is asserted upon reset adequate?

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: May 05, 2015, 08:09:27 pm
content: Quote from: technix on May 04, 2015, 09:17:26 pmYes. SPI works the same on PIC and AVR, so the PIC shouldn't need any more pins.QuoteChecking SS after a reset should be sufficient. Here's an SPI bootloader for the 16F877:-http://legacy.nrao.edu/alma/memos/html-memos/alma414/memo414.pdf

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: May 05, 2015, 08:59:26 pm
content: Quote from: technix on May 04, 2015, 06:17:25 pmMost modern PICs use Vpp simply as a signal to switch into programming mode, so you may only need 8~9V. However, many popular mid range PICs also require 5V on Vdd for programming. If you are using ICSP then youmustmatch it to the specs of the particular PIC you want to program.I suggest using a boot loader, because then the hardware requirements are simpler and the Pi doesn't have to worry about specific programming requirements of different PICs. You may have to burn the boot loader into the PIC with a dedicated programmer, but once that is done you know it is properly configured to suit the circuit of your HAT.

author: technix
author_rank: Super Contributor
timestamp: May 05, 2015, 09:08:25 pm
content: Quote from: Bruce Abbott on May 05, 2015, 08:09:27 pmIf I am to use a boot loader, is the SPI EEPROM interface a good protocol to use? Linux does have kernel driver for such EEPROM devices so maybe it can make flashing the devices easier. If the PIC in question does not use multiples of bytes as its instruction word length, it is padded with zeros when read and discarded when written.About protection, the boot loader area is not writable except the last few words which stored the code length and checksum and all of the app area is writable.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: May 06, 2015, 08:43:50 pm
content: Quote from: technix on May 05, 2015, 09:08:25 pmYou could make PIC emulate an EEPROM, but then the bootloader code would be more complicated and harder to debug. I would just write a small utility that is dedicated to flashing the PIC, which accesses the SPI port through one of the recommended drivers (bcm2835 library, spidev etc.).QuoteThis depends on which PIC you have and how much of the ROM you want available for user code. Even if the boot area is not write protected it should be safe so long as user code doesn't try writing to it.