Quantcast
Channel: MSP430 Technical Forums
Viewing all 2077 articles
Browse latest View live

PWM using timer output toggle mode

$
0
0
The usual way to generate PWM with the MSP430 is to set the timer to up mode, CCR0 to the PWM period, and then use CCR1 and up in reset/set mode to set the PWM pulse width. This provides a precise hardware driven PWM with minimal CPU overhead. The only ISR required is the CCR0 interrupt so new PWM values can be updated without creating glitches.

It is possible to use CCR0 to do PWM in addition to CCR1 and up by using continuous mode and output compare toggle mode. This requires an ISR for each CCR used. It is glitch free and allows different PWM periods for each output if desired.

The basic ISR is simple:
__interrupt void isr_ccr0(void)                 // - ISR for CCR0
{                                               //
    static unsigned s = 0;                      // State
    static unsigned d;                          // On duration
                                                //
    TA1CCR0 += (s++ & 1) ? (pwm_period[0] - d) : (d = pwm_on[0]);
}                                               //
Each time the ISR occurs, the output time is advanced in to the future. The lsb of a state variable toggles between adding the on duration or off duration to the previous time. When the lsb is 0, then the on duration is used, and also saved for later. When the lsb is 1, then the off duration is calculated from the saved on duration and the PWM period. Toggling of the output pin is automatic because the CCR output mode is set to toggle.
 

Complete code for 3 PWM outputs using CCR0, CCR1, and CCR2 of Timer 1
 
#include <msp430.h>

static unsigned pwm_on[3];                      // PWM on duration
static unsigned pwm_period[3];                  // Total PWM period - on duration + off duration
                                                //
#pragma vector = TIMER1_A0_VECTOR               // - ISR for CCR0
__interrupt void isr_ccr0(void)                 //
{                                               //
    static unsigned s = 0;                      // State
    static unsigned d;                          // On duration
                                                //
    TA1CCR0 += (s++ & 1) ? (pwm_period[0] - d) : (d = pwm_on[0]);
}                                               //
                                                //
#pragma vector = TIMER1_A1_VECTOR               // - ISR for CCR1, CCR2
__interrupt void isr_ccr12(void)                //
{                                               //
    static unsigned s1 = 0;                     // State
    static unsigned d1;                         // On duration
    static unsigned s2 = 0;                     //
    static unsigned d2;                         //
                                                //
    switch(TA1IV) {                             //
        case 0x02:                              // - CCR1
            TA1CCR1 += (s1++ & 1) ? (pwm_period[1] - d1) : (d1 = pwm_on[1]);
            break;                              //
        case 0x04:                              // - CCR2
            TA1CCR2 += (s2++ & 1) ? (pwm_period[2] - d2) : (d2 = pwm_on[2]);
            break;                              //
    }                                           //
}                                               //
                                                //
static void pwm_init(void)                      //
{                                               //
    P2DIR |= (BIT0 | BIT2 | BIT4);              // PWM outputs on P2.0, P2.2, P2.4
    P2SEL |= (BIT0 | BIT2 | BIT4);              // Enable timer compare outputs
    P2SEL2 &= ~(BIT0 | BIT2 | BIT4);            //
                                                //
    TA1CTL = TASSEL_2 | ID_3 | MC_2;            // Setup timer 1 for SMCLK / 8, continuous mode
                                                //
    TA1CCTL0 = TA1CCTL1 = TA1CCTL2 = OUTMOD_4 | CCIE; // Set timer output to toggle mode, enable interrupt
    TA1CCR0 = TA1CCR1 = TA1CCR2 = TA1R + 1000;  // Set initial interrupt time
}                                               //
                                                //
int main(void)                                  //
{                                               //
    WDTCTL = WDTPW | WDTHOLD;                   //
                                                //
    DCOCTL = 0;                                 // Run DCO at 8 MHz
    BCSCTL1 = CALBC1_8MHZ;                      //
    DCOCTL  = CALDCO_8MHZ;                      //
                                                //
    pwm_init();                                 // Initialize PWM
                                                //
                                                // Setup PWM period
    pwm_period[0] = pwm_period[1] = pwm_period[2] = 20000;
    pwm_on[0] = 1000;                           // Setup servo times
    pwm_on[1] = 1500;                           //
    pwm_on[2] = 2000;                           //
                                                //
    _enable_interrupts();                       // Enable all interrupts
                                                //
    for(;;) {                                   //
    }                                           //
                                                //
    return 0;                                   //
}                                               //

interfacing msp430g2 launchpad with multiplexed common anode seven segment display using energia

$
0
0

i would like to interface a multiplexed 4-digit-7-segment common anode display with msp430 g2 launchpad and display 4 numbers simultaneously.here the 4 digits are controlled by 4 BC547 transistors.

here the segments a,b,c,d,e,f,g,dp of the display are connected to port1 pins respectively and the transistors bases are connected to port2 pins.

i tried with single 7-segment display and it is working .when i extended to 4-digits i could not get the display.

could you please give me the code to display 4 numbers simultaneously.

thank you...

OSX Forcibly Restarts During Upload (Randomly)

$
0
0

Hey All - pretty new here to Energia, but have run across an issue that I can't seem to troubleshoot.

 

I'm running the following:

  • OSX 10.9.4 with Energia 0101E0012
  • Stellaris Launchpad LM4F120H5QR

The first upload always works fine, but following uploads to the device will randomly restart OSX. No warning, just a momentary mouse freeze, black screen and system restart when the progress bar gets to 50%.

 

Serial Port is dev/tty.usbmodem0E102F71 (only option available). Bluetooth is turned off.

 

This has occurred with all different types of 'code' as well - from built in examples to things I wrote myself.

 

Thanks in advance for any advice any of you may have!

 

 

 

 

analogWrite bug with msp430g2553 in energia

$
0
0

Hello,

 

When I execute the code below, and check P2_1 and P2_2 on my scope, I see that both pins are 128, i.e, whichever analogWrite statement takes place the last, it overrides the one before. I am using launchpad v1.4

 

If I write 0 to one of the pins, it will work correctly.

 

void setup()
{
 
   pinMode(P2_1, OUTPUT); 
   pinMode(P2_2, OUTPUT);   
   
   analogWrite(P2_1, 32);
   analogWrite(P2_2, 128);  
   
}
 
unsigned long time;
 
void loop()
{
  time = millis();
  delay(100);  
}

Simple Web Server: MSP430F5529LP with CC3000 Boost

$
0
0

Hi,

I am following this video to create a simple web server on MSP430F5529LP with CC3000 Boost, with Energia version 11.

 

The output of the serial monitor is attached. 

 

When I access the server IP (http://192.128.1.68/) from the browser, the page doesn't load. 

 

The boost IP doesn't seem legit. Look at the attached output and you will see the gateway is 192.128.1.254 but actually the gateway is 192.168.1.254 (got from cmd prompt ipconfig result).

 

Similarly, the boost IP should be 192.168.1.68, not 192.128.1.68. Tried both in the browser but none works.

 

It seems like my CC3000 Boost is not properly configured. 

 

Can anyone please suggest?

 

energia-server.png

Getting started: MSP430F5529LP launchpad & CC3000 Boosterpack

$
0
0

Hi,

I am having difficulty configuring CC3000 boosterpack with MSP430F5529LP. I did this successfully with MSP430G2 board earlier following the tutorial. So wondering if there is any such tutorial for MSP430F5529LP.

I followed below steps, but I don't see the board version number or CC3000 IP address in the hyperterminal. Can anyone please help?

 

1. Take the out of the box MSP430F5529LP launchpad board (no jumper changes).

2. Get the patch programmer V1.11 loaded for MSP430F5529LP from here

3. Get the CC3000 SDK V1.12 (latest) to get Basic WiFi Application for MSP430F5529. Modify that to reflect MSP430F5529LP changes as mentioned here. And flash it to the MSP430F5529LP evaluation board. 

4. Did the hyperterminal setup according to the example

5. Pressed reset button S3 (not S1 as in MSP430G2). 

Nothing shows up in the hyper terminal. If everything were correct, it is supposed to show the version number. I also tried typing '01' in the terminal, but it doesn't lead me towards smartconfig & can't get the IP address.

 

Can anyone please help?

decode the LEGO power functions protocol

$
0
0
LEGO power functions is a system of electronic components, motors,
lights, remote controls to power various LEGO models.
The remote control works with IR, but works surprisingly well even
when there is no direct visual contact. The handheld unit is small,
has two joystick-buttons, and allows 4 different channels to be selected.
Much cooler than a TV remote!
 
Interesting for hacking, LEGO has made the protocol open source, so 
anybody can play with it, as long as not making it commercial.
The protocol can be found here:
 
So I decoded the powerfuctions protocol with the launchpad/energia:
 
Apart from the lauchpad, I only needed a IR receiver. I tested with 
a Vishay TSOP38338, other sensors might work as well.
 
The processor sleeps when doing nothing, wake up only when there is 
something to do. It is low power, but not ultra low, since the IR
receiver needs around 0.4mA.
 
//example program für Lego Power Functions Remote
//2014-07-04
//
//tested with Energia, Launchpad, MSP430G2553, 16Mhz
//IR receiver Vishay TSOP38338:
//Pin1 to Pin 3  on Launchpad Signal
//Pin2 to Pin 20 on Launchpad GND
//Pin3 to Pin 1  on Launchpad +3.3V

volatile byte out;

void setup() {   
  pinMode(2, OUTPUT);        //red led 
  blinky (3);                //just checking
  
  pinMode(3, INPUT);         //remote sensor
  attachInterrupt(3, legosig, FALLING);
}

void loop(){
  
  // this if for channel 1, 
  // add 16 for channel 2
  // add 32 for channel 3
  // add 48 for channel 4
  // see page 7 on Lego spec: "Combo direct Mode"

  LPM3;        
  if (out){
    if (out==1 ) blinky(1);       //left up
    if (out==2 ) blinky(2);       //left down
    if (out==4 ) blinky(3);       //right up
    if (out==8 ) blinky(4);       //right down
    if (out==5 ) blinky(5);       //both up
    if (out==10) blinky(6);       //both down
    if (out==9 ) blinky(7);       //left up right down
    if (out==6 ) blinky(8);       //left down right up
    out=0;
  }  
}

void blinky(byte a){
  for(int i=0;i<a;i++){
    digitalWrite(2,1);
    delay(200);
    digitalWrite(2,0);
    delay(200);
  }
}



void legosig(){      //interrupt service routine reads powerfunctions protocol
                     //global variable "out" contains remote code when succesful, 
                     //otherwise 0
  int p,q;    
  word telegram;
  
  if (!out){
    telegram = 0;
    if (checkonebit()==0)       return;        //check for start bit
    for (q = 0; q < 16; q++){             //16 check 16 data bits
      if ((p=checkonebit())==0) return;
      telegram<<=1;if(p>18) telegram|=1;  //18:threshold, 421us<(18*25us+overhead)<711us
    }
    out=lowByte(telegram)^highByte(telegram);                 //xor for parity check   
    if(((out/16^out)&B00001111)!=15) out=0;                   //do the parity check
    out=lowByte(telegram)/16+(highByte(telegram)&B00110000);  //reduce to 6 bit 
  }
}

int checkonebit(){                //check one bit of remote protocol
  int loops=0;                    //returns lenght when succesful / 0 when too long
  while (!(P1IN & B00000010)) { 
    delayMicroseconds(25); 
    loops++; if (loops>64)  return 0;
  }
  loops=0; 
  while   (P1IN & B00000010)  { 
    delayMicroseconds(25); 
    loops++; if (loops>64)  return 0;
  }
  return loops;
}

 

Attached Thumbnails

  • pf_launchpad.jpg

I2C problem on a EK-TM4C1294XL connected Lauchpad

$
0
0

Hi,

 

I am trying to get i2c working on a EK-TM4C1294XL on energia. I am trying to user i2c channel 0. So they should be on pb2 and pb3. Thing is, I do not see any signal on sda or sck on the scope except for the pullup.

 

On the serial debug I see "Start" and "Loop" but "Loop2" never appears. As simpel as this program is, I am not getting it or something is wrong in the libraries.

 

Hope you can help,

 

cheers

 

John

#include <Wire.h>


void setup()
{
  Wire.setModule(0);
  Wire.begin();                // join i2c bus (address optional for master)
  Wire.setModule(0);
  Serial.begin(115200);          // start serial communication at 9600bps
  pinMode(PC_7, OUTPUT);
  pinMode(PB_2, INPUT_PULLUP);
  pinMode(PB_3, INPUT_PULLUP);
  Serial.println("Start");
}


void loop()
{
  Serial.println("Loop");
  
  Wire.beginTransmission(112); // transmit to device #112 (0x70)
  Wire.write(byte(0x00));      // sets register pointer to the command register (0x00)  
  Wire.write(byte(0x50));      // command sensor to measure in "inches" (0x50) 
  Wire.endTransmission();      // stop transmitting


  Serial.println("Loop2");


  digitalWrite(PC_7,HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);                  // wait a bit since people have to read the output :)
  digitalWrite(PC_7, LOW);    // turn the LED off by making the voltage LOW
  delay(250);                  // wait a bit since people have to read the output :)
}

Interrupt/Timer-driven function call approach

$
0
0
Hi there,
 
I've got something in my mind and need your advice :)
 
Let's imagine we've got 8 LED's and 8 buttons attached to MSP430. (actually, it doesn't matter how many LED's or buttons, or which port they're attached to)
We want a solution where a press of button one causes the first LED to light up for 1 second. After that time it'll switch off automatically.
For now that's nothing special. Now, let's say every LED lights up when the corresponding button has been pressed, but every one of these LEDs switches off
after a different amount of time. Moreover this whole mechanism should be independent of when which button has been pressed. It should be somehow interrupt-driven
and low power (using low power modes between the interrupts). OR: use the spare processing power inbetween status changes for something else.
 
My first thoughts were:
 
1. functions for each LED like "LED1_on();", "LED1_off();" etc.
2. a timer function like "millis();" in Arduino IDE
3. a array or struct that will hold a function pointer and the amount of time (millis) it should take until the function will be executed
4. a function to allocate i.e. "LED1_off();" to this array with the desired amount of time
5. timer-ISR checks every ms if there exists a function in the array that needs to be serviced and if so, executes it
 
my program could look something like this:
if(button1 pressed)
{
    LED1_on();
    AddTimerEvent(LED1_off, 500); // after 500ms it should "fire"
}
// move on doing other stuff
Adding this to a port ISR makes it completely independet of my main program code.
 
 
What do you think about my approach? Any advice? Does it already exist and I missed it?
 
 
Regards,
Leo
 
PS: I have to admit I never used function pointers. I only read "The C programming language" (Kernighan & Richie) some days ago and thought this would be a good match.

CCS + Grace + different build configurations

$
0
0

Hi there,

 

I'm in the process of developing some wireless system. I want to have more than one transmitter - behaving just a little bit different from each other.

Using Code Composer Studio I've discovered the ability to have different "build configurations". I made three different "main.c" files:

 

main_transmitter1.c

main_transmitter2.c

main_transmitter3.c

 

In build config 1 the second and third are excluded from build. In build config 2 the first and third are excluded... I think you get it.

 

Now my question:

 

To configure the peripherals I used Grace. Now I have a new idea where I need to change some of that Grace configuration in transmitter1 but not in the others.

 

Is there a possibility to make the Grace config dependent of the current build config?

 

Regards,

Leo

RC Car Made with LaunchPad Box

$
0
0
Since I am working on the Robotics Boosterpack with @HylianSavior and jwp071, I decided to make a prototype with the box LaunchPad comes with. I've used Firmata to send command to LaunchPad. Check out my other post here
 
 
A quick overview of what's inside.
Hardware
- G2 LaunchPad Box 
- Caps, wires, breadboard
 
Software
- Firmata over serial (enabled by Bluetooth)
- Energia Library on LP
- NodeJS on PC

MSP430F5529 & CC3000 mDNS with Energia

$
0
0

I am using MSP430F5529 LP with CC3000 boosterpack, Energia v12.  My goal is to make the F5529LP device mdns discoverable so the mDNS Watch app can find it.

 

Using example sketch 'SimpleWebServer',  I have added below line after the wireless connection is established. But the mDNS Watch app can't find the F5529 device (the app can find other BonJour devices)

 

 

void loop() {

.......
int ret=0;
ret=mdnsAdvertiser(1, "CC3000", 6);
Serial.println("MDNS Advertizing returning!");
Serial.println(ret);
delay(5000);

.......

}

 

I see that the mdnsAdvertiser call is returning -67 or 189. But it should return 1 or 0 right? Wondering if I am missing any driver/firmware setup. 

Also I tried Wireshark and used the display filter "dns and udp.port eq 5353" but Wireshark is not showing anything with the filter. 

 

Please suggest. 

Super newbie with an MSP430G2553 - trying to flash from ARM

$
0
0

Hey guys,

Let me start out by saying thanks for reading this.  I am a *super* newbie in this stuff - hardware is decidedly not my area of expertise ;)

 

I've got an AM3358 ARM device, connected up to an MSP430G2553.  The task that I've been given is to set it up so that we can re-flash the BSL on the MSP from said ARM device.  They are connected to each other using the UART3 pins.

 

Using mspdebug and aiming at my uart3 device, using tilib, flash-bsl, and uif-bsl, I wind up with assorted errors (timeouts, errors initializing the device, or Bootloader active (error = 56))

 

I am assuming that these errors are indicative of the MSP not being in BSL mode - does that seem reasonable?  And that my problem is *probably* that however we've got the chip wired up is such where the reset/test pins arent being appropriately tagged to switch modes?

 

Are there any specific tests/commands I can use to try to verify this?

 

Sorry for all the questions, just super new at this stuff :D

 

Thanks again!

Wolverine Launchpad update for early purchasers

$
0
0
Just got this from TI. Nice to see they're looking after people who are keen on their kits.

Dear valued MSP430™ MCU customer, 

Thank you for your purchase of the MSP430FR5969 LaunchPad Development Kit (MSP-EXP430FR5969). As you may know, on June 24th, 2014, Texas Instruments announced an updated version of the MSP430FR5969 LaunchPad Kit populated with the production-ready silicon. The MSP430FR5969 MCU features several improvements, including EnergyTrace++ technology support. 

As a valued customer, your satisfaction is very important to us. Because you purchased an MSP430FR5969 LaunchPad prior to June 24, 2014, Texas Instruments would like to offer you a FREE MSP430FR5969 LaunchPad replacement. Stay tuned for a follow-up email within 90 days containing the coupon code to redeem your free kit.

Wolverine Launchpad update for early purchasers

$
0
0
Just got this from TI. Nice to see they're looking after people who are keen on their kits.

Dear valued MSP430™ MCU customer, 

Thank you for your purchase of the MSP430FR5969 LaunchPad Development Kit (MSP-EXP430FR5969). As you may know, on June 24th, 2014, Texas Instruments announced an updated version of the MSP430FR5969 LaunchPad Kit populated with the production-ready silicon. The MSP430FR5969 MCU features several improvements, including EnergyTrace++ technology support. 

As a valued customer, your satisfaction is very important to us. Because you purchased an MSP430FR5969 LaunchPad prior to June 24, 2014, Texas Instruments would like to offer you a FREE MSP430FR5969 LaunchPad replacement. Stay tuned for a follow-up email within 90 days containing the coupon code to redeem your free kit.


I2C hangs at Wire.endtransmission() after running for a while

$
0
0

Hello,

 

I just received a TM4C1294XL connected launchpad. I'm trying to get it working with L3G4200D gyroscope  (it's a module from Parallax with pull-ups). The program runs as expected for a while and then freezes and I have to long press the reset button to get it working again. By importing the Energia sketch into CCSv6, I was able to find the program hangs at the Wire.endtrsmission(), in particular at line

 

  //Wait for any previous transaction to complete
  while(ROM_I2CMasterBusBusy(MASTER_BASE));
 
in the Wire library. I tried with another sensor and experience the same problem. Could somebody help me out?
 
The related code is attached below (sorry for not knowing how to format the code in the post):
 
void setup()
{
// Start the Ethernet and UDP
Ethernet.begin(mac,ip);
udp.begin(localPort);
 
// Start I2C
Wire.setModule(0);
Wire.begin();
// Initilize the L3G4200D gyro
gyro.init();
}

 

void loop()
{
currentTime = millis();
interval = currentTime - lastTime;
if (currentTime - lastTime >= 100)
{
// Serial.println(interval);
lastTime = currentTime;
// Get sensor data
gyro.getRawData();
 
compseTxPacket();
 
IPAddress remoteIP(192,168,1,10);
uint16_t remoteLocalPort = 13000;
udp.beginPacket(remoteIP, remoteLocalPort);
udp.write(txPacketBuffer, TX_PACKET_SIZE);
udp.endPacket();
 
}
}

 

void L3G4200D::getRawData()
{
while((i2cReadReg(L3G4200D_REGISTER_STATUS_REG) & 0x08) == 0);
 
Wire.beginTransmission(L3G4200D_ADDRESS);
Wire.write(L3G4200D_REGISTER_OUT_X_INC); // first register to start read from
Wire.endTransmission();
Wire.requestFrom(L3G4200D_ADDRESS, 6);
while(Wire.available() < 6);
 
byte raw_low;
byte raw_high;
raw_low = Wire.read();
raw_high = Wire.read();
data.xRawDPS = (raw_high << 8) | raw_low;
raw_low = Wire.read();
raw_high = Wire.read();
data.yRawDPS = (raw_high << 8) | raw_low;
raw_low = Wire.read();
raw_high = Wire.read();
data.zRawDPS = (raw_high << 8) | raw_low;
}

Import Energia sketches into Code Composer Studio v6 // enabling true debugging on a sketch

$
0
0

Hi 43oh folks!

 

I wrote a quick blog post & tutorial on the www.energia.nu website. I wanted to walk through the process of setting up Code Composer Studio v6 to enable Energia sketch imports. This is a cool new feature that takes full advantage of the on-board hardware debugger that is available on our LaunchPad kits & allows developers to go beyond Serial.print().

 

This provides a nice migration path from Energia to CCS. Energia is great for rapid prototyping, but there are times when a true debugger could be helpful. With CCSv6, we can now import Energia sketches & get full debug features such as:

- Hardware breakpoints

- Watching variables

- Stepping through code line-by-line

- More!

 

You can see my blog post & tutorial @ http://energia.nu/go-beyond-serial-print-put-the-launchpads-on-board-debugger-to-work-import-energia-sketches-into-ccsv6/

 

Thanks!
Adrian

AccelStepper library in Energia

$
0
0

Hi,

 

I'm using MSP430F5529 launchpad and I tried hard to adapt AccelStepper library for MSP430 platform, but I cannot make it.

 

Does anyone succeded to make it work?

 

Thanks,

Andy

UECIDE coming out of beta soon

$
0
0

Hi,

 

I have been working for the past few years on a project called UECIDE.  It's a new IDE that is intended to be a single environment for programming a whole gamut of different development boards.

 

It was originally based on MPIDE, which was originally itself based on Arduino 0023, but there's only about 100 lines of the original code left there now.  Everything else has been completely re-written.

 

Anyway, it has for some time now had Launchpad and Stellaris supoort in it - at least it's meant to.  However, I am only one man, and I only have an original Launchpad and a Stellaris LM4F board - none of the other boards / chips to play with.

 

So, I was looking for people willing to have a play (with the latest beta version) and see what could do with improving / tweaking / rewriting to better support these boards.

 

To whet your appetite, this is what the latest beta looks like:

 

BasicWindow.png

 

The download is here: http://uecide.org/download with the beta version listed at the bottom of the page.

 

So if you could give it a bit of a hammer and let me know what you think of it that'd be fantastic.

 

By the way, the MSP430 / LM4F support is taken direct from your github repository by a set of build scripts, so should be as up to date as I remember to run the scripts ;)  The scripts are here if you want to see them: https://github.com/UECIDE/launchpad

We need more info! Timers used by what

$
0
0

Well hello guys, i have more complaints!!!, kiding, it just seems i only apear here to complain or want to change sometigh

This is a problem i had specificaly with Tiva board

 

Well i went and visit my old high school club and they had a problem. I found out was confliting timer usage betwen servo, PWM and milis(). 

I had to check the source files and found out they were using the same timer for the servo and PWM.

 

Since servo and milis timer (wich milis shouldn't even be a general timer in the Tiva) can't be changed unless it is in the source files i think there should be more information available about this. Like saying wich timers are used for what, wich one is for pulsein, milis, servo. And wich pins should not be used for PWM when using those fuctions).

I sugest servo because it's a library that comes with Energia by default.

 

milis() usse TIMER5 

pulsein() it uses micros() so TIMER5

servo TIMER2

 

and any others that Energia functions use or default libraries

 

This would probably help alot of people so they don't have to search the source files

Viewing all 2077 articles
Browse latest View live