University of Texas at El Paso Electrical and Computer Engineering Department

Similar documents
MSP430 Interfacing Programs

Timer A (0 and 1) and PWM EE3376

ECE 511: FINAL PROJECT REPORT GROUP 7 MSP430 TANK

Lab 5 Timer Module PWM ReadMeFirst

Copyright 2015 by Stephen A. Zajac & Gregory M. Wierzba. All rights reserved..spring 2015.

Timer A. Last updated 8/7/18

ECE 511: MICROPROCESSORS

Laboratory Seven Stepper Motor and Feedback Control

LM4: The timer unit of the MC9S12DP256B/C

Laboratory Exercise 1 Microcontroller Board with Driver Board

CSE 3215 Embedded Systems Laboratory Lab 5 Digital Control System

Lazy Clock Electronics and Software

ME 461 Laboratory #2 Timers and Pulse-Width Modulation

Lab 5: Inverted Pendulum PID Control

ME 461 Laboratory #5 Characterization and Control of PMDC Motors

Name & SID 1 : Name & SID 2:

Part (A) Using the Potentiometer and the ADC* Part (B) LEDs and Stepper Motors with Interrupts* Part (D) Breadboard PIC Running a Stepper Motor

Lecture 6: More on Timers and PWM

Sensors and Sensing Motors, Encoders and Motor Control

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

Measuring Distance Using Sound

CprE 288 Introduction to Embedded Systems (Output Compare and PWM) Instructors: Dr. Phillip Jones

WDTCTL = WDTPW + WDTHOLD; P1DIR = 1; // P1.0 output, all others input. sits here as long as the pin is high while (P1IN & 8); while (!

Exercise 3: Sound volume robot

Microcontrollers and Interfacing

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

Built-in soft-start feature. Up-Slope and Down-Slope. Power-Up safe start feature. Motor will only start if pulse of 1.5ms is detected.

Activity 4: Due before the lab during the week of Feb

Chapter 6 PROGRAMMING THE TIMERS

MICROCONTROLLER TUTORIAL II TIMERS

Lab 5: Interrupts, Timing, and Frequency Analysis of PWM Signals

Other than physical size, the next item that all RC servo specifications indicate is speed and torque.

Sensors and Sensing Motors, Encoders and Motor Control

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

Microcontrollers: Lecture 3 Interrupts, Timers. Michele Magno

VORAGO Timer (TIM) subsystem application note

1) Intro biped. Commando's: Demo:

Using the Z8 Encore! XP Timer

International Journal of Advanced Research in Electrical, Electronics and Instrumentation Engineering. (An ISO 3297: 2007 Certified Organization)

µtasker Document µtasker Hardware Timers

Using Servos with an Arduino

Introduction. Theory of Operation

Counter/Timers in the Mega8

Marine Debris Cleaner Phase 1 Navigation

UNIVERSITY OF VICTORIA FACULTY OF ENGINEERING. SENG 466 Software for Embedded and Mechatronic Systems. Project 1 Report. May 25, 2006.

Analog to Digital Conversion

LED + Servo 2 devices, 1 Arduino

CSCI1600 Lab 4: Sound

Timer 0 Modes of Operation. Normal Mode Clear Timer on Compare Match (CTC) Fast PWM Mode Phase Corrected PWM Mode

EE 314 Spring 2003 Microprocessor Systems

Chapter 7: The motors of the robot

ELCT 912: Advanced Embedded Systems

Portland State University MICROCONTROLLERS

Lab 5: Interrupts, Timing, and Frequency Analysis of PWM Signals

EE445L Fall 2011 Quiz 2A Page 1 of 6

Robotic Swing Drive as Exploit of Stiffness Control Implementation

2.017 DESIGN OF ELECTROMECHANICAL ROBOTIC SYSTEMS Fall 2009 Lab 4: Motor Control. October 5, 2009 Dr. Harrison H. Chin

Designing with a Microcontroller (v6)

Electronics Design Laboratory Lecture #6. ECEN2270 Electronics Design Laboratory

Lab 8. Stepper Motor Controller

Hello and welcome to this Renesas Interactive Course that provides an overview of the timers found on RL78 MCUs.

COMP 4550 Servo Motors

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

Exercise 5: PWM and Control Theory

MicroToys Guide: Motors N. Pinckney April 2005

Learning Objectives. References 10/26/11. Using servos with an Arduino. EAS 199A Fall 2011

Input/Output Control Using Interrupt Service Routines to Establish a Time base

PreLab 6 PWM Design for H-bridge Driver (due Oct 23)

Today's plan: Announcements: status report, midterm results op-amp wrap-up Comparators Measuring capacitance Powering your project

Microcontroller: Timers, ADC

Module: Arduino as Signal Generator

100UF CAPACITOR POTENTIOMETER SERVO MOTOR MOTOR ARM. MALE HEADER PIN (3 pins) INGREDIENTS

Laboratory Assignment Number 3 for Mech 143. Pre-Lab: Part 1 Interfacing to a DC Motor and Potentiometer

EE283 Electrical Measurement Laboratory Laboratory Exercise #7: Digital Counter

Lab Exercise 9: Stepper and Servo Motors

Upgrading from Stepper to Servo

Servo click. PID: MIKROE 3133 Weight: 32 g

ME 333 Assignment 7 and 8 PI Control of LED/Phototransistor Pair. Overview

Final Report MAL-9000

Hardware Flags. and the RTI system. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

The plan... CSE 6324 From control to actuators Michael Jenkin Office Hours: Sherman 1028 Wed 3-4. From the bottom up...

Electronics Design Laboratory Lecture #9. ECEN 2270 Electronics Design Laboratory

1. Introduction to Analog I/O

Lab 5: Control and Feedback. Lab 5: Controls and feedback. Lab 5: Controls and Feedback

128 KB (128K 1 = 128K

Hashemite University Faculty of Engineering Mechatronics Engineering Department. Microprocessors and Microcontrollers Laboratory

ESE 350 HEXAWall v 2.0 Michelle Adjangba Omari Maxwell

MicroToys Guide: Motors A. Danowitz, A. Adibi December A rotary shaft encoder is an electromechanical device that can be used to

ies-2309 Integrated Easy Servo

EE 308 Spring 2013 The MC9S12 Pulse Width Modulation System

High Speed Continuous Rotation Servo (# )

Intro to Engineering II for ECE: Lab 3 Controlling Servo Motors Erin Webster and Dr. Jay Weitzen, c 2012 All rights reserved

EE 308 Lab Spring 2009

1. Objectives Generation of Gate Drive Signals Inverter Circuitry Initial Testing Inverter Testing 5. 5.

PWMLib PWM Library. Jim Schimpf. Document Number: PAN Revision Number: April Pandora Products. 215 Uschak Road Derry, PA 15627

Arduino Microcontroller Processing for Everyone!: Third Edition / Steven F. Barrett

Lab #10: Analog to Digital Converter (ADC) Week of 15 April 2019

Lock Cracker S. Lust, E. Skjel, R. LeBlanc, C. Kim

COSC 3215 Embedded Systems Laboratory

SOLAR PATIO UMBRELLA

Transcription:

University of Texas at El Paso Electrical and Computer Engineering Department EE 3176 Laboratory for Microprocessors I Fall 2016 LAB 05 Pulse Width Modulation Goals: Bonus: Pre Lab Questions: Use Port and Timer Interrupts with PWM (Pulse Width Modulation) to sweep the single-bladed arm of the SG90 back and forth between 0 and 180 degrees. Use the on-board button to start and stop the sweep. Use the on-board LEDs to indicate the state of the motor; red for stop, green for start. Use a Port Pin other than P1.2 to output the PWM and use a different output and count mode. Justify your reasoning to the TA and in your report. +10 Use only one timer. +10 What values of TA0CCR1 did you use to move the arm to - 0, 90 and 180? What duty cycle are these? Give your answer in time in ms and percentage. What happens with duty cycles below or above those mentioned in the specification sheet?

Pulse Width Modulation Lab Guide A secondary use for the Timer peripheral is the generation of a continuous period signal, sometimes referred to as a pulse train or pulse wave; this is known as PWM (Pulse Width Modulation). We can generate various periodic signals using the Timer peripheral of the MSP430. Timer The registers that control the Timer Interrupts are 16 bit. There are two timer modules; Timer A0 and Timer A1. Below are the pertinent registers: TAxCTL - Timer A Control; x = 0 or 1 (Timer A0 or Timer A1) TAxCCTLy - Timer A Capture/Compare Control TAxCCRy - Timer A Capture/Compare Module Register TAxR - Timer A Count Register TAIV - Timer A Interrupt Vector Value Where x is the Timer A Module number, 0 or 1 (Timer A0 or Timer A1) and y is the Timer A Capture/Control Module number: 0, 1 or 2. For the MSP430G2553, we have 2 Timer A Modules with 3 Capture/Compare modules for a total of 8 interrupt trigger sources: 2 Timer Overflows and 6 Capture/Compare flags (there is no Capture function for Module 2 for Timer A0). Shorthand to refer to a Timer module and its capture/compare submodule exists. For example, TA0.1 refers to Timer A0 Capture/Control Module 1. In addition, the MSP430G2553 header file has Control Bits defined for the Timer Control Registers. See the Interrupts Guide for more details.

SG90 Servo Motor The SG90 is a simple servo motor with a 180 position capability. You can use 3 base positions to determine your motors exact range: far left, middle and far right at -90, 0 and 90 respectively. See the diagram below: 90 0 180 The datasheet is short and contains all the info you need. Connect the power wire to any VCC pin on the MSP430, same with the Ground pin, to any GND pin that is. The PWM wire should be connected to any Port Pin that is PWM capable, i.e. pins that are enabled using TAxCCR1 (See the Interrupts Guide for more details). You will gradually increase or decrease the duty cycle of the pulse width by manipulating this value.

Notes: Every motor is slightly different. Also, these motors run best under 5V, but the MSP430 puts out about 3.3V. This just affects the pulse width s period, meaning that the duty cycle necessary for a given position will vary slightly than what is mentioned in the data sheet. A period of 20ms is still recommended. Depending of the position of the motor, you might cause a momentary short, making it a bit inconvenient to debug as it will severe communication to the PC. This is not cause for concern. You will notice that your motor may have a range slightly more (or less than, depending on how you look at it) than the ± 90 degrees. Once you reach a point where the motor will no longer move, you may stop increasing the pulse width duty cycle. The goal is to sweep back and forth through the whole 180 range of the motor, being able to start and stop with the push of the button. Depending on how you increment the pulse width duty cycles and set up the timing, you will either get a slow choppy motion or a swift and smooth swipe. Either is fine.

Pulse Width Modulation Lab Hints It is recommended that you examine the sample program provided. Read the comments and study the program flow. Note the use of TA0CCR1 for the Period and TA0CCR1 for the Duty Cycle. Since we are using interrupts, we will have an empty main loop. Setup the onboard button like you normally would. You will use the Port 1 ISR to stop and start the clock/pwm as well as toggle the LEDs. It s possible to accomplish this lab with only one Timer ISR, but you may use two. See the Interrupts Guide for help on doing so. If you decide, you may choose to use global variables in your C program. The variables must be global or you will not be able to access them from any of the ISRs. Below is the basic setup. You may use it as the basis for your code, just fill in the blanks:

Main Program: #include <msp430g2553.h> unsigned int go = 0, step = 0, up = 1, tic = 0; ;//Example of Global variables. int main (void) { //Setup WDTCTL = WDTPW + WDTHOLD;//Stop Watchdog Timer //Setup P1.3 P1DIR &= ~BIT3; P1REN = BIT3; P1OUT = BIT3; //Setup LEDs P1DIR = BIT0 + BIT6; P1OUT = BIT0; P1OUT &= ~BIT6; //Setup PWM - Timer A0.1 - P1.2 P1DIR = //?? P1SEL = //?? P1SEL2 &= ~(//?? TA0CTL = //Setup Timer TA0CTL ^= //Stop Timer Here (This and previous line can be combined). TA0CCTL1 = //?? TA0CCR0 = //Period of 20ms (50Hz) TA0CCR1 = //Duty Cycle of 1ms (5%) //Setup Timer A1.0 TA1CTL = //Setup Timer TA1CTL ^= //Start Timer Here (This and previous line can be combined). TA1CCTL0 = //Enable Timer Capture Compare Interrupt TA1CCR0 = // 50000 clock cycles //Setup Port 1 Interrupts P1IE = BIT3; P1IES = BIT3; P1IFG = 0; _enable_interrupts(); //Enable General Interrupts. Best to do this last. } while (1){} //Empty infinite while loop.

Interrupt Service Rountine(s): // Port 1 Interrupt Service Routine #pragma vector=port1_vector interrupt void Port_1(void) { // *Toggle Start/Stop of the Timer for the PWM. Stopping the Timer // stops the PWM and thus stops the motor. // *Stop Timer 1 or else the pulse width will not be the same as when you // stopped the PWM and thus neither will be the position of the motor. // *Toggle LEDs Green/Red to indicate Start or Stop. } P1IFG &= ~BIT3; // Clear Button Flag // Timer 1 A0 Interrupt Service Routine #pragma vector = TIMER1_A0_VECTOR interrupt void Timer1_A0_ISR( void ) { /* Will jump in here when TA1R reaches value of TA1CCR0 stored during setup. Increment or toggle TA0CCR1 here to vary the position of the motor. MAKE SURE YOU TOGGLE *TA0CCR1* since it belongs to the PWM and DO NOT TOGGLE *TA1CCR1* since that belongs to *this* timer. */ }

Pulse Width Modulation Post Lab Lab Notebook Questions: Answer the following questions in your lab notebook: What is the difference between a servo motor and a regular DC motor? What are the dis/advantages of each? What uses, besides a windshield wiper, can you think of for the SG90?

Pulse Width Modulation Frequently Asked Questions What s inside a servo motor? Inside the servo motor, we have a regular DC motor, a potentiometer, and a control circuit. The DC motor is connected to the control circuit through a series of gears and the potentiometer. As the DC motor rotates, the resistance increases and the motor decides where to stop depending on the pulse signal applied to the PWM wire. Can I use the motor to push, pull or lower and raise something; I see 9g on the side of the SG90; does that mean it can only lift 9 grams? Sure. Each motor has a Stall Torque rating; a weight and distance that the motor can safely stall at, resisting any motion. For example, the SG90 has a Stall Torque rating of 16.7oz/in or 1.2kg/cm at 4.8V, meaning that the SG90 can, for instance, hold an item that weighs 16.7oz suspended by a string about 1 inch from the pivot of the attached arm or center of the motor. However, since we are interfacing with a 3.3V micro controller, those numbers will be smaller. It would still be close to a pound though. The 9g on the side of the motor means that the motor itself weighs 9 grams! My motor sometimes swings fast and other times it moves slow; how can I get it to move more consistently? The speed of the motor is proportional to the current position and the desired position, meaning that the speed will be faster if the distance between the two positions is greater, and slower if the distance is smaller. This is known as Proportional Control and helps the motor be as efficient as possible, keeping the motor from doing more work than necessary. Unfortunately, this means precise speed control is not possible and so you must take this into account.