Memsic dual-axis accelerometer: (Freescale mc9s12dg256b and the Dragon12-P board) AND (Microchip PIC16F690 with CCS C)

I cleaned up a little in my junk room/hobby room/office last night, and I found something in my IC bin that I thought was pretty cool. I bought it about 2 years ago, and I never opened it. It’s the Parallax Memsic 2125 Dual-axis accelerometer.

This project is done on the Dragon12-P eval board since that is what I am using in school, but I plan on making a Microchip version as well. [I say this now, but it may be months before I actually have a chance. I have to focus on school again starting tomorrow]. I did it within 12 hours of saying so. Here’s the deal: I used a different approach with the Microchip. It is completely and totally simple compared to Freescale.

The Freescale route used a Capture port. I tried this with Microchip, but it didn’t work. I simply made a function that works just like a Capture. I call the function. If the input is high, it waits until it goes low and then starts the timer from zero. Then it waits until the rising edge and then reads the timer into a variable. Then it waits until the input drops to low, reads the value into another variable. Done!

Source code for MC9S12DGxxx (Dragon board): main.c
Includes: TERMIOSCI.HTERMIOSCI.C

Source code for PIC16F690 (Pickit2): main.c (only uses one axis)

Datasheet for Memsic 2125 (Parallax): Memsic 2125 pdf

Continue reading

Update on microcontrollers: Microchip and Freescale compilers (Hi-Tech, MPLAB C, Codewarrior)

Lately, I have had my eyes opened some in the microcontroller field. C compilers for Microchip: HI-TECH or CCS? Free or pay?
The article pretty much blasts Hi-Tech for being expensive and for creating code that is less than optimal. I really had a “come to Jesus” moment recently when I realized that not everyone wants to pay $150 or $200 dollars for a compiler. This is especially true if the hobby is planned to be short lived.

Microchip

I did a little research to find the compiler listing for Microchip. Both MPLAB C and HI-TECH have lite versions for programming Microchip’s microcontrollers. Microchip C CompilersHI-TECH User Manual…There are several MPLAB C user Manuals depending on the chip structure.

The Pickit 3 programmer is less than $50 usd. You don’t even need special programmer hardware since you can build a header in your circuit to program any chip. The PDF user’s manual describes how to program the ICs. See page 24. Pickit3 User Guide

Freescale

I have had to learn C for Freescale microcontrollers for school. I can’t say that using Freescale is easy, but I have enjoyed learning. I had to buy this book for school, and it has helped some. The downside is the price. The HCS12/ 9S12 by Han-Way Huang

Freescale has offered a great compiler for free. The other cool thing about Codewarrior is that it is supported in Linux (IDE!!!). CodewarriorCodewarrior specs

I could not find a tutorial or user manual for Codewarrior, but I can tell you that programming Freescale is a labor intensive process that involves an intimate involvement with the register names. Example, in CCS, to make an output high you simply say ‘output_high(PIN_A1);’. This is not the case for Freescale. ‘DDRA=0×01; PORTA=0×01;’. DDRA sets the direction of port a, pin 0 as output. PORTA sets that pin high.

Conclusions:

I hope that this information is helpful. 2.5 years ago when I wrote the original article about Hi-tech and CCS, I was looking for a “get rich quick” scheme to programming in C. I found the book and used the compiler from that book. Yes, I have gained much knowledge from it, but now I share with you that the same can be done with any of these products for less money. The code may not be optimised with the lite versions and there may be some tiny limitations, but for beginners that isn’t going to make a difference. Even for the more advanced users, these limitations are not that bad.