PWM On The Stellaris Launchpad

[Joonas] has been following TI’s ‘getting started’ tutorials for their new Stellaris Launchpad. Everything had been going swimmingly until [Joonas] reached the fourth tutorial on interrupts. To the ire of LEDs the world over, implementing PWM on the new Stellaris Launchpad is a somewhat difficult task. After banging his head against the documentation for hours, [Joonas] finally cracked his PWM problem and decided to share his discoveries with the world.

The Stellaris has a PWM mode for its six hardware timers, but unfortunately there are no PWM units on the chip. Solving this problem required making two 16-bit timers out of a single 32-bit one. This allowed [Joonas] to specify a ‘load’ and ‘match’ value.

After coding this up, [Joonas] discovered the PWM timer only works on two of the Launchpad’s pins. Hours of Googling later, he had real PWM on his Stellaris Launchpad.

Given the amount of time [Joonas] spent on this problem, we’re glad to help all the other frustrated Stellaris tinkerers out there by sharing this.

20 thoughts on “PWM On The Stellaris Launchpad

  1. Cool, this got featured! To clarify, each timer unit (and there are six of them) with PWM has two pins it can be connected to, and it needs to be configured before PWM starts working.

  2. Interesting. I’ve been doing some similar stuff using timers to control a stepper motor driver (so interested in period but with a fixed pulse). I didn’t have any problems using interrupts to let me manually toggle the pins but this does look more efficient. I might try this technique when I get a chance.

    As far as the “magic incantations” to map pin functionality goes the PinMux utility makes this really easy and lets you check for clashes when you’re trying to do more than one thing with a pin.
    http://www.ti.com/tool/lm4f_pinmux

  3. I stopped using the MSP430 when I got to PWM’s. Seems these things shouldn’t be so difficult especially when they are targeted towards hobbyists. Guess that’s why avr and pic are king.

    1. Stellaris has an explicit PWM mode. It’s in the datasheet — I don’t know how Joonas missed it. MSP430 basically has one too — there’s a section in the users’ guide.

  4. I’m a little rusty, but aren’t AVRs the same? The PWM ‘hardware’ is just outputs on the timers.
    Still, nice writeup. Will be useful when I get around to playing with these launchpads.

  5. Just to make things clear.
    I work with CortexM3 Stellaris parts. If there it’s not PWM PERIPHERAL doesn’t mean that there is no hardware PWM support in TIMER PERIPHERALS. You can get running hardware PWM with 2 channels per timer if you “split” each timer to 16bit.
    Some motor-enabled Stellaris parts have extra dedicated peripheral only for PWM with much more options but.
    It’s bit harder to understand how to configure Stellaris timers to do PWM, specialy to “split” 32b timer to two 16 bits :)

    Still waiting for my Stellaris M4. I have no idea what I will do with it because I have other Stellaris M3 kits and no plans to take advantage of FPU on the M4 :(

    1. I generally find TI’s documentation to be quite good. A huge step above that of STM or Atmel (shudder!).

      However in general any documentation for a MCU can be quite cryptic, which is why internet forums exist.

      1. I happen to like AVR documentation (with the exception of PWM operation setup bits, what a coincidence :D ) but I did not see the newer datasheets. Seeing recent developments at Atmel, I don’t find it difficult to believe that they are horrendous.

        With MSP430 my grumble is how they tend to describe the generic architecture and let you discover yourself, by finding and searching at least 3 different non-cross-referenced papers, how the things are really done in your particular device. This drives me crazy. Especially when I’m to discover that the feature that I needed the most turns out to be not in this particular device that I have handy. That’s just plain evil.

    2. I honestly can’t complain, as this complicated process of figuring stuff out is what leads to better thinking and researching, it’s hard but hell I only paid $5 for this with a usb micro cable and actually free programming software lol

  6. TI is a multinational company with branches all over the world. The quality of the documentation has a lot to do with the branch. TI bought Chipcon in 2006, I think. It took years for the documentation to get up to snuff — it is still nothing compared to the docs that come out of the MSP430 unit. TI bought Luminary in 2009, and that’s where they got Stellaris. Given that Stellaris has been used quite a bit for motor controllers, I’m guessing the problem is actually that the PWM features are way more sophisticated that what you are used to with the AVR/PIC, and therefore a bit challenging to take-up.

    1. TI gave an estimated shipping date with every order, how bout not bitching and just logging onto TI’s website and look at the estimated shipping date instead of being a twat. They’ve shipped mine 8 days early!

      If the estimated shipping date has passed and it still hasn’t shipped how about emailing TI and asking them about it? Instead of coming onto a site not affiliated with TI in any way and bitching.

      Maybe your order didn’t go through because you weren’t aware of the fact you were supposed to hit the order button.

  7. I had seen this a few weeks ago when i was trying to make software PWM for my measly MSP430g2553 equipped launchpad had hoped for some parallels and insight from his experience didn’t happen but i did finally get my software pwm working.
    Though my frequency counter isn’t the most precise or long ranged I was able to verify that it runs quite well 500Hz all the way up to 32Khz with 6 outputs of Port2.. which is beyond my requirements anyway.
    I got away with it by using timer 1 A0 and one taiv output of timer1 A1
    by sorting an array of timing values (dutycycle)least to greatest ahead of time and serving up the current element till A0 resets to provide the frequency.

    Do all the hard stuff outside of the timer loop otherwise you will never make it through all the pins before A0 resets

    The lack of REAL Multiplication and division was a real bummer as integer division is almost worthless and it really sucks having to do long division in a micro and honestly that was one of the hardest parts of this whole endevor allowing percentages to define duty cycles. the other thing i did was calibrate the frequency with the external xtal and now its pretty stable works well still though even though it was under $5 there were sure a lot of gotchas and it took me a week to get to where i figured i would have been it a day I suppose at least I know for next time

  8. TI provides an example of driving each element of the RGB with an indepedent timer PWM. The qs-rgb example that ships programmed into the board uses the file in StellarisWare\boards\ek-lm4f120xl\ named rgb.c. The rgb.c file configures 2 timers to generate 3 outputs one for each color.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.