Path: EDN Asia >> Design Centre >> IC/Board/Systems Design >> Guide to using MSP430 Launchpad (Part 1)
IC/Board/Systems Design Share print

Guide to using MSP430 Launchpad (Part 1)

14 Nov 2014  | Adrian Fernandez, Dung Dang

Share this page with your friends

PWM is primarily useful because of the ability to choose the duty cycle from a fixed frequency digital signal. Once fixed on a specific frequency, 490Hz in our example, the LaunchPad can convey different information to other "intelligent" devices by varying the duty cycle from 0% to 100%. The PWM signal receiver can decode the duty cycle into different available actions and behave accordingly.

Actually, PWM can also be used to control the power that is fed into certain electrical devices. By changing the duty cycle of a PWM signal, we can actually simulate an average voltage (or current) output. The longer the duty cycle is, relative to the period, means that, on average, the signal is more HIGH than LOW. This means on average more voltage (or current) is seen at the digital output pin. If we start at a duty cycle of 0%, we should see an effective average voltage of 0 V. Increasing duty cycle to 50%, we'll start to see an effective average voltage of ~1.8 V (VCC/2). And lastly, at a duty cycle of 100%, we should see an effective voltage of ~3.6 V (VCC).

As a matter of fact, this is exactly how we created the analogue output signal in our previous chapter using our analogWrite() function.


What, ANALOGWRITE() is a lie?
Sadly so. The MSP430 device on the MSP430 LaunchPad does not actually have a true analogue output module, which is often called a digital-to-analogue converter (or DAC). Now, some other MSP430 devices do have the actual DAC modules, but the MSP430G2553 device on our LaunchPad does not.


PWM signal components
If we take a close up look at our PWM signal, the ON and OFF components inside of a single period look very discrete and separated. However, the faster the frequency of our PWM signal, the harder it is to discern between the ON and OFF state and the signal appears to be averaged out. To explain this concept, think of an animated flipbook. If we flipped this animation one time per second, our animation would look jerky and very unconvincing. However, if we increase the frequency of our flipbook to change frames 60 times per second, suddenly the animation is smooth and realistic. Similarly, we can simulate an average voltage output at a pin by varying the duty cycle at a pin when frequency is high enough. Fortunately for us, the default 490Hz frequency of our LaunchPad is quick enough to fool most external devices into thinking a stable voltage is present.

A component can perceive the PWM signal as an average voltage signal that is somewhat between VCC and 0 V. The value of this averaged voltage signal can be determined by the relative ON duration of the signal in each period or cycle. For example, if the duty cycle of the signal is 75%, the averaged out voltage level can appear to be ~75% of VCC.


Average signal (V) = Duty cycle (%) x VCC (V)


PWM signal components

Figure 3: PWM signal components.


So just to reiterate, the analogWrite() function that we played with last chapter actually isn't analogue at all! It's truly a digital function that simulates an analogue output by varying the duty cycle of a PWM output signal.

The parameter that we passed into our analogWrite() function was simply telling the PWM signal what duty cycle it should toggle at. Because our analogWrite() function can accept an input parameter between (0_255), we can tell our PWM signal to generate up to 256 unique duty cycles. An input of 255 causes a duty cycle of 100%, while an input of 0 creates a duty cycle of 0%. This input maps linearly and we can get a good idea of what average voltage we can expect to see at the digital output pin for analogWrite(analogWriteInput) using the equation below:


Average voltage = VCC x (analogWriteInput=255)


So we were using PWM signals without even knowing it! In Chapter 8, we used this digital trick to change the intensity of LEDs. We even used three PWM signals to change the intensity of three LEDs to create a wide array of colours.

As we have actually spent quite some time with our PWM signal between this chapter and the last, let's spend the rest of the chapter learning more about a special type of PWM signal—the square wave.


Project 17: Square wave and a buzzer
A square wave is a unique PWM signal which has a duty cycle of 50%—this means that the signal is ON just as much as it is OFF. In this project, we will use a square wave to make some noise using a piezo buzzer.

Ingredients:

1. LaunchPad

2. Educational BoosterPack

OR

Breadboard, piezo buzzer (2.048kHz), 33 Ω resistor


Piezo buzzers
Piezo buzzers are used for making bleeps, bloops, and tones. We can generate these types of sounds by providing a square wave to a piezo buzzer. The frequency of the square wave (Hz) determines the pitch of the noise the buzzer generates. The slower the frequency, the lower the pitch. The higher the frequency, the higher the pitch.

 First Page Previous Page 1 • 2 • 3 Next Page Last Page


Want to more of this to be delivered to you for FREE?

Subscribe to EDN Asia alerts and receive the latest design ideas and product news in your inbox.

Got to make sure you're not a robot. Please enter the code displayed on the right.

Time to activate your subscription - it's easy!

We have sent an activate request to your registerd e-email. Simply click on the link to activate your subscription.

We're doing this to protect your privacy and ensure you successfully receive your e-mail alerts.


Add New Comment
Visitor (To avoid code verification, simply login or register with us. It is fast and free!)
*Verify code:
Tech Impact

Regional Roundup
Control this smart glass with the blink of an eye
K-Glass 2 detects users' eye movements to point the cursor to recognise computer icons or objects in the Internet, and uses winks for commands. The researchers call this interface the "i-Mouse."

GlobalFoundries extends grants to Singapore students
ARM, Tencent Games team up to improve mobile gaming


News | Products | Design Features | Regional Roundup | Tech Impact