So that’s Embedded Programming…

Been a while, so let me catch up on what’s been going on. Mainly “real life” has been getting in the way of progress, but that’s not say nothing has happened.

LaunchPadI made huge Digikey and Mouser orders to continue to build up my inventory and have the supplies needed to proceed. The process of putting those orders together and waiting for them to ship added to the delay. There were three categories of components I picked up. First, I bought a bunch of rf pieces to get started on learning wireless communication (more on this and my failures in a later post). I also bought a couple of Ti Launchpad MSP430 development boards and a bunch of components to control water valves. While I’m far from done learning my way around the MSP430, it has already been an interesting experience.

First, some motivation. Over time thinking about this project, I’ve come around to running nodes wirelessly instead of running wires around. The MSP430 ends up being a better choice than the Arduino (AVR) chips due to their extremely low power consumption. They also are highly cost competative – coming in at around a dollar a chip at retail. Even the development boards only cost $4.30. Of course, they’re also far more hardcore, a theme running through this whole project – why do something the easy way when you can do it the hardest way possible?

As soon as I started trying to learn to program the MSP430, I realized it was not quite at the same level as the work I’d done thus far on the Arduino. The arduino has a pretty high level wrapper to make it friendly for programmers new to embedded development, while the MSP430 has none of that prettiness. Instead, you have eight letter register names that you manipulate directly. I initially started they way I approach any new language – trying to do something and reading sample code as needed to fill in gaps in my knowledge. Unfortunately, while I know enough c to get started, the actual code and variables were completely foreign to me and it was clear I had to go deeper to understand what was going on.

Fortunately, TI has put together some really good tutorials to guide the new user through learning about the chip. Specifically the Getting Started Workshop does a really good job guiding you through what you need to get started. A great example of the difference between arduino and the msp430 is in the A/D conversion. On the arduino, you just call the function “analogRead.”

  sensorValue = analogRead(analogInPin);

On the MSP430, you have to do everything manually yourself – turn on the A/D converter, start the conversion, wait for the conversion to finish and then read out the result.

ADC10CTL1 = INCH_10 + ADC10DIV_0;                  // Temp Sensor ADC10CLK
_delay_cycles(5);                                  // Wait for Ref to settle
ADC10CTL0 |= ENC + ADC10SC;                        // Samp and convert start
P1OUT = 0x40;                                      // P1.6 on (green LED)
_delay_cycles(100);                                // Wait for conversion
ADC10CTL0 &= ~ENC;                                 // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON);                   // Ref and ADC10 off
tempRaw = ADC10MEM;                                // Read conversion value

I think it is pretty clear that just reading this code doesn’t help the newbie understand what is going on. You have to go into the processor documentation, but the workshop guides you through the process pretty well.

Having this level of control lets you have very precise control over power consumption. Having the A/D on increases the power consumption greatly, so you can adjust its availability to suit the needs of your specific project. The Workshop guides you through running operations with everything enabled and powered up, then through the guide adds additional power saving options culminating in having the CPU fall down to a super low power state. This is where the MSP430 line really shines – one guy ran one along with an LCD for a couple of weeks with only capacitors. This makes it really well suited towards being solar powered.

I’ve got a lot more learning to do which I’ll be sharing over the next couple of weeks + try to tie it back into the overall project. Clearly “growing with arduino” won’t work as a name for this project any more – I’ll have to figure something else out.

Leave a Reply

Your email address will not be published. Required fields are marked *