As if I don’t have enough going on already (school, lab, work, numerous hobby projects, cigars and Tom Waits), I’ve begun modifications of one of those small radio-controlled helicopters using a PIC16f628A microcontroller.
I’ve done something similar with an radio-controlled car in the past (very basic “go forward, turn, go forward, back up” stuff though), but that was 5+ years ago. My goal this time is to code a program allowing the helicopter to lift-off, turn in search of the brightest source of light, and follow it. (Have you ever seen Sea-Monkeys go crazy over a flashlight? That’s my goal here, but with a helicopter)
A lot has changed in 5 years. The last time I worked on a project like this (as basic as it really is), I was using a PIC IDE on Windows 2000 (something I’ve since misplaced). I was also using the PIC16f84A then, a chip that’s since become less than favorable (less memory, needs an external oscillator)
Having migrated entirely to the Linux operating system (aside from a dual-boot laptop for school), I went in search of a decent C compiler and simulator – and I really lucked out. SDCC and GPSIM were exactly what I needed. (I have to give Micah Carrick a big thanks for his article that steered me in this direction)
SDCC is simply a Small Device targetted C compiler, so I’m not going to go into in depth here (see Micah’s great article above). BUT I did have a major issue getting it set up initially:
The problem I experienced with SDCC was that the Gentoo Portage distributed version is 2.5.6 (as of March 2010). Unfortunately, memory locations for individual pins on PORTA and PORTB on the PIC16f628A aren’t defined in the header files in 2.5.6. Usually, one can access them via RB[0-7], etc… So my advice is this – use the subversion distributed version of SDCC (which is presently 2.9.7)
My second issue getting set up was with GPSIM. I’ve not had a chance to delve into the reasons, but for some unknown reason the version 0.23.0 and 0.24.0 wouldn’t play nice with any controller I tried:
gpsim -p16f627 -c testcode.stc
gpsim – the GNUPIC simulator
version: Release 0.23.0type help for help
**gpsim> SimulationMode:51
FIXME gui_breadboard.cc Build
WARNING: command line processor named “16f627” is being ignored
since the .cod file specifies the processor
WARNING: Ignoring the hex file “testcode.asm”
since the .cod file specifies the hex code
RRR gui_breadboard.cc:createLabel p16f627 11 42
Disabling WDT
FIXME: HLL files are not supported at the moment
**gpsim> running…
attempt write to invalid file register
address 0x10a, value 0x1
could not decode trace type: 0x0
0x0000000000000066 p16f627 0x00FC 0x008A movwf pclath
Read: 0x0001 from W
Invalid Trace entry: 0x0
After flailing around trying to make gpsim happy, I finally downgraded to 0.22.0, finding that I had no issues with it.
GPSIM has some nice features – stopwatch, available breakpoints, simulated oscilloscope probes, the ability to lay out basic logic circuits, simulated LEDs and pushbuttons, etc
Ok, so now I’m all set to develop. I’ll post videos of the helicopter before and after modifications, as well as a before and after test-flight shortly.
Update: 3/28/2010:
Rob Pearce has infomed me that the issue above (regarding 0.2[34].0) has been now been fixed in subversion. While writing this article on the road, perusing the bugtracker (or reporting the bug) somehow slipped my mind – my bad. Kudos for the quick response time (once someone actually bothered to report it).
In any event, this article is meant to point out an excellent tool. Have a look at it.
FWIW, this problem happened to me in the Windows port, and sure enough, just “downgrading” to brought me to a usable system.
Cesar did the right thing, and raised this in the GPSim bug tracker; thanks. I have fixed it in the latest SVN.