Stellaris Launchpad PWM Tutorial

After receiving my Stellaris Launchpad, I decided to browse the little amount of tutorials there was available on the subject. I was really impressed by the Getting Started hands-on workshop offered in TI’s wiki. After watching the first few tutorials, I had a somewhat firmer grasp on how this little puppy was supposed to be programmed, and the capabilities of the Code Composer Studio IDE.

I got as far as Chapter 4: Interrupts until I hit the first snag: After the Lab4 assignment, the friendly instructor told that as a home assignment, one could try out the PWM (pulse-width modulation) capabilities of the Launchpad before proceeding further. Little did I know how many hours I would spend on that topic! After a solid 8 hours of banging my head against the documentation, Launchpad and CCS (which is prone to hanging at least on my PC), I finally got it working, and decided this would be a great place for a tutorial.

Rule 1 of PWM on Launchpad: There are no PWM units

The initial four hours of my PWM efforts were spent on the StellarisWare Driverlib documentation concerning PWM. In case you haven’t yet watched the tutorials, the Driverlib is essentially a bundle of code that takes away the burden of writing into dozens of control registers, and instead presents the programmer with a couple of hundred API calls to enable a higher-level approach.

It wasn’t until the third hour of googling around that I discovered, that while the timer functionality of the Launchpad includes a PWM mode, there are no actual PWM units on board! So if you’re looking at the PWM functions in Chapter 21 of Stellaris Peripheral Driver Library User’s Guide – stop it and get back to the Chapter 27: Timer functions.

Step 1: Setting up the timer0 PWM mode

So the only PWM functionality the Launchpad supports is the “PWM mode” of the six hardware timers. Thankfully, that’s already quite nice (if I ever find out how to use interrupts with PWM, even better). So unless you already know how the timer system works, now’s a good time to watch the Chapter 4 video which explains it quite nicely. Based on that tutorial, we learn that the following piece of code should initialize the timer for us:


ulPeriod = (SysCtlClockGet() / 10) / 2;
TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod - 1);

TimerEnable(TIMER0_BASE, TIMER_A);

Continue reading Stellaris Launchpad PWM Tutorial

TI Stellaris Launchpad Test Run

My local electronics store Partco overdid themselves again. Believe it or not, while most of the people in US are still waiting their Stellaris Launchpads, this small Finnish electronics outlet had several in stock. Thanks to two generous donators of $11 and $1.5 respectively, I also had the financial leverage to acquire one. :)

The board came in a decent black cardboard box with a small quickstart booklet – see Hack-a-Day hands on coverage for details on the package. Even the board itself contains the URL where you can get the software package. I proceeded to download the 1.3 GB Code Composer Studio + StellarisWare package. It took 30 minutes to download, thanks to less-than-impressive transfer speeds from TI, and another 1 hour to install.

The guys at TI were generous enough to include working quickstart / driver installation guide with the package, and for once, I was actually able to walk through it without any “oh this doesn’t work anymore” -moments. Even the three drivers required were found under Software/ICDI in the setup package. Kudos! As a result of installing CCS and StellarisWare, I now had 3.75 GB and 63 872 files of additional hacking capability on my hard drive. Gone are the days where you could fit an IDE into four floppies like my Borland Turbo C++ 3.0!

Taking it for a test drive

I first followed TI’s quickstart tutorial to the end to get some blinky LED action, and even tried out the UART example – even that worked out of the box with Putty set to COM25 and 115 200 baud rate. Next I made my own project by shamelessly following the recent HaD Getting Started guide.

Sure enough, the LEDs were now blinking just like I wanted them to – and blinding me in the process: whoever thought that you need SMD LEDs that are bright enough to leave light trails on my retina must’ve been utterly mad. I recommend either wearing sunglasses (might not be enough – seriously) or placing something near-opaque (like a piece of white paper) between yourself and the Launchpad when working with the LEDs for any longer periods.

However, I couldn’t yet find much information about input side, so after some searching, I located the documentaion for StellarisWare peripheral drivel library, SW-DRL-UG-9453.pdf and started reading. Armed with that and the short “Stellaris LM4F120 LaunchPad Evaluation Board User Manual” that was found from Documentation/Board/EK-LM4F120-UM.pdf I quickly wrapped up something that was supposed to turn red and green LEDs ON when pressing user switches SW1 and SW2, respectively:
Continue reading TI Stellaris Launchpad Test Run