Saturday, January 09, 2010

Shelved the PIC

I've heard from Kelly and then from Ken that the Arduino is the way to go for a hobby embedded project. I had been using the PIC for the FTH project but Michael and I discussed the Arduino and decided we really should take the advice. I bought the ATmega168 with Arduino bootloader installed and built the supporting circuit around it and was up and running within a couple hours. The Arduino is as impressive as people made it sound - seriously good stuff.

Michael started looking at the MsTimer2 library to easily hook into the Timer2 so we can get a reliable interrupt for reading the pressure transducers. I put that into the app and did some testing with delays and Serial printing to verify that Timer2 really would interrupt loop, delays, and Serial. It looks good so far.

Here's a clip of code that sets up Timer2 to just print 'Reading Transducer.' and then a Serial call that should happen about the same time as the interrupt. I got lucky in the timing and feel like it proved itself.


void setup() {
Serial.begin(BAUD_RATE);
Serial.println("FTH-Arduino Booting...");
...
// Read the transducers @ 1kHz
MsTimer2::set(1000, readTransducer);
MsTimer2::start();
}

void loop() {
delay(4000);
Serial.println("Boo");
...


void readTransducer() {
Serial.println("Reading Transducer.");
}


Here's the serial output.


FTH-Arduino Booting...
Reading Transducer.
Reading Transducer.
Reading Transducer.
BoReading Transducer.
o
Reading Transducer.


I've still got the PIC code in Bit Bucket and may build something with the PIC in the future but for now I'm loving the Arduino. Here's the current breadboard.

No comments: