MSP430

Introduction

This page contains some basic information for programming the MSP430 microcontroller (the MSP430G2553 and MSP430G2452 specifically). It’s really just a few introductory examples to get you started. There are seven so far:

For detailed information on the MSP430G2553 and MSP430G2452, please refer to the following documents:

To those learning to program microcontrollers for the first time, these documents can seem intimidating. However, it’s highly recommended that you download them and begin dipping into them for information. It can be difficult to make head or tail of microcontroller datasheets at first, but the more you use them the more familiar they become and the easier it is to find the information you need. For serious work with either of these MSP430 microcontrollers, the above documents are indispensible.

A simple example: blink an LED

To introduce the basic process we’ll use to program the MSP430 microcontroller, let’s look at a really simple example: flashing an LED on and off. The final circuit is demonstrated in the video below. The LED repeats the following sequence indefinitely: on for 0.1 seconds, off for 0.9 seconds.

Circuit

We’re going to build the microcontroller circuit on a mini breadboard and then connect the LaunchPad to it via four wires. Two of these wires will supply power to the MSP430 (red=3V and black=0V). The other two wires (yellow and green) are used to transfer the compiled program from the PC (via the LaunchPad) to the MSP430 where it will be stored in flash memory.

One MSP430 pin (P1.0, pin 2) is configured as a digital output and is used to turn the LED on and off. A 220Ω resistor in series with the LED limits the current to a level that is safe for the MSP digital output and for the LED (low mA).

Circuit schematic for blinking LED example

Here’s how my circuit looks:

Programming

The program that will ultimately run on the MSP430 microcontroller is written and compiled on a PC. We need to install some software on the PC to compile and transfer the program to the microcontroller.

  • Download the file RoboSlam.zip to a location of your choice.
  • From the zip file, extract the folder “RoboSlam” to the location “C:\RoboSlam”. (You can use a different location if you prefer, but the path to the “RoboSlam” folder must not contain any spaces.)

Screenshot showing the contents of the newly downloaded RoboSlam folder

The RoboSlam folder contains three pieces of software:

  • Notepad++ is a plain text editor, which we use to write C code into a file.
  • MSPGCC is a C compiler for Texas Intruments MSP430 microcontrollers.
  • MSP430Flasher is used to transfer compiled programs from the PC to flash memory in the MSP430 microcontroller.

The process for writing and saving the C program is as follows:

  • Create a new folder called “blink” inside the “RoboSlam” folder.
  • If your microcontroller is an MSP430G2553, copy and paste the file “build_for_g2553.bat” from the RoboSlam folder into the “blink” folder.
  • Alternatively, if your microcontroller is an MSP430G2452, copy and paste the file “build_for_g2452.bat” from the RoboSlam folder into the “blink” folder.
  • Double click the “Run Notepad++” link in the “RoboSlam” folder to start Notepad++.
  • Paste the C code shown below into Notepad++ and save it as “C:\RoboSlam\blink\main.c”.
//
// Blinking LED example for MSP430G2553
// Written by Ted Burke - Last modified 14-9-2016
//
 
#include <msp430.h>
 
void main( void )
{
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
     
    P1DIR = 0b00000001; // P1.0 is an output, P1.1-7 are inputs
    P2DIR = 0b00000000; // P2.0-7 are inputs
     
    // Main loop repeats forever
    while(1)
    {
        P1OUT = 0b00000001;     // LED on - set P1.0 high
        __delay_cycles(100000); // Approx 0.1 second delay (100000 cycles)
        P1OUT = 0b00000000;     // LED off - set P1.0 low
        __delay_cycles(900000); // Approx 0.9 second delay (900000 cycles)
    }
}

Once the C code is saved as “main.c”, it should appear in Notepad++ with coloured syntax highlighting for the C code.

The contents of your “blink” folder should now appear as follows:

Screenshot of the

To build the program:

  • Ensure that the circuit is correctly wired and that the LaunchPad is connected to the PC using the mini USB cable.
  • Double click the file “build_for_g2553.bat”. A console window should appear, similar to that shown below.

Screenshot of the MSP430 LED Blink example being built in a console window

If the build process has been successful, the contents of your “blink” folder should be as shown below. Note that a new file called “a.hex” is now present in the folder – this is the binary version of your program which has now also been transferred to the MSP430 (via the LaunchPad) and stored in flash memory.

Screenshot of the

The LED should be blinking at this point, as shown in the video at the start of this example. In this case, the microcontroller circuit draws its power from the LaunchPad (and hence indirectly from the USB socket), so it needs to remain connected to the PC. However, if a 3V battery pack was connected to the breadboard, the circuit could be disconnected from the PC and the LED would continue blinking. The program we compiled is now stored in flash memory on the MSP430 and begins running every time the chip is powered up.

Motor control

In this example, we will perform bi-directional control of two DC motors using an MSP430. The behaviour of the system is shown in the video below:

As shown in the video, once the microcontroller has been programmed and battery power is supplied, the circuit no longer needs to be connected to the PC; It works independently.

Each digital output on the MSP430 can only source a very small current, which is inadequate to power a motor directly. We therefore use an SN754410NE driver chip to interface the microcontroller to the motors. It has four inputs and four outputs. Each input is connected to a digital output on the MSP430, and controls one channel’s output. When the input voltage on a channel is high (3V), the output voltage on that channel is also high. When the input voltage is low (0V), the output voltage is also low. The low output voltage is 0V, but the high output voltage depends on the power supply voltage connected to the driver chip. The SN754410NE can therefore be used to interface the low voltage MSP430 to much higher voltage motors (e.g. 12V or 24V). In this case, the motors are being driven with 6V (drawn from a 4xAA battery pack).

Circuit

Example circuit for motor control with MSP430 and SN754410NE driver IC

The process of constructing the circuit on a mini breadboard is illustrated step-by-step in the following gallery:

Programming

//
// Motors example for MSP430G2553 or MSP430G2452
// Written by Ted Burke - Last modified 30-1-2014
// See https://robosumo.wordpress.com/msp430/
//
 
#include <msp430.h>
 
int main( void )
{
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
     
    P1DIR = 0b00000001; // P1.0 is an output, P1.1-7 are inputs
    P2DIR = 0b00110011; // P2.0,1,4,5 outputs, P2.2,3,6,7 inputs
    
	P1OUT = 0b00000001; // LED on - set P1.0 high
	
    // Main loop repeats forever
    while(1)
    {
        P2OUT = 0b00010001;      // Both motors forwards
        __delay_cycles(2000000); // 2 second delay (2000000 cycles)
        P2OUT = 0b00010010;      // One forward, one reverse
        __delay_cycles(2000000); // 2 second delay (2000000 cycles)
        P2OUT = 0b00100010;      // Both motors reverse
        __delay_cycles(2000000); // 2 second delay (2000000 cycles)
        P2OUT = 0b00100001;      // One reverse, one forward
        __delay_cycles(2000000); // 2 second delay (2000000 cycles)
    }
     
    // The program never actually reaches this point
    return 0;
}

Analog Input

//
// Analog input example for MSP430G2553
//
// Voltage on A3 is converted to 10-bit unsigned int (i.e. between 0-1023).
// An LED is switched on or off, depending whether the measured voltage
// exceeds a threshold value (512).
//
// Written by Ted Burke - last updated 12-2-2014
//

#include <msp430.h>

// Function prototypes
unsigned int read_analog_channel(unsigned int);

int main( void )
{
    // Watchdog timer
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
    
    // Digital i/o
    P2DIR = 0b00000000; // P2.0-7 are inputs
    P1DIR = 0b00000001; // P1.0 is an output, P1.1-7 are inputs

    // Analog inputs
    ADC10AE0 = 0b00111000; // A3,A4,A5 (pins 5-7) are analog inputs
    ADC10CTL0 = ADC10ON;   // Turn on the ADC
    
    int voltage;
    
    while(1)
    {
        // Read voltage from analog input A3 (pin 5)
        voltage = read_analog_channel(3);
        
        // If voltage is greater than threshold, light LED
        if (voltage >= 512) P1OUT = 1; // LED on
        else P1OUT = 0;          // LED off
    }
    
    return 0;
}

//
// This function performs a single analog to digital conversion,
// converting the voltage on analog input pin ANx into a 10-bit
// unsigned integer. Execution time for this function is of the
// order of 100us.
//
unsigned int read_analog_channel(unsigned int x)
{
    ADC10CTL0 &= ~ENC;            // disable conversion
    ADC10CTL1 = x << 12;          // select channel
    ADC10CTL0 |= ENC;             // enable conversion
    ADC10CTL0 |= ADC10SC;         // start conversion
    while(ADC10CTL1 & ADC10BUSY); // wait until complete
    return ADC10MEM;              // return digital value
}

Printing messages via the UART

//
// Analog signal record and transmit for MSP430G2553
// Samples pins A3,A4,A5 at approx 10Hz; prints values via UART
// Written by Ted Burke - last updated 12-2-2014
//

#include <msp430.h>
#include <stdio.h>

// Function prototypes
void setup();
int read_analog_channel(unsigned int);

int main( void )
{
    setup(); // configure MSP430 pins
    
    int v1, v2, v3;
    
    while(1)
    {
        // Read voltages from analog inputs A3, A4, A5
        v1 = read_analog_channel(3);
        v2 = read_analog_channel(4);
        v3 = read_analog_channel(5);
        
        // Print the three measurements via the UART
        P1OUT = 1; // LED on
        printf("%04d,%04d,%04d\n", v1, v2, v3);
        P1OUT = 0; // LED off
                
        __delay_cycles(100000); // 100ms delay
    }
    
    return 0;
}

//
// This function configures the pins and modules of the MSP430
//
void setup()
{
    // Watchdog timer
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
    
    // Digital i/o
    P2DIR = 0b00000000; // P2.0-7 are inputs
    P1DIR = 0b00000001; // P1.0 is an output, P1.1-7 are inputs

    // Analog inputs
    ADC10AE0 = 0b00111000; // A3,A4,A5 (pins 5-7) are analog inputs
    ADC10CTL0 = ADC10ON;   // Turn on the ADC

    // Basic Clock Module (set to 1MHz)
    DCOCTL = CALDCO_1MHZ;
    BCSCTL1 = CALBC1_1MHZ;
    
    // UART
    // Baudrate = 1MHz / (256 * UCA0BR1 + UCA0BR0)
    UCA0BR1 = 0; UCA0BR0 = 104;  // Set baudrate = 9600
    UCA0CTL1 |= UCSSEL_2;        // Set USCI clock to SMCLK
    UCA0MCTL = UCBRS0;           // Modulation UCBRSx = 1    
    P1SEL = BIT2; P1SEL2 = BIT2; // Set P1.2 as TXD
    UCA0CTL1 &= ~UCSWRST;        // Start USCI (release from reset)
}

//
// For the printf function (from stdio.h) to work, we need to provide
// a putchar function which transmits a single character via the UART.
//
int putchar(int c)
{
    UCA0TXBUF = c;
    while((IFG2 & UCA0TXIFG) == 0); 
}

//
// This function performs a single analog to digital conversion,
// converting the voltage on analog input pin ANx into a 10-bit
// unsigned integer. Execution time for this function is of the
// order of 100us.
//
int read_analog_channel(unsigned int x)
{
    ADC10CTL0 &= ~ENC;            // disable conversion
    ADC10CTL1 = x << 12;          // select channel
    ADC10CTL0 |= ENC;             // enable conversion
    ADC10CTL0 |= ADC10SC;         // start conversion
    while(ADC10CTL1 & ADC10BUSY); // wait until complete
    return ADC10MEM;              // return digital value
}

Timer A Interrupt

//
// Timer A interrupt example for MSP430G2553
//
// Written by Ted Burke - last updated 12-2-2014
//

#include <msp430.h>

int main( void )
{
    // Watchdog timer
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
    
    P1DIR = 0b00000001; // Make P1.0 an output
    
    // Configure Timer A interrupt
    TA0CTL = TASSEL_2 + MC_1 + ID_3; // "up" mode, divide SMCLK by 8
    TA0CCR0 =  62500;                // set timer period to 500ms
    TA0CCTL0 = CCIE;                 // compare interrupt enabled    
    _BIS_SR(GIE);                    // global interrupt enable
    
    while(1); // Now just let interrupt do the work
    
    return 0;
}

// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
    P1OUT = 1 - P1OUT; // Toggle LED on P1.0
}

Timer_A PWM for motor speed control

2014-03-28 01.51.31

2014-03-28 01.51.19

//
// Timer_A PWM example for MSP430G2553
//
// This program generates a 1kHz PWM signal on TA1.1 (pin 10).
// The duty cycle ramps up steadily from 0% to 100% repeatedly.
// This is achieved simply by incrementing the value of TA1CCR1.
// The PWM period could also be changed by assigning a new value
// to TA1CCR0, but that isn't done here.
// 
// An LED driven by TA1.1 (pin 10) steadily increases in
// brightness from completely off to fully on over a two-
// second period. This repeats indefinitely. 
//
// Written by Ted Burke - last updated 12-2-2014
//
 
#include <msp430.h>

int main( void )
{
    // Watchdog timer
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
    
    // Select primary peripheral module function on P2.2 (i.e. TA1.1)
    P2SEL  = 0b00000100;
    P2SEL2 = 0b00000000;
    P2DIR  = 0b00000100; // Pin must also be configured as an output
    
    // Configure Timer A interrupt
    TA1CTL = TASSEL_2 + ID_0 + MC_1; // Timer_A1: SMCLK clock, input divider=1, "up" mode
    TA1CCR0 = 1000;                  // Set Timer_A1 period to 1ms for 1kHz PWM
    TA1CCR1 = 500;                   // 50% duty cycle initially (500us pulse width)
    TA1CCTL1 = OUTMOD_7;             // Select "Reset/Set" output mode
    
    // This loop is just an example of varying the PWM duty cycle on
    // TA1.1 simply by updating the value of TA1CCR1.
    while(1)
    {
        TA1CCR1 += 1;
        if (TA1CCR1 >= TA1CCR0) TA1CCR1 = 0;
        __delay_cycles(2000);
    }
    
    return 0;
}

Timer_A PWM for servo angle control

//
// Servo control PWM example for MSP430G2553
//
// This program generates a 50Hz PWM signal on TA1.1 (pin 10),
// suitable for servo control. In my servo, pulse widths vary
// between 1ms (0 degrees) and 2ms (180 degrees).
// 
// The main loop just cycles indefinitely through three servo
// angles.
//
// Written by Ted Burke - last updated 28-3-2014
//
 
#include <msp430.h>

int main( void )
{
    // Watchdog timer
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
    
    // Select primary peripheral module function on P2.2 (i.e. TA1.1)
    P2SEL  = 0b00000100;
    P2SEL2 = 0b00000000;
    P2DIR  = 0b00000100; // Pin must also be configured as an output
    
    // Configure Timer A interrupt
    TA1CTL = TASSEL_2 + ID_0 + MC_1; // Timer_A1: SMCLK clock, input divider=1, "up" mode
    TA1CCR0 = 20000;                 // Set PWM period to 20ms for servo control
    TA1CCR1 = 1500;                  // Set initial pulse width to 1.5ms
    TA1CCTL1 = OUTMOD_7;             // Select "Reset/Set" output mode
    
    // This loop cycles the servo through three angle steps
    // In my servo, as in many low-cost angle servos, the
    // pulse width is controlled as follows (approximately):
    //
    // - pulse widths should be in the range 1-2ms
    // - 1ms is 0 degrees
    // - 2ms is 180 degrees
    //
    while(1)
    {
        TA1CCR1 = 1200;          // 36 degrees approx
        __delay_cycles(1000000); // 1 second delay
        TA1CCR1 = 1500;          // 90 degrees approx
        __delay_cycles(1000000); // 1 second delay
        TA1CCR1 = 1800;          // 144 degrees approx
        __delay_cycles(1000000); // 1 second delay
    }
    
    return 0;
}

Example function to read the HC-SR04 rangefinder

NOTE: The example below is for the MSP430G2553 and requires a couple of simple modifications to use with the MSP430G2452. Since the MSP430G2553 has two timers, all timer-related register names include either the number “1” or “2” to differentiate between them (e.g. TA1R and TA2R, TA1CTL and TA2CTL). However, this isn’t necessary in the MSP430G2452 since it only has one timer (e.g. TAR and TACTL). Therefore, to compile the program below for MSP430G2452, just change the following register names in the code:

  • Change TA1CTL to TACTL
  • Change TA1R to TAR
//
// Ultrasonic rangefinder example for MSP430G2553
//
// This program provides a simple example function for reading
// the HC-SR04 ultrasonic rangefinder.
//
// - An LED is driven by P1.0
// - The trigger pulse is sent to the rangefinder via P1.1
// - The echo pulse is read from the rangefinder via P1.2
// - Timer_A1 is used to measure the duration of the echo pulse
//
// Written by Ted Burke - last updated 28-3-2014
//

#include <msp430.h>

int main()
{
    int distance_cm;
    
    // Disable watchdog timer
    WDTCTL = WDTPW + WDTHOLD;
    
    // Make P1.0 a digital output for the LED and P1.1
    // a digital output for the sensor trigger pulses
    P1DIR = 0b00000011;
    
    // Set up Timer_A1: SMCLK clock, input divider=1,
    // "continuous" mode. It counts from 0 to 65535,
    // incrementing once per clock cycle (i.e. every 1us).
    TA1CTL = TASSEL_2 + ID_0 + MC_2;
    
    // Now just monitor distance sensor
    while(1)
    {
        distance_cm = read_distance_sensor_cm();
        
        if (distance_cm < 50) P1OUT |= BIT0; // LED on else P1OUT &= ~BIT0; // LED off } return 0; } int read_distance_sensor_cm() { int echo_pulse_duration; // time in us int distance; // distance in cm // Send a 20us trigger pulse P1OUT |= BIT1; // trigger high __delay_cycles(20); // 20us delay P1OUT &= ~BIT1; // trigger low // Measure duration of echo pulse while ((P1IN & BIT2) == 0); // Wait for start of echo pulse TA1R = 0; // Reset timer at start of pulse while ((P1IN & BIT2) > 0);    // Wait for end of echo pulse
    echo_pulse_duration = TA1R;   // Current timer value is pulse length
    distance = 0.017 * echo_pulse_duration; // Convert from us to cm
    return distance;              // Return distance in cm to calling function
}
Advertisements

25 Responses to MSP430

  1. failsafeday says:

    Hi Ted,

    Just wondering, would you be able to include the interrupt flag reset for the Timer A Interrupt program?

    Thanks,
    Joe Mangan.

    • batchloaf says:

      Hi Joe,

      I just checked the Timer_A interrupt example above on an MSP430G2452 and it’s working fine without needing to reset the interrupt flag. I’m assuming it would also work on an MSP430G2553, although I don’t have one handy to check it right now. I also consulted the MSP430x2xx Family User’s Guide and it says in Section 12.2.6.1 (page 367) that “The TACCR0 CCIFG flag is automatically reset when the TACCR0 interrupt request is serviced.” So it looks like you don’t need to worry about manually resetting the interrupt flag.

      Are you having a problem getting the example working? If so, perhaps there’s another reason?

      Ted

      • failsafeday says:

        Hi Ted,

        Thanks for the reply. Yeah, I’m having a bit of a problem getting the example working. I’ve included a copy of the code I’m using at the bottom of this reply if it helps(Exact same as your example, except I have a second LED toggling from the while loop).

        What I’m trying to do is blink an LED(P1.1) from the while loop and after 500ms have the interrupt pause it and blink another LED(P1.0) just once. Then return to the while loop and again after 500ms interrupt the while loop again.

        All that seems to happen is that the while loop blinks LED(P1.1) and after 500ms the interrupt takes over, blinks LED(P1.0), and continues to loop the blinkng of LED(P1.0), like its stuck in the interrupt.

        Is this whats actually supposed to happen with interrupts or is there just something wrong with my code?

        Thanks for the help,

        Joe

        //
        // Timer A interrupt example for MSP430G2553
        //
        // Written by Joe Mangan – last updated 24-4-2014
        //
        
        #include
        
        int main( void )
        {
            // Watchdog timer
            WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
        
            P1DIR = 0b00000011; // Make P1.0 P1.1 output
        
            // Configure Timer A interrupt
            TA0CTL = TASSEL_2 + MC_1 + ID_3; // “up” mode, divide SMCLK by 8
            TA0CCR0 = 62500; // set timer period to 500ms
            TA0CCTL0 = CCIE; // compare interrupt enabled
            _BIS_SR(GIE); // global interrupt enable
        
            while(1)
            {
                P1OUT |= BIT1; // Toggle LED on P1.1
                __delay_cycles(50000);
                P1OUT &= ~BIT1;
                __delay_cycles(50000);
            }
            return 0;
        }
        
        // Timer A0 interrupt service routine
        #pragma vector=TIMER0_A0_VECTOR
        __interrupt void Timer_A(void)
        {
            P1OUT |= BIT0; // Toggle LED on P1.0
            __delay_cycles(500000);
            P1OUT &= ~BIT0;
            __delay_cycles(500000);
        }
        
      • batchloaf says:

        Hi Joe,

        Sorry for the delay in responding!

        What’s going on here is simple enough. The way you have the timer setup, it will generate an interrupt once every 500ms. Under normal circumstances, that would result in your interrupt service routine (ISR) “Timer_A” being executed like clockwork every 500ms. However, there’s a problem. Your ISR includes two 500ms delays, so it actually takes over 1 second to complete. By the time it finishes, the Timer_A Capture Compare interrupt flag has already been set again, so the ISR runs again immediately!

        Ordinarily, ISR functions are designed to run for only a very short time, so they wouldn’t normally include any long delays. If you want an ISR to run repeatedly at a fixed interval, you need to make sure that the execution time of the ISR is comfortably shorter than the interrupt interval so that it doesn’t end up tripping over its own coat tails.

        In this case, I think you only want the interrupt to happen once – is that right? If so, all you need to do is include something in the ISR function to disable the interrupt so that it doesn’t repeat. Try modifying your ISR function as shown below:

        // Timer A0 interrupt service routine
        #pragma vector=TIMER0_A0_VECTOR
        __interrupt void Timer_A(void)
        {
            // Disable compare interrupt for Timer_A 0
            // by setting the Capture Compare Interrupt
            // Enable (CCIE) bit to zero.
            TA0CCTL0 &= ~CCIE;
            
            // Now flash the P1.0 LED once
            P1OUT |= BIT0;
            __delay_cycles(500000);
            P1OUT &= ~BIT0;
            __delay_cycles(500000);
        }
        

        The extra line at the start just resets the CCIE (capture compare interrupt enable) bit in the TA0CCTL0 register (Timer_A 0 Capture Compare control register 0), which prevents the interrupt from being triggered again.

        Please let me know if that doesn’t fix the problem.

        Ted

      • Ahmed Khalaf says:

        Hello Ted,
        Am in the process of learning about this field of MSP430G2553 and keep gathering some info from here and there. So, the first experiment came to my mind is to make my power wheelchair run through the wireless of RC toy car Joy Stick. Yet, since I just started with this field and have the basics about ADD, ADDC, SUB, XOR, BIS, BIC, BIT, JGE, JUMP , …etc I really found myself overwhelmed and clueless about only “how to create Forward/Backward and Left/Right instructions!!!
        Please, any kind of help that you can provide me with at this point.
        Thanks for your time
        Ahmed

      • batchloaf says:

        Hi Ahmed,

        Those commands you mentioned (ADD, ADDC, SUB, XOR, BIS, BIC, BIT, JGE, JUMP, etc) sound like assembly code instructions. Learning to program a microcontroller in assembly language can certainly be a very useful skill, but if you’re looking to get something up and running fast, I would probably suggest that you use a C compiler instead. I use MSPGCC, which is a free C compiler for the MSP430 family of microcontrollers.

        Controlling the powered wheelchair sounds like an interesting project. I’ve worked on some similar systems in the past (I used to work in an engineering research lab in Ireland’s National Rehabilitation Hospital), but it’s been a while since I looked at this kind of thing and my knowledge of the hardware interfaces is a bit rusty. What kind of hardware interface is provided on your powered chair? Also, are you planning to use the wireless receiver module out of the RC car to receive the radio signals from the handset. If so, it seems that the role of the MSP430 is to read electrical signals coming from the wireless receiver module and translate them into signals which can be inputted to the chair’s control interface. Is that correct?

        Ted

      • c d says:

        When I run Timer_A interrupt program, TAR register is not increment and execution remains on while(1) loop . Is there clock issue or some other issue?

  2. failsafeday says:

    Hey Ted,

    No prob. Just wanted to say the interrupt works perfectly now.
    Much appreciated.

    Thanks,

    Joe.

    • batchloaf says:

      Great! Glad to hear you got it working. Talk to you next week.

      Ted

      • Ahmed Khalaf says:

        hehehehe yeah it is really cool. Really am not exactly sure about whats inside the control socket, but what am going to do is to follow the output wires going to the wheels and get them connected to outputs from my MSP430. So, at this point do you have any sample code that I can use, or even modify, for my MSP430G2553 that I can generate F/B and L/R outputs ?

      • batchloaf says:

        Hi Ahmed,

        The code you need to run on the MSP430 for forward/backward/left/right completely depends on how the MSP430 is connected to the control interface of the wheelchair. Without more information about what type of control interface is available in your chair, it’s not really possible to provide a useful example. Can you provide more information about the chair and its normal controller?

        Ted

  3. WalkerThong says:

    Hi Ted,
    Can u help me to write a code about ultrasonic rangefinder with vibrating motor ? i tried my best to do it but still no progress…

  4. nickmushhayz says:

    Hi Ted,
    My username is nickmushhayz
    Sorry about the delay.
    Thanks

  5. subhajit says:

    hello I would like to ask you if I have to generate a 10khz signal in 50hz cycle then what is the solution will the below code help????
    if((P2IN&BIT5)==1)
    {
    TA1CCR0 = 105;
    TA1CCR2 = 50;
    TA1CCTL2 = OUTMOD_7;
    TA1CTL = TASSEL_2 + MC_1;
    P2IFG &=~BIT5;
    }

  6. c d says:

    Hi Ted, I have some confusion in Timer_A interrupt example. What i understand is TAR register value increase at every clock pulse and when its value equal to TA0CCR0 register, interrupt will generate and it toggle the pin value. But the problem when i run the program is TAR register value not increment. Where is the problem i don’t understand. TAR is not getting the clock or any other problem?

    • batchloaf says:

      Hi cd,

      How can you tell that the TAR register is not incrementing? Are you running this on a physical MSP430 chip or in some kind of simulator?

      Ted

      • c d says:

        I am running on simulator. Sorry i forget to specify and thanks for reply.

      • batchloaf says:

        Hi c d,

        I’m not sure why it’s not working for you, but is it possible for you to try it on a physical chip in case it’s something to do with the simulator? I don’t have a chip here with me, but when I posted the code originally it seemed to be working fine (on a physical chip). I haven’t tried it in any simulator though, so I’m not sure if there’s some setting you need to enable or something like that in order to use the Timer A module.

        Ted

  7. c d says:

    O.K. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s