The use of battery-operated electronics gadgets is increasing fast in our daily lives. Products are expected to be versatile, while consuming minimal power. Reduced power consumption has added advantages of smaller size and cost-effective products.
The MSP430 family of ultra-low power microcontrollers from Texas Instruments meets these requirements well. These microcontrollers combine a number of precision components like comparators and analogue-to-digital converters with the versatility of a 16-bit CPU, Flash memory and many digital modules. The entire architecture is aimed at operating the end product at the lowest power without compromising on accuracy and functionality. Its low cost is an additional attribute that has seen the use of MSP430 microcontroller in products like blood-glucose meters, energy meters, clinical thermometers, handheld weather monitors and handheld precision instruments.
Here we introduce you to the architecture of MSP430 and tools to help you design ultra-low-power products.
Introduction to MSP430
Key features of MSP430 microcontroller are:
1. 16-bit RISC CPU
2. Current drawn is less than 0.1 μA in ‘off’ mode (RAM retention) and less than 0.5 μA in ‘standby’ mode
3. The microcontroller can wake up in less than 1 μs from power-down to full-speed functional mode
4. Zero-power-brownout detection circuit
5. 1kB to 128kB in-system-programmable (ISP) Flash memory
6. Intelligent peripherals to boost performance and versatility. These include:
• LCD drivers
• Communication ports like UART,SPI, I2C and IrDA
7. Embedded emulation
8. 14-pin to 100-pin packing options
The microcontroller features multiple frequency clocks so as to run peripherals at the required frequency. There are three clocks in total, of which ACLK (auxiliary clock) is the low-frequency clock while MCLK (main clock) is the master clock which is normally at a higher frequency (see Fig.1). The third is SMCLK (sub-main clock).
ACLK can be sourced from an external 32.768kHz watch crystal or an internal very low-frequency oscillator (VLO). The CPU is driven by MCLK, which is derived from the internal high-frequency digitally controlled oscillator (DCO) whose frequency can be selected using software settings.
MSP430 is designed to extensively support interrupt-driven burst processing as indicated in Figs1 and 2.This ensures ultra-low-power operation of the system.
Key features of its 16-bit CPU are:
1. No accumulator bottleneck
2. RISC architecture with:
• 27 core instructions
• 24 emulated instructions
• 7 addressing modes
• Constant generator
3. Single-cycle register operations
4. Memory-to-memory atomic addressing
5. Bit, byte and word processing In this part of the article, we have described the Flash programmer-cum-emulator for MSP430 family devices that can be built with readily available components. Part 2of the article will demonstrate two examples: a blinking LED circuit and a circuit to read temperature accurately on a digital multimeter based on MSP430F2013 chip. The pin details of a 14-pin MSP430F2013 device are shown in Fig.3
MSP430F2013 features a 16MHz CPU, 2kB Flash and 128-byte RAM. It has a 16-bit sigma-delta ADC, about ten ports with interrupt capability and in-built pull-up/pull-down resistors, 16-bit versatile timer with two outputs, 16-bit watchdog timer, SPI and I2C interfaces, and a zero-power-brownout protection block. Brownout protection ensures system safety during power-‘on’ or power-‘off.’ One of the main reasons for selecting this device is its availability in DIP package, which makes it easy for hobbyists to handle.
Tools for programming and debugging
Every MSP430 chip has a JTAG interface that is used for downloading the user program into the Flash memory of the microcontroller and running and debugging the code. For this, the following tools are required:
1. Development software that resides in the PC. These are typically called integrated development environments (IDEs). Following choices are available:
(a) IAR Embedded Workbench Kickstart version. This freeware from IAR Systems is sufficient for developing simple programs in ‘C’ with size limit of 4 kB. However, there is no such limitation for code development in Assembly language. A screenshot of a typical IAR embedded workbench environment is shown in Fig.4.
(b) Code Composer Essentials Evaluation. This freeware from Texas Instruments is based on industry standard Eclipse open-source platform. You can use it to develop code up to 8kB size.
Either of the above software can be downloaded from Texas Instruments’ website by selecting ‘tools & software’ option under the MSP430 ultra-low power microcontrollers section.
2. Hardware tool called the Flash emulation tool (FET). It connects the PC to the MSP430-based system. Two types of FET tools are available:One is based on the parallel port, while the other is based on the USB interface.
Fig.5 shows the block diagram of the MSP430 development system. The next section describes the construction of Flash Emulation Tool based on PC’s parallel port called ParaFET, which can be used to interface with any of the MSP430 target devices.
Designing MSP430 Flash emulation tool
Fig.6 shows the ParaFET circuit or Flash emulation tool based on the PC’s parallel port. As you can notice, the PC connects to this board through a 25-pin, D-type connector. The JTAG interface is established through the 14-pin FRC connector. It is important to note that the signals on the PC side are TTL-compatible and referenced to 5V, while the MSP430 works off 1.8V-3.6V supply. For Flash programming, the voltage needs to be a minimum of 2.2V.
The main component that is used to interface the signals from the PC side to the MSP430 is the octal tristate buffer based on SN74AHC244 or SN-74HC244 IC. This chip along with the of the simple circuits.
Due to the current-drive limitation of the parallel port, the users have to ensure that the peripheral logic connected to the MSP430 chip doesn’t consume more than 1 mA of current. For cases where the MSP430 system consumes higher current than that supplied by the can be boosted using the PC’s USB port. The USB port has 5V supply and can drive up to 100 mA.
A USB cable needs to be connected between the FET and USB port on the PC. USB supply is taken through a precision low-dropout regulator using TL431 voltage reference, which gives a stable voltage
The TL431 is a three-terminal precision adjustable shunt regulator, with specified thermal stability over applicable automotive, commercial and military temperature ranges. Its output voltage can be set to any value between Vref (approximately 2.5 V) and 36V, with two external resistors. Typically, the device has output impedance of 0.2 ohm. The active output circuitry provides a very sharp turn-on characteristic, making the device an excellent replacement for Zener diode in many applications, such as on-board regulation, adjustable power supplies and switching power supplies. Presence of this voltage automatically blocks the supply from parallel-port pins 9 and 1 due to Schottky diodes SD1 and SD2.
Note that the USB connection is required here for driving extra power and regulated supply but not for any signal communication. When the peripheral logic in the target MSP430 board consumes less than 1 mA, the power from the USB port is not required. Hence, power from the USB port is used in the ParaFET when:
1. The target board consumes more than 2 mA and less than 100 mA.
2. The target board requires a well regulated 3V supply.
The ParaFET circuit components can be accommodated on a single-side PCB. All the components used in the circuits including the ParaFET, blinking LED and thermometer have been listed in the parts list above. An actual-size, single-side PCB layout of the ParaFET circuit is shown in Fig.7 (View as PDF) and its component layout in Fig.8 (View as PDF).
Once the components are soldered, the board can be connected to the PC’s parallel port.
The 25-pin parallel-port connector should be a female connector mounted on the PCB board. Attach the body of the female connector to the PCB board firmly. Connect it to ground line of the circuit through a 3.3-kilo-ohm resistor. P1 and P2 shown in the circuit are nothing but the connecting points of the metallic part of connector CON1 to the PCB board. A 25-pin FRC cable about 40cm in length with 25-pin parallel-port male connector at both ends can be used to connect the circuit board and the PC.
A 14-pin FRC cable about 20cm in length with 14-pin header (female) at both ends can be used to connect the target board from the JTAG connecting points. An industry-standard USB cable is required to connect the PC when extra power is required in the target board. Glowing of LED1 indicates that the board is connected to the PC.
After you have successfully assembled the circuit, however, without invoking the IAR IDE tool and connecting a target board to the ParaFET, not much can be tested. The next section will describe building the target board for testing the working of the ParaFET.
Now, we describe here construction of the target board to test the working of the ParaFET circuit. The internal block diagram of MSP430F2013 is shown in Fig.9.
Building the applications
The target board combines two applications: a blinking LED and a precision digital thermometer based on MSP430F2013 chip. The circuit is shown in Fig. 10. (Refer to Parts List.)
To make you familiar with MSP430 programming and debugging, let us begin with a simple blinking-LED application. For this purpose, it is recommended to use a 3mm or 5mm LED which consumes less than 2 mA. Resistor R25 and capacitor C3 provide power-‘on’ reset to the MSP430. C4 and C5 are filter capacitors between VCC and GND. The connections include the TDO, TDI, TMS, TCK, TEST, RESET, +VCC and GND lines, which are terminated at the 14-pin JTAG connector (or FRC connector).
The Blinking_LED.c program is written in ‘C’ language can be downloaded from the link at the end of the article. The program starts with the msp430×20×3.h header file for MSP30F2013 device. This file is automatically picked up by the compiler from the IAR installation directory during program compilation. At the beginning of the program, the watchdog timer needs to be stopped. Otherwise, it will cause a non-maskable interrupt after about 32 ms.
Now, set up the clock system. By default, MCLK and SMCLK start off with the internal digitally controlled oscillator (DCO) at 1 MHz.ACLK has been programmed to use the internal very low-frequency oscillator (VLO), whose oscillation frequency is approximately 10 kHz. So there is no need to connect any external crystal.
Next, configure the port modules. The unused bits of port 1 are programmed as outputs with a value of zero. This ensures that stray voltages on this port don’t cause in advertent leakage currents. Port 2.6 is configured as the output to drive the LED through resistor R29.
Programming and debugging
The steps for programming and debugging after installing the IAR Embedded Workbench Kick Start for MSP430 in your system follow:
1. Connect the parallel port FET board (ParaFET) to the PC’s parallel port.
2. Connect the MSP430 target board to the 14-pin FRC connector from the ParaFET board.
3. Start IAR system from the desktop.
4. Select ‘Create New Project’ option from ‘Project’ menu (refer Fig.11).
5. Give a suitable project name, e.g., BlinkingLED.
6.Select ‘New File’ from ‘File’ menu. It will open up a blank document.
7.Copy and paste the blinking LED program to the blank document.
8. Right-click ‘Untitled’ tab and enter the file name with ‘.c’ extension, e.g., blinking_led.c
9. In the left window pane, right click the project name and select ‘Add’ option to include ‘blinking_led.c’ program.
10. Right-click the project name and select ‘Options’ (refer Fig. 12).
11. Left-click the square button next to the text box containing ‘Generic MSP430 Device’ and select ‘MSP430F2013.’
12. Click ‘Library Configuration’ and select ‘Normal DLIB’ for library option.
13. Click ‘Library Options’ tab and select ‘Tiny’ for printf formatter and ‘Small’ for scanf formatter; these settings ensure small size of the compiled ‘C’ code, which is appropriate for the applications given in this article.
14. Click ‘ok.’
15. Again, right-click the project name and select ‘Debugger’ from ‘Options’ pull-down menu. Here, you can choose between simulator and FET debugger options.
16. Select ‘Simulator’ to simulate the program in software and ‘FET Debugger’ to download the program using ParaFET to the target board in order to program the MCU and do an in-circuit emulation. Ensure that the FET debugger is either Texas Instruments LPT-if or just parallel-port-if.
17. Invoke the simulator/debugger by clicking the icon shown in Fig. 13.
18. On clicking the debug button, the IAR will compile the program and give a message saying that it is erasing the flash and downloading the program. If the program download is successful, the debugger environment comes up. Now, the program is ready to run on the target board.
19. Remove the ParaFET circuit and test the blinking of the LED. The LED should blink with ‘on’ and ‘off’ durations of about one second each.
1. Ensure that the target board is not connected to the battery when it is connected to ParaFET.
2. USB connection is not required for the blinking-LED application. However, it is required for digital thermometer program.
3. After ensuring that the program is working correctly, disconnect the target board from ParaFET and connect the external battery. The target board should work off the external 3V
After successfully testing the LED blinking application program, you can proceed to the digital thermometer application. Repeat the above steps for digital thermometer program.
The CPU itself works off an internal oscillator, so there is no need to connect an external crystal. The high resistance (82-kilo-ohm) thermistor keeps the system power consumption low and also makes the error quite negligible. It is connected to 1.2V (Vref) internal voltage reference pin 5 (p1.3) through resistor R27 (680-kiloohm). We recommend use of a metal film resistor for linearity and precise output. Metal-film resistor has better temperature characteristics and current- noise suppression level. It is good to measure the value of this resistor and note down before soldering it, as this value can be used in the program to improve accuracy.
Designing a low-cost precision thermometer
Here we describe a simple add-on circuit for a digital multimeter that enables direct read-out of temperature with fairly high degree of accuracy. Designing with MSP430 microcontroller
results in low cost, low power consumption and high precision of the application.
The circuit is designed for use with a commonly available 82-kilo-ohm thermistor bead. A digital voltmeter is connected to the board to read out the temperature directly. For example, a value of 10°C is displayed as 100 mV, 25.6°C is displayed as 256 mV and so on.
The CPU itself works off an internal oscillator, so there is no need to connect an external crystal. The high resistance (82-kilo-ohm) thermistor keeps the system power consumption low and also makes the error quite negligible. It is connected to 1.2V (Vref) internal voltage reference pin 5 (p1.3) through resistor R27 (680-kilo-ohm). We recommend use of a metal-film resistor for linearity and precise output. Metal-film resistor has better temperature characteristics and current-noise suppression level. It is good to measure the value of this resistor and note down before soldering it, as this value can be used in the program to improve accuracy.
Capacitor C7 (470nF) is used to filter noise on reference voltage pin 5. The voltage across the thermistor is measured using the differential voltage on pins A0+ and A0- of ADC channel 0. This method of measurement also helps in rejecting any common-mode noise that the thermistor leads might pick up.
The temperature output is available at pin 4 of the MSP430 MCU. It is fed to the digital multimeter through an R-C filter formed by resistor R28 and capacitor C6.
The JTAG pin connections are brought out to a 14-pin FRC connector which is used for flash programming and debugging. Push-to-on switch S1 is used to generate a trigger to the system to toggle the system state between active and power-down modes.
Thermistors are highly non-linear components whose resistance decreases with increase in temperature. It has a negative temperature coefficient. Thermistors are good in that these are very sensitive to temperature changes and quite inexpensive. However, their resistance vs temperature characteristic is highly non-linear. Hence normally it requires complex signal conditioning to measure the temperature accurately. It is exactly in this respect that the circuit becomes versatile as the non-linearity of the thermistor behaviour can be easily compensated in software. Here, it is assumed that the user has characterised a thermistor and therefore has a lookup table of resistance vs temperature readily available.
The formula to measure the thermistor resistance is derived as follows:
Voltage across the thermistor
where R1 is the reference resistor (680-kilo-ohm), Vref is the internal voltage reference (1.2V) and Rt is the thermistor resistance at a given temperature.
From Eq. (1), we can obtain thermistor resistance:
Using the lookup table, consisting of characterised values of resistance vs temperature, along with a linear interpolation technique, you can get the equivalent temperature with a fairly high degree of precision.
Next, convert this value into a precisely scaled PWM waveform such that the average value of this waveform, in volts, is equal to the temperature measured in °C. As the PWM waveform swings between ground and VCC, the average value is dependent on VCC. In this case, since we are using a battery without regulation, VCC changes over time as the battery discharges. Hence the program measures the battery voltage periodically and always uses this value to create the right PWM waveform. Thus a simple PWM is used to generate an accurate digital read-out on the multimeter over the entire lifetime of the battery.
The digit_thermo.c thermometer program is written in ‘C’ language. It can be downloaded from the link at the end of this article. Here is the outline of the program.
After the initial variable declarations comes the res_temp_lookup table, containing the resistance vs temperature values. About 99 values are present in this table to cover the temperature range from 0°C to 100°C accurately. The get Tem DegC function is defined to fetch the correct value of temperature for a given thermistor resistance after interpolation between adjacent entries in the table.
The clock system is programmed to run both MCLK and SMCLK on the internal DCO at 2 MHz. ACLK runs on VLO. Ports P1.0, P1.1 and P1.3 are programmed to ensure proper ADC connectivity. ADC registers are programmed to use SMCLK.
The timer is set up such that it generates a 2kHz PWM waveform on port 1.2, which is fed to the digital multimeter. Switch S1 takes the system to sleep mode or to active mode.
Variable sysOn is used as a flag to indicate the state of the controller system. This flag is toggled whenever an interrupt is generated using switch S1. The sysOn has a value ‘0’ when S1 is pressed momentarily. When sysOn is ‘1,’ the system will be in active mode and keep measuring the temperature. When sys On is ‘0,’ the system will be in sleep mode.
Even in active mode, the system normally enters low-power mode 1 (or LPM1 mode), where MCLK and the CPU are ‘off’ but SMCLK and ACLK are running. SMCLK is needed to keep the PWM output active to enable continuous reading of the temperature.
The watchdog timer is programmed to wake-up the system approximately every second. On wake-up, the system measures VCC value and the thermistor resistance through the ADC channels. The resistance is converted into temperature. These values are used to set up an appropriate duty cycle on the PWM waveform whose average value equals temperature in °C.
Note that this system consumes about 500 μA of current when measuring and displaying temperature. This means that it will work for more than 300 hours continuously with a CR2032 (3V lithium cell). In sleep mode, the system consumes just about 0.1 μA. Hence the battery will last longer for intermittent temperature measurements. Additionally, the low sleep mode current eliminates the need for a separate power switch as the system can be put to sleep mode without worrying about draining the battery.
Combined actual-size, single-side PCB layout for the blinking LED and thermometer is shown in Fig. 14 (View as PDF) and its component layout in Fig. 15 (View as PDF). Note that the PCB has a provision for connecting an LED, though it is not used in the thermometer program.
Download PCB and component layout PDFs (Fig. 7,8,14,14,15): click here
You may visit the www.ti.com/msp430 to get access to all the datasheets, user guides, application notes, example codes and development tools pertaining to the MSP430 chip.
Download source code: click here