Implementing Pulse-Width Modulation through MSP430 Timers. Roy Dong 11/19/2010

Similar documents
Timer A (0 and 1) and PWM EE3376

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Analog signals are those which are naturally occurring. Any analog signal can be converted to a digital signal.

Pulse Width Modulation Applications

Analog to Digital Conversion of Sound with the MSP430F2013

STEPPER MOTOR SPEED AND POSITION CONTROL

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

25. AM radio receiver

Micro-Step Driving for Stepper Motors: A Case Study

ADS9850 Signal Generator Module

Android Application Development and Bluetooth Technology

AN4646 Application note

Application Report. 1 Introduction. 2 Resolution of an A-D Converter. 2.1 Signal-to-Noise Ratio (SNR) Harman Grewal... ABSTRACT

Atmel Norway XMEGA Introduction

Microcontroller-based experiments for a control systems course in electrical engineering technology

Pulse Width Modulation

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AC : PRACTICAL DESIGN PROJECTS UTILIZING COMPLEX PROGRAMMABLE LOGIC DEVICES (CPLD)

1/22/16. You Tube Video. Definitions. Duty Cycle: on-time per period (specified in per cent)

MAS.836 HOW TO BIAS AN OP-AMP

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Implementing SPI Communication Between MSP430 G2452 and LTC ADC

Interfacing Analog to Digital Data Converters

Microcontroller for Variable Speed BLDC Fan Control System. T.C. Lun System Engineer, Freescale Semiconductor, Inc.

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

Fundamentals of Power Electronics. Robert W. Erickson University of Colorado, Boulder

A DESIGN OF DSPIC BASED SIGNAL MONITORING AND PROCESSING SYSTEM

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Crazy Alarm Clock L A K S H M I M E Y Y A P P A N J A M E S K A Y E W I L L I A M D I E H L C O N G C H E N

Signal Processing in So.ware and Electric Field Sensing

Designing an Induction Cooker Using the S08PT Family

DAC Digital To Analog Converter

Construction and Application of a Computer Based Interface Card

MECE 102 Mechatronics Engineering Orientation

Computer Aided Design of Home Medical Alert System

The Design of DSP controller based DC Servo Motor Control System

Pulse width modulation

Voltage Measurement with A PIC Microcontroller

PWM IN AVR. Developed by: Krishna Nand Gupta Prashant Agrawal Mayur Agarwal

Digital Guitar Effects Pedal

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Lab Experiment 1: The LPC 2148 Education Board

Computer and Set of Robots

Conversion Between Analog and Digital Signals

DS1104 R&D Controller Board

Microcontroller to Sensor Interfacing Techniques

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Pulse Width Modulated (PWM) Drives. AC Drives Using PWM Techniques

3.2 inch QVGA TFT Color LCD User s Guide Version 1 & 2

Software Manual RS232 Laser Merge Module. Document # SU Rev A

LEVERAGING FPGA AND CPLD DIGITAL LOGIC TO IMPLEMENT ANALOG TO DIGITAL CONVERTERS

Microcontroller Programming Beginning with Arduino. Charlie Mooney

Chapter 6: From Digital-to-Analog and Back Again

Analog and Digital Filters Anthony Garvert November 13, 2015

DESIGN OF 6 DOF ROBOTIC ARM CONTROLLED OVER THE INTERNET

AP TriCore. Sinusodial 3-Phase Output Generation Using The TriCore General Purpose Timer Array. Microcontrollers

HP03 BAROMETER MODULE Version: 1.1

Single Phase Two-Channel Interleaved PFC Operating in CrM

Lab 1 Course Guideline and Review

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

Flexible Active Shutter Control Interface using the MC1323x

Theory of Operation. Figure 1 illustrates a fan motor circuit used in an automobile application. The TPIC kω AREF.

Microtronics technologies Mobile:

An Introduction to MPLAB Integrated Development Environment

Room Temperature based Fan Speed Control System using Pulse Width Modulation Technique

The Study and Design Of a Wireless ECG Monitoring System

Series AMLDL-Z Up to 1000mA LED Driver

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

Decimal Number (base 10) Binary Number (base 2)

Pulse Width Modulated (PWM)

Software engineering for real-time systems

RPLIDAR. Low Cost 360 degree 2D Laser Scanner (LIDAR) System Development Kit User Manual Rev.1

HT46R14A Single Phase AC Induction Motor Frequency Converter Application

Three-Level PWM DC/AC Inverter Using a Microcontroller

Welcome to the tutorial for the MPLAB Starter Kit for dspic DSCs

PHY-2464 Physical Basis of Music

Industrial Automation Training Academy. PLC, HMI & Drives Training Programs Duration: 6 Months (180 ~ 240 Hours)

Accurate Measurement of the Mains Electricity Frequency

POCKET SCOPE 2. The idea 2. Design criteria 3

MSP-EXP430G2 LaunchPad Workshop

REMOTE HOST PROCESS CONTROL AND MONITORING OF INDUSTRY APPLIANCES

How To Control A Motor Control On An Hvac Platform

Hideo Okawara s Mixed Signal Lecture Series. DSP-Based Testing Fundamentals 46 Per-pin Signal Generator

Theory and Practice of Tangible User Interfaces. Thursday Week 2: Digital Input and Output. week. Digital Input and Output. RGB LEDs fade with PWM

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Selecting and Implementing H-Bridges in DC Motor Control. Daniel Phan A

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Analog/Digital Conversion. Analog Signals. Digital Signals. Analog vs. Digital. Interfacing a microprocessor-based system to the real world.

Single Phase Two-Channel Interleaved PFC Operating in CrM Using the MC56F82xxx Family of Digital Signal Controllers

Monitoring of Intravenous Drip Rate

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK

Experiment 8 : Pulse Width Modulation

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

EVAL-UFDC-1/UFDC-1M-16

AN2680 Application note

Transcription:

Implementing Pulse-Width Modulation through MSP430 Timers Roy Dong 11/19/2010 Executive Summary: Pulse-width modulation has a variety of uses, and is particularly useful because it allows digital sources, such as microcontrollers, to convey values between 0 and 1. This application note presents a brief discussion of pulse-width modulation, as well as how to code pulse-width modulation using the timer registers on a MSP430G2231 microprocessor using C. In closing, I provide the two applications of pulse-width modulation on the DRV8412 motor driver card: driving a brushed DC motor and communicating analog values. Keywords: MSP430, timer, pulse-width modulation

Introduction Pulse-width modulation (PWM) is a method by which digital circuit elements can output analog values using only high and low voltage signals. This is achieved by alternating between high and low at the correct intervals to achieve a signal with an equivalent DC voltage to the desired analog value. The fraction of the period in which the signal is high is known as the duty cycle. PWM signals have a variety of uses. This application note will discuss two possible uses, both implemented on the Texas Instruments (TI) DRV8412 motor driver card: 1) driving a brushed DC motor, and 2) communicating an analog value to a test point. The information presented in this application note is an implementation of PWM on the TI MSP430G2231 microcontroller in C. This is one of the microcontrollers featured in TI s recently released MSP430 LaunchPad (MSP-EXP430G2). More specifically, this application note will cover how to code PWM on the MSP430 LaunchPad, as well as possible uses for the DRV8412 motor driver card.

Coding PWM through Software Pulse-width modulation is done on the MSP430 through the timer. A timer on the MSP430 increases a register by one every clock cycle on the MSP430. There are four options for the MSP430 timer, pictured in Table 1 below. MC_0 disables the timer. MC_1 counts from 0x0000 to the value stored in the CCR0 register, resets to 0x0000, and repeats. MC_2 counts from 0x0000 to 0xFFFF, resets to 0x0000, and repeats. MC_3 counts from 0x0000 to the value stored in the CCR0 register, counts down from this value to 0x0000, and repeats. Graphical representations of MC_1 through MC_3 are attached as Figure 1 through Figure 3, which are taken from TI s MSP430x2xx User s Guide. MC_0 Stop MC_1 Up to CCR0 MC_2 Continuous Up MC_3 Up/Down Table 1: Timer modes Figure 1: Up to CCR0 Figure 2: Continuous Up

Figure 3: Up/Down Mode To program the timer in a certain mode, we have to use the control register on the MSP430. For example, if we wish to program Timer A to count 1000 values, we use the TACTL register. TACTL stands for Timer A Control. Also, since the count begins from 0x0000, to count 1000 values, we would set CCR0 to 999. The code would be as follows: CCR0 = 1000 1; TACTL = MC_1; Now, we can set which pin to output the PWM signal. For example, from pg. 6 of the MSP430G2231 datasheet, pin 4 is P1.2/TA0.1/A2. We want to use this pin as TA0.1. To do this, we have to set second bit of both the P1SEL and P1DIR registers accordingly. Generally, to set the Px.y pin, we must set the PxSEL and PxDIR registers accordingly at bit y. A 0 in PxDIR is input; a 1 is output. A 0 in PxSEL means general purpose input/output, while a 1 in PxSEL reflects a special purpose based on the pin. For example, to use the timer, we would set the appropriate bits in PxSEL and PxDIR to 1. To use the ADC converter (A2), we would set PxSEL to 1 and PxDIR to 0. The code to set the pin as a timer is as follows: P1DIR = BIT2; P1SEL = BIT2; We use the = operator so the bits we do not wish to change remain the same.

Next, we must set the PWM mode through the CCTLx register, where x is the port number of the pin. For example, to use P1.2/TA0.1/A2, we would use CCTL1. The modes are pictured below in Table 2. OUTMOD_0 OUTMOD_1 OUTMOD_2 OUTMOD_3 OUTMOD_4 OUTMOD_5 OUTMOD_6 OUTMOD_7 Table 2: PWM modes PWM Disabled Set PWM Toggle/Reset PWM Set/Reset Toggle Reset PWM Toggle/Reset PWM Reset/Set If the mode used has only one description, e.g. Set, then the pin performs this action when it reaches CCR1. So, if the PWM is in OUTMOD_1, the register will go high when the timer reaches CCR1 and stay high until it is reset manually. If the mode used has two descriptions, the first description is performed when CCR1 is reached, and the second is performed when CCR0 is reached. For example, if we are in OUTMOD_3, the register will set at CCR1 and then reset at CCR0. To use the PWM to achieve a duty cycle of 20%, we would use the following code: CCTL1 = OUTMOD_7; CCR1 = 200-1; Since we are in MC_2, which counts up to CCR0, the pin is set high just before 0x0000, when the timer register equals CCR0. Then, the pin outputs high until CCR1 is reached, when it resets. The timer, in our example code, will count from 0 to 999. From 0 to 199, the register will be high, and from 200 to 999, the register will be low. This achieves a 20% duty cycle.

Results PWM has many possible applications. TI s DRV8412 motor driver card provides two examples of how PWM can be used. First, the PWM signal can be used to drive a brushed DC motor. In this case, increasing the duty cycle from 0% to 100% increases the speed and torque of the motor. Sensing current feedback through the DRV8412 can also allow for advanced PI control of the brushed DC motor. Also, the DRV8412 has special PWM DACs. This allows a microcontroller to communicate analog values through digital signals sent to the DRV8412. At first, it may seem that DACs should merely provide an analog version of the pulse-width modulated signal. However, one must remember that a DAC is essentially a low-pass filter, and if the frequency of the pulses is significantly higher than the cut-off frequency of the DAC, the DAC will just output an analog value equal to the average DC voltage. The output of this DAC will be: duty cycle * Vcc. Beyond the DRV8412, there are many other uses for PWM signals. PWM allows us to digitally create analog voltage levels for control functions and power supplies. Also, PWM can create analog signals for arbitrary waveforms, including music and speech. With the ability to code PWM on the MSP430, a broad set of options for analog signal generation through digital sources are available.

References Timers and Clocks and PWM! Oh My! NJC s MSP430 LaunchPad Blog. http://www.msp430launchpad.com/2010/07/timers-and-clocks-and-pwm-oh-my.html Accessed 11/19/2010. MSP430G2231 Datasheet. Texas Instruments. http://focus.ti.com/docs/prod/folders/print/msp430g2231.html Accessed 11/19/2010. MSP430x2xx User s Guide. Texas Instruments. http://focus.ti.com/lit/ug/slau144e/slau144e.pdf Accessed 11/19/2010. Wireless Sensor Network and Laboratories. NTU School of Engineering and Applied Science at Walden University. http://nslab.ee.ntu.edu.tw/courses/wsn-labs-fall-07/ Accessed 11/19/2010. MSP430 Interrupts. Dublin Institute of Technology. http://eleceng.dit.ie/frank/msp430/msp430interrupts.pdf Accessed 11/19/2010.