Category Archives: Ti Launchpad

ISR PWM Motor Control

This code runs the Low Voltage Motor Booster Pack for the MSP-430 with the MSP430G2553 chip but could easily be adapted to any microcontroller. This uses Timer1_A0 to make a timing interrupt. Using the timing interrupt it changes the duty cycle of the PWM. Supports reverse by sending the “move_motors” command negative values.

Default is P2.0, P2.1, P2.2, and P2.3 for controlling the motor driver. P1.0 is toggled (on board LED) in the ISR.

Code: CCS V5

Project File Ver1.0

 *Version: 1.0
 *Parker Dillmann
 *The Longhorn Engineer (c) 2013 
 *Check bottom of file for License.

#include "msp430g2553.h"
#include "isr_motor_pwm.h"

#define Motor_DIR P2DIR
#define Motor_OUT P2OUT

#define Motor_A1 BIT0
#define Motor_A2 BIT1
#define Motor_B1 BIT2
#define Motor_B2 BIT3

volatile int Motor_Speed_A;
volatile int Motor_Speed_B;

volatile int Motor_isr_cnt;

void init_motors(void)
  TA1CCTL0 = CCIE;             //Enable the CCR0 interrupt
  TA1CCR0 = 50000;             // Set the interrupt register to "trip" each 50000 cycles"

  TA1CTL = TASSEL_2 + MC_2 + TACLR;     //Timer_A Source Select; Set source to SMCLK, continuous mode, clear TAR

  P1DIR |= 0x41;                            // P1.0 output

  Motor_DIR |= (Motor_A1 | Motor_A2 | Motor_B1 | Motor_B2);    //Set Motors to output
  Motor_OUT &= ~(Motor_A1 | Motor_A2 | Motor_B1 | Motor_B2);    //Set Motor outputs to 0

  Motor_isr_cnt = 1;


void move_motors(int Speed_A, int Speed_B)
  Motor_Speed_A = Speed_A;
  Motor_Speed_B = Speed_B;

void stop_motors(void)
  Motor_Speed_A = 0;
  Motor_Speed_B = 0;

#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer1_A0_ISR(void)
  //Upkeep Time
  if (Motor_isr_cnt == 512)
    Motor_isr_cnt = 1;

  //Motor_A PWM
  if (abs(Motor_Speed_A) >= Motor_isr_cnt)
    if (Motor_Speed_A > 0)
      Motor_OUT |= Motor_A1;
      Motor_OUT &= ~(Motor_A2);
      Motor_OUT |= Motor_A2;
      Motor_OUT &= ~(Motor_A1);
    Motor_OUT &= ~(Motor_A1 + Motor_A2);

  //Motor_B PWM
  if (abs(Motor_Speed_B) >= Motor_isr_cnt)
    if (Motor_Speed_B > 0)
      Motor_OUT |= Motor_B1;
      Motor_OUT &= ~(Motor_B2);
      Motor_OUT |= Motor_B2;
      Motor_OUT &= ~(Motor_B1);
    Motor_OUT &= ~(Motor_B1 + Motor_B2);

  P1OUT ^= 0x40;    // Toggle P1.0
  TA1CCR0 += 500;  //Add offset to CCR0

MSP-430 LaunchPad UART and FIFO

This code is currently for the MSP430G2553 on the Ti LaunchPad. The MSP430G2553 has a built in USCI that can be used for UART. Unlike lower end models of the value line you do not have to make a slow software UART. I looked online and did not see any UART libraries that where nice to work with without hacking them apart. I did not see any FIFO implementations at all either. They generally waited on the UART to finish its business before sending more data.

The advantage of the FIFO allows the MSP430 to push that data into the FIFO as fast as it can and let the hardware UART do the rest of the job. This frees up the CPU to do allot more stuff. The only bad thing is that if the FIFO gets full you start loosing data. The code has a global flag to let the main code know that the FIFOs are full.

The Receive (RX) portions of the code also have a global mailbox flag to notify the rest of the code that the UART received something. This would be useful if you need to send commands to a robot or device.

There are 4 different flavors of the code.

1. RX TX
2. RX TX with a FIFO
3. TX only
4. TX only with a FIFO

The code without the FIFOs waits on the UART during the transmission but uses far less memory then the FIFO code. You have to sacrifice speed or memory on this one. The TX only code strips out the RX portions if you just want to have the msp-430 print to a terminal. This is useful for debugging purposes.

If you are going to use this on the MSP-430 LaunchPad then you will need to cross the RX and TX lines. This pdf I found on the internet explains on page 3 (step 6) what I am talking about.

Project File

Project File

Project File

Project File

FIFO Code (CCS V5)
Project File

MSP-430: IEEE CS Competition – Knock Knock Security System

Matt and I won a TI sponsored Launchpad programming contest that was held by the IEEE CS here at The University of Texas at Austin.

Here is the link for the details. In case the IEEE site goes down here is a screen cap of the page.

My partner Matt on left. Parker (me) grinning like a fool on the right. I did the majority of the programming and design work where Matt debugged my code as I wrote it saving allot of time.

The idea was to create a simple secret knock security system that could record a knock “pattern” and then only unlock a door when the pattern was repeated. Only three hours where given for the competition and we where the only ones to finish everything in that time slot. They extended the contest another hour to permit more teams to finish. More details about the contest can be had by downloading the packet they gave us.



The code is a bit rough around the edges and the bulk of the program happens in the timer interrupt (which is a no no) but for only 3 hours to solve, design, program, and debug a solution; sloppy code is a bit expected.

Points where awarded based on a few areas.

Your solution will be graded and scored on the following categorizes 
1)  Time it took for your team to create the solution and produce a working 
prototype to the Company.  
a.  Every 1 min is -1 pts 
b.  Ex: if you finish in 1:30 in you will get -90 points 
2) Working prototype: after you submit your prototype to the company, 
Quality Control will take it into their lab and run test on your system. Their 
test will not exceed the specified requirements and each test you pass you 
will get +10 points to your score. (MAX 80pts) 
3)  Documentation: As in any real project you should keep a good record on 
how you came up with your idea for your solution. This is to keep the 
company safe from legal problems, have a record of our intellectual 
a.  Submit your code   
b.  Submit any notes 
c.  Document any resources for the internet 
d.  Instruction Manual  
Our legal team at the company will take a look over and award points 
(MAX 10pts) 
4)  Creativeness of the solution: When you submit your solution to the 
company, your manager will take a peek at your solution. If you solved it in 
a new and ‘creative’ way, this many include additional functionality, more 
efficient algorithms, or intuitive (easy to use) interface. (MAX 30pts) 
5)  Cost: The Company does have a parts store. You will be able to buy extra 
parts such as button kits and if you burn out your chip you can buy a new 
If you get stuck we do have an internal consulting group which will help you but 
for a cost of 2pts per 1 min. This is not for questions about the contest or 
questions about the problem; this is for help solving the problem.

We scored 65 points where the nearest team behind us only scored 22 points. We dominated the competition. The judges loved the simple interface and the admin password setup. The code was fairly changeable so you can adjust the precision of the knock (humans are not robots) and how long the passwords are. Teams that did finish had no where near the feature set our solution had.

This contest made me wonder if GPA should even be a consideration for companies like Texas Instruments in hiring. I have a 2.8 GPA and have a hard time realizing that I actually had the lowest GPA out of the entire contestants and I completely schooled everyone that had 4.0 GPAs. I think this goes to show that theoretical knowledge != practical knowledge. Hey maybe since Texas Instruments sponsored this event I could possibly get a career out of it?

To anyone out there hiring an embedded systems engineer and want a motivated worker that will tackle projects with all of his might? Hire me!

MSP-430: Servo and Accel demo Update

Awhile ago I uploaded a demo of the Fraunch Board that used the Accelerometer and outputted it to a set of servos. I made a video demonstrating it but I forgot to upload it.

The MSP-EXP430FR5739 board has a built in AXL335 which is a 3-axis accelerometer. It is hard wired to ports P3.0, P3.1, and P3.2. There was no demo code how to get the ADC10 to read those values.

I looked into the sequential sampling that the MSP430 supports which is where ADC10INCHx is set to the last ADC port and will go all the way down to ADC10INCH0 in sequence. This is a problem on the Fraunch Pad as the AXL335 outputs are wired to P3.0 – P3.2 which means when you set ADC10INCHx to ADC10INCH14 (P3.2) it will process more then half the pins as analog inputs!

Solution was to change the ADC10INCHx between sampling so the ADC process became round robin style. Here is the working code to sample all the axises on the Fraunch board. Also included is the “zero” calibration routines.

This code also contains a twin servo routine. The servos are connected to P1.4 and P1.5. When the X-axis moves the servo on P1.4 moves and when the Y-axis moves the servo on P1.5.