Wednesday, February 29, 2012

Raspberry Pi now available from Farnell and RS Components

The Raspberry Pi Foundation just announced that they are partnering with Farnell and RS Components to manufacture and distribute their much anticipated 'Raspberry Pi' computer.

This is a sensible move. Else the charity would have to built up an Amazon style logistics operation from scratch -- a huge distraction from their mission to provide affordable and hackable computers for teaching, experimentation and kids to play with. I just managed to get my order in to Farnell. It wasn't easy. Their system was creaking under the load! (at 06:00 in the morning!)

A quick summary of what a Raspberry Pi has to offer: it's an electronics board about the size of a credit card (no casing is provided right now). At its heart is an ARM based Broadcom BCM2835 with integrated CPU, GPU and RAM clocked at 700MHz (and a pretty beefy GPU by all accounts!),  256MB RAM, HDMI video output, SD card for storage, 2 x USB for peripherals and external storage, 1 x 100Mbps ethernet port, 3.5mm jack for audio.  And for hardware hackers, a general purpose IO port (with hardware support for UART, SPI, I2C etc).

Cost? Well it's supposed to be about $35. I got mine for €31.87 + VAT (ie about €35) from Farnell. But that includes shipping: so it's a fair price. (BTW: here is a direct link to the Raspberry Pi  Model B at Farnell).

I look forward to my Pi in the coming days!

Update (1 Mar 2012): Just got an email from Farnell. Despite pushing in my order 13 minutes after the announcement I still didn't make the first batch of 10,000 units. ETA for my Pi: end April 2012 ☹

Monday, February 13, 2012

Getting started with the PIC24FJ64GB002 and PIC32MX110F016B

Microchip's new MPLABX development environment (free download) came out of beta a few weeks ago and the PICkit3 programmer/debugger was on special offer. So I figured this was as good a time as any to pick up a PICkit3 and to get a 'hello world' program running on the PIC24FJ64GB002 and PIC32MX110F016B samples I had in my parts drawer. Both are available in 28 pin DIP packages. (Can't beat DIPs and breadboards for quick prototyping!)

Programming the 8 bit PIC range such as 12F and 16F series with the PICkit2 programmer is simple: just connect the five ICSP pins MCLR, Vdd, GND, PGD, PGC from the programmer to the corresponding pins on the chip. Nothing else is needed. The chip can then be probed and programmed. I prefer to use the command line tool.  For example to verify that a chip was present:
pk2cmd -P
and then I'd upload myprogram.hex firmware with something like
pk2cmd -P -Fmyprogram.hex  -M -R
and apply power at 3.3V for testing (internal oscillator must be configured if there is no external crystal):
pk2cmd -P -T -A3.3

The PIC24FJ64GB002 and PIC32MX110F016B chips are not as straight forward. My naive attempt at treating them like the 8 bit PICs didn't work. I noticed searching Microchip's forums that others were have difficulty also. Like most problems relating to programming MCUs the answer is in the datasheet. You either need to read it cover-to-cover or fumble around and experiment. I'm still not sure which approach gets you there faster, but the latter is more fun :-)

There are a few important differences when compared to the older 12F and 16F series. These chips use a dual power supply. The CPU core runs at a lower voltage (usually 2.2V) and the on-chip peripherals run off a higher voltage (usually 3.3V). The core power can be configured to be supplied from an on-chip source or externally. The on-chip supply is selected by grounding the DISVREG pin and connecting Vcap to ground via a 10µF capacitor [Reference PIC24FJ64GB004 family datasheet, section 2 "Guidelines for getting started with 16-bit microcontrollers"].

Another important difference: the chip must be powered up, even for probing and programming. This is not necessary for the 8 bit PICs that I've been using. This one threw me for a bit: MPLABX with PICkit3 kept telling me no target was connected. Finally I twigged that I should have power applied:
right-click on the project and select 'Properties', select PICkit3, select the Power category from the pull down menu, select the desired voltage (usually something close to 3.3V) and check "Power target circuit from PICkit3" checkbox.

So to summarize the setup for both chips (electrically identical, just different names/functions on some pins).

  • MCLR (pin 1) to programmer MCLR
  • 10k resistor (approx) between MCLR and Vdd
  • Vdd (pin 13) to programmer Vdd
  • Vdd (pin 28) to programmer Vdd
  • Vss (pin 27) to programmer Gnd
  • Vss (pin 8) to programmer Gnd
  • PGED (choose from port 1,2 or 3) to programmer PGD
  • PGEC (chose from port 1,2 or 3) to programmer PGC. Must be the same port as that used for PGED.
  • Vcore (pin 20) to 10µF capacitor to Gnd
  • DISVREG (pin 19) to Gnd
  • Decoupling capacitor between pins 28,27
  • Decoupling capacitor between pins 13,8
  • MCLR (pin 1) to programmer MCLR
  • 10k resistor (approx) between MCLR and Vdd
  • Vdd (pin 13) to programmer Vdd
  • AVdd (pin 28) to programmer Vdd
  • AVss (pin 27) to programmer Gnd
  • Vss (pin 8) to programmer Gnd
  • PGED (choose from port 1,2 or 3) to programmer PGD
  • PGEC (chose from port 1,2 or 3) to programmer PGC. Must be same port as that used for PGED
  • Vcap (pin 20) to 10µF capacitor to Gnd
  • Vss (pin 19) to Gnd
  • Decoupling capacitor between pins 28,27
  • Decoupling capacitor between pins 13,8
You should now be able to program the chip with MPLAB and the PICkit3.

Finally the configuration bits must be set just right if you want the PICkit3 in-circuit debugger to work. The syntax used to defining the configuration bits seem seems to vary from compiler to compiler. For the PIC24FJ64GB002  this is what worked for me using the Microchip C30 C compiler version 3.30c:

        & GCP_OFF
        & GWRP_OFF
        & ICS_PGx2  // NB: set to correct channel
        & FWDTEN_OFF
        & WINDIS_OFF
        & FWPSA_PR32
        & WDTPS_PS8192);
        & FNOSC_FRCPLL
        & OSCIOFNC_ON
        & POSCMOD_NONE
        & PLL96MHZ_ON
        & PLLDIV_DIV2
        & FCKSM_CSDCMD
        & IOL1WAY_OFF);
        & SOSCSEL_IO
        & WUTSEL_FST
        & WPDIS_WPDIS
        & WPEND_WPENDMEM);
        & RTCOSC_LPRC
        & DSBOREN_OFF
        & DSWDTEN_OFF);

The configuration bits I found that worked for the PIC32MX110F016B (Microchip C32, v2.02) are:

#pragma config FPLLODIV = DIV_1 
#pragma config FPLLMUL = MUL_20 
#pragma config FPLLIDIV = DIV_2 
#pragma config FWDTEN = OFF 
#pragma config FPBDIV = DIV_1 
#pragma config WDTPS = PS1 
#pragma config FCKSM = CSECME 
#pragma config OSCIOFNC = OFF 
#pragma config POSCMOD = HS 
#pragma config IESO = ON 
#pragma config FSOSCEN = OFF 
#pragma config FNOSC = PRIPLL 
#pragma config CP = OFF
#pragma config BWP = OFF 
#pragma config PWP = OFF 
#pragma config ICESEL = ICS_PGx2 // NB: set to correct channel
#pragma config DEBUG = OFF

Note that both of these chips have several programming ports. Any can be used for programming. However for debugging you must specify which port is being used in the configuration bits.