Category Archives: Software

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



isr_motor_pwm.c
isr_motor_pwm.h
Project File Ver1.0


/*
 *isr_motor_pwm.c
 *Version: 1.0
 *Parker Dillmann
 *The Longhorn Engineer (c) 2013 
 *www.longhornengineer.com
 *
 *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;

  return;
}

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

void stop_motors(void)
{
  Motor_Speed_A = 0;
  Motor_Speed_B = 0;
  return;
}

#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer1_A0_ISR(void)
{
  //Upkeep Time
  Motor_isr_cnt++;
  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);
    }
    else
    {
      Motor_OUT |= Motor_A2;
      Motor_OUT &= ~(Motor_A1);
    }
  }
  else
  {
    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);
    }
    else
    {
      Motor_OUT |= Motor_B2;
      Motor_OUT &= ~(Motor_B1);
    }
  }
  else
  {
    Motor_OUT &= ~(Motor_B1 + Motor_B2);
  }

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

IEE Flip VFD Working! Test code coming soon.

Today I wrote some code to get the IEE Flip VFD working. It has a fairly simple protocol and only took a bit of tweaking to get it working. I wrote the demo code for my Prop Dev Stick and will be uploading the SPIN code later once I finish the feature set.

After this I will write some C code for the MSP430 LaunchPad and get that working. The screen supports a serial input mode which saves 8 I/O pins but requires more timing. I will try to get that working as well.

IEE FLIP Alphanumeric Display Works!

I picked up some of these really neat VFD alphanumeric displays at a surplus shop while at Maker Faire. After acquiring the datasheet from the manufacture, I decided to test them with the built in test mode. I have already started writing the code to run the display and will be posting the code and datasheet when it is done.

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.

RX TX UART Code (CCS V5)
Project File
main.c
uart.c
uart.h

RX TX UART FIFO Code (CCS V5)
Project File
main.c
uart_fifo.c
uart_fifo.h

TX UART Code (CCS V5)
Project File
main.c
uart_tx.c
uart_tx.h

TX UART FIFO Code (CCS V5)
Project File
main.c
uart_fifo_tx.c
uart_fifo_tx.h

FIFO Code (CCS V5)
Project File
fifo_.c
fifo.h

LEDDMD 128×32 Complete

So I finally finished the prototype of the 128 x 32 Light Emitting Diode Dot Matrix Display V1.0 (LEDDMD). The protocol to write to the display is almost exactly like a shift register. There is a clock, latch, and data lines. It works in either 1 bit mode or 8 bit mode data line modes.

In 1 bit mode there is only 1 data line and in 8 bit mode this is 8 data lines. 8 bit mode enables you to clock in an entire byte of data at a time speeding up the transfer process by a factor of 8. In either mode you can do animations smoothly. All processing of the data is done on the microcontroller. The Display stores the data and takes care of running the display.

The bulk of the hardware is in the FPGA. I am using a Cyclone II EP2C8Q208C8N FPGA breakout board. There are some darlington transistor arrays that sink the current from a single row. To expand the I/O of the FPGA some decoders are used.

Here are the links to all the code:
FPGA:
Main Routine
Memory

Propeller:
Transmission Protocol and Test

LM3S1968: 74HCT595 Shift Registers

For one of my up coming Labs for EE445L I am going to need to expand the I/O of the LM3S1968. I am using the 74HCT595 much like on my pinball machine. One 74HCT595 allows you to turn 3 output pins into 8 output pins. They can be daisy chained so you can have any multiple of 8 output pins for those 3 original output pins.

In this demo I have 3 74HCT595 chips wired up. Instead of using the SSIO ports on the LM3S1968 I bit banged the port. SSIO is built in hardware that does serial communication. I decided to not use is for the 74HCT595’s because I am going to use it in controlling a DAC.

The code is fairly module and easy to change to different ports and pins.

Link to the code.