MSP430 Encoder Adjustable PWM

PULSE WIDTH MODULATION

Pulse Width Modulation (PWM) is an easy and efficent way of controlling the speed of a DC motor or control the brightness of a lamp or LED. In conjunction with a low pass filter, PWM can also be used as an accurate way to create a digital to analog converter, which in turn can be used to create sine waves or other analog waveforms.

A basic PWM output consists of a digital waveform that is fixed in frequency and varies in duty cycle, usually from 0% (FULL OFF) to 100% (FULL ON). When used to control an inductive load such as a motor, PWM, operating at a high enough frequency, provides an average value of current flow to the motor which is directly related to the duty cycle of the PWM.

While it is possible to create PWM in software, many low cost microcontrollers, including the Texas Instruments MSP430 series, contain hardware timer modules which allow the creation of PWM waveforms to be easily implemented.

The program shown below creates a single PWM output using a MSP430G2553 microcontroller along with the MSP_EXP430G2 Launchpad.

The PWM control program has the following attributes:

1.) PWM output frequency of 10 kHz. (Easily Changed)
2.) PWM output duty cycle is adjustable using an inexpensive quadrature encoder
3.) PWM output is adjustable from 0% (Full Off) to 100% (Full On) in 1% increments.
4.) Visual indication of PWM duty cycle percentage using a red – green LED.
5.) Visual indication (Blue LED) when PWM is at exactly 50%.
6.) Encoder pushbutton switch sets PWM output to 0% (Off).
7.) Precise PWM frequency and duty cycle using a 4.0Mhz crystal oscillator.
8.) LaunchPad LED1 and LED2 flash with increment and decrement pulses from encoder.

OUTPUT DRIVER

Most applications will require an output driver to control a motor or a lamp. A reasonably priced driver is the SN754410 quadruple half H-bridge driver that has a 1 amp output capability per driver at a voltage of 4.5 VDC to 36VDC in positive supply applications.

COMMENTS

The start-up PWM value is set at 5%. This can be easily changed in the main function below. The maximum PWM is set to full on (100%), this can be changed to another value in the encoder interrupt.

I have done extensive testing and the encoder interface works very well, in fact quite bullet proof – no skipped or extra encoder pulses even when the encoder is rotated as fast as possible. The combination of RC network and interrupt polling makes it happen.

Note: The program below utilizes an external 4.0 MHz crystal oscillator connected to pin 19 (xin) of the MSP430 Launchpad. This oscillator is not shown on the schematic! The program can be modified to utilize the microcontrollers internal oscillator.

 MSP430 ENCODER PWM MAIN FUNCTION

MSP430 ENCODER PWM INTERRUPTS

MSP430 ENCODER PWM OUTPUT WAVEFORMS

PWM OUTPUT AT 1%

 

PWM OUTPUT AT 50%

 

PWM OUTPUT AT 99%

 

MSP430 ENCODER PWM SCHEMATIC

MSP430 ENCODER PWM SCHEMATIC

 

ENCODER PWM PROTOTYPE

ENCODER PWM PROTOTYPE

 

 

 

 

 

 

 

End Post

Leave a Reply

Your email address will not be published. Required fields are marked *