ELEC 3040/3050 Lab #7

Similar documents
Lab 9. Speed Control of a D.C. motor. Sensing Motor Speed (Tachometer Frequency Method)

ECE 271 Microcomputer Architecture and Applications University of Maine

For reference only Refer to the latest documents for details

ECE 271 Microcomputer Architecture and Applications University of Maine. Lab 7: Pulse Width Modulation Instructor: Prof. Yifeng Zhu Spring 2016

Microcontrollers: Lecture 3 Interrupts, Timers. Michele Magno

AN2581 Application note

Lab 10. Speed Control of a D.C. motor

Course Introduction. Content 20 pages 3 questions. Learning Time 30 minutes

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

Grundlagen Microcontroller Counter/Timer. Günther Gridling Bettina Weiss

Timer A. Last updated 8/7/18

Hello, and welcome to this presentation of the STM32 Infrared Timer. Features of this interface allowing the generation of various IR remote control

ECE251: Tuesday October 3 0

Lab 5 Timer Module PWM ReadMeFirst

Oct 30 Announcements. Bonus marked will be posted today Will provide 270 style feedback on multiple-choice questions. [3.E]-1

ECE 271 Microcomputer Architecture and Applications University of Maine

Using the Z8 Encore! XP Timer

AN4062 Application note

Microcontroller: Timers, ADC

Hello, and welcome to this presentation of the FlexTimer or FTM module for Kinetis K series MCUs. In this session, you ll learn about the FTM, its

Chapter 6 PROGRAMMING THE TIMERS

LM4: The timer unit of the MC9S12DP256B/C

µtasker Document µtasker Hardware Timers

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

Timing System. Timing & PWM System. Timing System components. Usage of Timing System

EE251: Thursday October 25

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

Tektronix Courseware. Academic Labs. Sample Labs from Popular Electrical and Electronics Engineering Curriculum

ATmega16A Microcontroller

EEL 4744C: Microprocessor Applications Lecture 8 Timer Dr. Tao Li

Reading Assignment. Timer. Introduction. Timer Overview. Programming HC12 Timer. An Overview of HC12 Timer. EEL 4744C: Microprocessor Applications

PWM System. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

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

AN3332 Application note

AC LAB ECE-D ecestudy.wordpress.com

Graphical Control Panel User Manual

Timer A (0 and 1) and PWM EE3376

RV-8564 Application Manual. Application Manual. Real-Time Clock Module with I 2 C-Bus Interface. October /62 Rev. 2.1

Microprocessor & Interfacing Lecture Programmable Interval Timer

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

EIE/ENE 334 Microprocessors

I-7088, I-7088D, M-7088 and M-7088D User Manual

MICROCONTROLLER TUTORIAL II TIMERS

ELCT 912: Advanced Embedded Systems

Topics Introduction to Microprocessors

Lazy Clock Electronics and Software

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

Temperature Monitoring and Fan Control with Platform Manager 2

Electronic Instrumentation ENGR-4300 Fall 2004 Section Experiment 7 Introduction to the 555 Timer, LEDs and Photodiodes

To design/build monostable multivibrators using 555 IC and verify their operation using measurements by observing waveforms.

High Resolution Pulse Generation

Select the single most appropriate response for each question.

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

Timer/Counter with PWM

Menu. More on Timer-Counter, this time with INTERRUPTS for output timing

Iowa State University Electrical and Computer Engineering. E E 452. Electric Machines and Power Electronic Drives

Measuring Distance Using Sound

Project Final Report: Directional Remote Control

The Need. Reliable, repeatable, stable time base. Memory Access. Interval/Event timers ADC DAC

FR FAMILY MB91460 PROGRAMMABLE PULSE GENERATOR 32-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

Utilizing the Trigger Routing Unit for System Level Synchronization

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

HOMANN DESIGNS. DigiSpeed. Instruction manual. Version 1.0. Copyright 2004 Homann Designs.

Introduction to Oscilloscopes Instructor s Guide

ME 461 Laboratory #5 Characterization and Control of PMDC Motors

Counter/Timers in the Mega8

High Group Hz Hz. 697 Hz A. 770 Hz B. 852 Hz C. 941 Hz * 0 # D. Table 1. DTMF Frequencies

PIC ADC to PWM and Mosfet Low-Side Driver

ZKit-51-RD2, 8051 Development Kit

VORAGO Timer (TIM) subsystem application note

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

Hello, and welcome to this presentation of the STM32 Digital Filter for Sigma-Delta modulators interface. The features of this interface, which

Generating DTMF Tones Using Z8 Encore! MCU

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

High Speed Counter (HSC) Self-Help Guide

Temperature Monitoring and Fan Control with Platform Manager 2

Migrate PWM from MC56F8013 to MC How to set up the PWM peripheral on the MC56F8247 using the setting of the PWM on the MC56F8013

Analog Digital Converter

Version Futek Instruments, LLC

PSoC 4 Timer Counter Pulse Width Modulator (TCPWM)

PIC Analog Voltage to PWM Duty Cycle

AN4277 Application note

Universal Driver Software User Guide FP-GPIO96 FeaturePak 96-bit digital I/O module For Version and later

Section 35. Output Compare with Dedicated Timer

L13: (25%), (20%), (5%) ECTE333

LV-Link 3.0 Software Interface for LabVIEW

EE445L Fall 2014 Quiz 2A Page 1 of 5

Electronics I. laboratory measurement guide

CSCI1600 Lab 4: Sound

Embedded Systems and Software

AN3248 Application note

F²MC-16FX FAMILY ALL SERIES PROGRAMMABLE PULSE GENERATOR 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

Using the HCS08 TPM Module In Motor Control Applications

DC Brushed Motor Controller Module EDP-AM-MC1

EVDP610 IXDP610 Digital PWM Controller IC Evaluation Board

PAK-VIIIa Pulse Coprocessor Data Sheet by AWC

Fixed-function (FF) implementation for PSoC 3 and PSoC 5 devices

EE 308 Spring 2013 The MC9S12 Pulse Width Modulation System

STM32L151xC STM32L152xC

ACT8846 Rev 9.0, 18-Jun-2018

Transcription:

ELEC 3040/3050 Lab #7 PWM Waveform Generation References: STM32L1xx Technical Reference Manual STM32L100RC Data Sheet

Goals of this lab exercise Begin the primary design project for the semester Speed controller for a D.C. motor Generate a pulse-width-modulated (PWM) waveform with keypad-selectable duty cycle Using a programmable timer The generated waveform will be amplified in a the next lab to drive a D.C. motor 2

Motor Speed Control Project 1. Generate a PWM waveform 2. Amplify the waveform to drive the motor 3. Measure motor speed 4. Measure motor parameters 5. Control speed with a PID or other controller 12v DC Motor Tachometer 9v Power Supply Amplifier Computer System Frequency/ Amplitude Measurement 3

PWM Digital Waveforms A pulse-width modulated (PWM) waveform is a periodic signal comprising pulses of varying duration Modulation refers to modifying the pulse width (with period held constant) to achieve a desired effect Effect often an average voltage to control a device PWM signals are often used to drive D.C. motors, commercial lights, etc. 4

PWM to Drive a Servo Motor Servo PWM signal 20 ms period 1 to 2 ms pulse width 5

PWM Waveform Parameters T = period of waveform (constant) T1 = duration of pulse T2 = T T1 Duty Cycle = T1/T = T1/(T1+T2) V avg = V max x Duty Cycle Pulses can also be active-low. 6

Timer operating modes Timer capture/compare channels provide operating modes other than periodic interrupts Output compare mode Create a signal waveform/pulse/etc. Connect timer output TIMx_CHy to a GPIO pin Compare CNT to value in Capture/Compare Register CCRy Change output pin when CNT = CCRy Pulse-Width Modulated (PWM) waveform generation mode Setup similar to output compare mode Force output pin active while CNT < CCRy Force output pin inactive while CCRy CNT ARR ARR sets PWM period, CCRy determines PWM duty cycle One pulse mode Create a single pulse on a pin Setup similar to output compare mode Disable the counter when the event occurs Input capture mode Capture time at which an external event occurs Connect a GPIO pin to timer input TIMx_CHy Capture CNT value in Capture/Compare Register CCRy at time of an event on the pin Use to measure time between events, tachometer signal periods, etc 7

General-purpose timers TIM10/TIM11 Basic timing function (earlier lab) * 2.097MHz if default MSI clock used (0x0020_0000 cycles/sec) * 16 MHz if HSI clock used Capture/Compare Channel 1 TIMx_CH1 input/output 2 channels in TIM9, 4 channels in TIM2-3-4, no channels in TIM6-7 TIM6-7-10-11 have up counters, TIM2-3-4-9 have up/down counters 8

Timer capture/compare channels Input capture: Copy CNT to CCRx when input event detected ARR Output compare: Trigger an event when CNT = CCRx One-pulse Pulse-width modulation OCxREF active inactive Period Start CNT=CCRx=3 (toggle OCxREF) CNT=ARR=7 (reset CNT and OCxREF) 9

Capture/Compare Output Stage ARR CNT Comparator Outputs Output** = CCR1 Output polarity Mode = Output Compare or PWM Enable output ** Route output OC1 to a GPIO pin as an alternate function. (each GPIO pin can connect to one or two timer channels) 10

Timer outputs as GPIO pin alternate functions Each GPIO pin configurable as: INPUT, OUTPUT, ANALOG, ALTERNATE FUNCTION - Select pin modes in GPIOx->MODER (10 = alternate function) From STM32L100RX Data Sheet Table 7. Pin Definitions (partial) 1. Select AF mode for pin in MODER 2. Select AFn in GPIOx->AFRL/AFRH We will use TIM10_CH1 (Pin PA6) 11

Selecting an alternate function Timers GPIOn->MODER selects AF mode for pins (10) GPIOn->AFR[0] selects AFs for pins Pn0-Pn7 GPIOn->AFR[1] selects AFs for pins Pn8-Pn15 Only a subset of AF s available at each pin, as listed in data sheet. (see previous slide) Example: Configure PA6 as TIM3_CH1 (AF2) GPIOA->MODER &= ~0x00003000; //clear PA6 mode GPIOA->MODER = 0x00002000; //PA6 = AF mode GPIOA->AFR[0] &= ~0x0F000000; //clear AFRL6 GPIOA->AFR[0] = 0x02000000; //PA6 = AF2 AFR[0]: AFRLn defines pin n, n=0..7 12

Timer System Control Register 1 TIMx_CR1 (reset value = all 0 s) See timer overview from earlier lab 7 6 5 4 3 2 1 0 ARPE CMS* DIR* OPM URS UDIS CEN Center mode select 00 = edge-aligned -count in one direction Others: center aligned -count in both directions Direction 0 = count up 1 = count down * TIM6-7-10-11 limited to count up: - DIR = 0 & CMS = 00 only One Pulse Mode Counter Enable* 0 = disable 1 = enable 1 = counter stops at update event 0 = counter continues at UE *CEN only bit that needs to be changed for simple PWM 13

Timer Status Register TIMx_SR (reset value = all 0 s) 7 6 5 4 3 2 1 0 See timer overview from earlier lab CC4IF CC3IF CC2IF CC1IF UIF Capture/compare interrupt flags 1 = capture/compare interrupt pending 0 = no capture/compare event occurred Set by hardware on capture/comp event Cleared by software (reset CCxIF bit to 0) TIM10 has only CC1IF Update interrupt flag 1 = update interrupt pending 0 = no update occurred Set by hardware on update event Cleared by software (reset UIF bit to 0) 14

Timer DMA/Interrupt Enable Register TIMx_DIER (reset value = all 0 s) See timer overview from earlier lab 8 7 6 5 4 3 2 1 0 UDE CC4IE CC3IE CC2IE CC1IE UIE Update DMA request enable 1 = enable, 0 = disable Update interrupt* enable 1 = enable, 0 = disable Capture/Compare interrupt* enable TIMx interrupt on capture/compare event 1 = CCx interrupt enabled, 0 = disabled TIM10 has only CC1IE * Capture/compare and update events generate the same IRQn signal, and use the same interrupt handler. Handler reads status register flags to determine source. 15

Capture/Compare Register Compared to TIMx_CNT to trigger operations at specified times. TIMx_CCRy = TIMx capture/compare register, channel y TIM2-3-4: y=1,2,3,4; TIM9: y = 1,2; TIM10-11: y=1 CCRy register width same as CNT/ARR registers (16 bits) ------------------------------------------------------------------------------------------ Input capture mode: TIMx_CNT captured in TIMx_CCRy when a designated input signal event is detected Output compare mode: TIMx_CCRy compared to TIMx_CNT; each match is signaled on OCy output One pulse mode: same as output compare, but disable after match PWM mode: TIMx_CCRy compared to TIMx_CNT CNT < CCRy => output active CNT CCRy => output inactive TIMx_CNT operates as discussed previously for periodic interrupt generation: - Signal update event and reset to 0 when CNT = ARR while counting up - Signal update event and reload ARR when CNT = 0 while counting down 16

Capture/Compare Mode Registers TIMx_CCMR1: bits 7:0 configure channel 1; bits 15:8/channel 2 TIMx_CCMR2 (TIM2-3-4): bits 7:0/channel 3; bits 15:8/channel 4 (reset values = all 0 s) Output mode -> Input mode** -> ** discussed later Output Compare 1 Mode 000 = frozen (no events) 001 = Set CH1 active* on match 010 = Set CH1 inactive* on match 011 = Toggle CH1 on match 100 = Force CH1 to inactive* (immediate) 101 = Force CH1 to active* (immediate) 110 = PWM mode 1 (active* to inactive*) 111 = PWM mode 2 (inactive* to active*) Capture/Compare 1 Select 00 = output 01 = input**: IC1 = TI1 10 = input**: IC1 = TI2 11 = input**: IC1 = TRC * Active/inactive levels selected in TIMx_CCER register 17

Capture/Compare Enable Register TIMx_CCER (reset value = all 0 s) Channel 1 15-12 11 8 7-4 CC4 CC3 CC2 bits bits bits CC1 Polarity If CC1 = output, CC1P selects: 0 = OC1 active high 1 = OC1 active low If CC1 = input: CC1NP/CC1P select capture trigger: 00: falling edge of input 01: rising edge of input 11: both edges of input CC1 Enable If CC1 = output: 1 = OC1 drives output pin 0 = OC1 does not drive output If CC1 = input: 1 = Capture enabled 0 = Capture disabled 18

Output Compare Mode Change output pin state or indicate when a period of time has elapsed When a match occurs (CCRx = CNT): Generate specified output on corresponding pin Set CCxIF = 1 (interrupt flag) in the SR Generate interrupt if configured (CCxIE = 1) 19

Pulse-Width Modulation (PWM) Mode Output pin (TIMx_CCRy) Duty Period (TIMx_ARR) Duty cycle = (Duty/Period) x 100% PWM by comparing TIMx_CNT to both TIMx_CCRy and TIMx_ARR Set TIMx_ARR = Period Set TIMx_CCRy = Duty TIMx_CCMRn (capture/compare mode) (n=1 for channels 1-2 / n=2 for channels 3-4): Set bits CCyS = 00 to select an output mode for channel y Set bits OCyM = 110 (PWM mode 1) active if CNT < CCRy, inactive otherwise OCyM = 111 (PWM Mode 2) - inactive if CNT < CCRy, active otherwise TIMx_CCER: Set bit CCyE = 1 to enable OCy to drive the output pin Set bit CCyP = 0/1 to select active level high/low (output polarity) of OCy Configure GPIO MODER and AF registers to select alt. function TIMx_CHy for the pin 20

PWM Signal Examples ARR=8 1 2 3 1 2 3 1 3 OCXREF always active 2 3 OCXREF always inactive 1. OCXREF active (high) when TIMx_CNT < TIMx_CCRx Assumes OCxM = 110 and CCxP = 1 2. OCXREF inactive (low) when TIMx_CNT TIMx_CCRx 3. Update Event when TIMx_CNT = TIMx_ARR (resets TIMx_CNT to 0) 21

Example: 20KHz PWM signal with 10% duty cycle on pin PB6 Configure TIM4, Channel 1 Since TIM4_CH1 = AF2 for pin PB6 Assume timer clock = 16MHz* and prescale = 1 PWM Period = 16MHz/20KHz = 800 = TIM4_ARR PWM Duty = 800 x 10% = 80 = TIM4_CCR1 Configure TIM4_CCMR1 bits: CC1S = 00 (make channel 1 an output) CC1M = 110 (PWM mode 1: active-to-inactive) Configure TIM4_CCER bits: CC1E = 1 to enable output OC1 to drive the pin CC1P = 0 to define OC1 as active high Configure PB6 as alternate function TIM4_CH1 Select AF mode for PB6 in GPIOB->MODER Select TIM4_CH1 (AF2) for PB6 in GPIOB->AFRL * What if timer clock = 2.097 MHz? (0x0020_0000 Hz) 22

Lab Procedure Generate a PWM waveform with timer TIM10 Period should be 1 ms (frequency 1 KHz) First, generate a waveform with one duty cycle value Then, verify that you can generate waveforms with each of the 11 specified duty cycles, from 0% to 100%, as selected by keypad keys 0 A. Measure and record the 11 duty cycle values Plot measured duty cycle vs. selection key # Repeat with PWM frequency = 100 Hz What needs to be changed? (Time permitting) Repeat with PWM frequency = 10 KHz 23