LM4: The timer unit of the MC9S12DP256B/C

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

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

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

Page 1. So Far. Usage Examples. Input Capture Basics. Familiar with CS/ECE 6780/5780. Al Davis. Trigger interrupts on rising/falling/both edges

Chapter 6 PROGRAMMING THE TIMERS

The MC9S12 Pulse Width Modulation System. Pulse Width Modulation


Lecture 12 Timer Functions

Lab 5 Timer Module PWM ReadMeFirst

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

EE 308 Spring 2013 The MC9S12 Pulse Width Modulation System

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

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

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

µtasker Document µtasker Hardware Timers

Using the Z8 Encore! XP Timer

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

MICROCONTROLLER TUTORIAL II TIMERS

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

A MORON'S GUIDE TO TIMER/COUNTERS v2.2. by

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

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

ATmega16A Microcontroller

ME 461 Laboratory #2 Timers and Pulse-Width Modulation

University of Texas at El Paso Electrical and Computer Engineering Department

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

Houngninou 2. Abstract

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

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

Page 1/10 Digilent Analog Discovery (DAD) Tutorial 6-Aug-15. Figure 2: DAD pin configuration

Controlling DC Brush Motor using MD10B or MD30B. Version 1.2. Aug Cytron Technologies Sdn. Bhd.

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

ME 461 Laboratory #5 Characterization and Control of PMDC Motors

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

INTERFACING WITH INTERRUPTS AND SYNCHRONIZATION TECHNIQUES

Microcontroller: Timers, ADC

ELCT 912: Advanced Embedded Systems

ECE 4510/5530 Microcontroller Applications Midterm Review

Microprocessor & Interfacing Lecture Programmable Interval Timer

VORAGO Timer (TIM) subsystem application note

Exercise 3: Sound volume robot

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

Table 1: Cross Reference of Applicable Products. INTERNAL PIC NUMBER Arm Cortex M0+ UT32M0R PWM Module QS30

Design and build a prototype digital motor controller with the following features:

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

PSoC Academy: How to Create a PSoC BLE Android App Lesson 9: BLE Robot Schematic 1

AN913 APPLICATION NOTE

Course Introduction. Purpose: Objectives: Content: 24 pages 3 questions. Learning Time: 35 minutes

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

Hello, and welcome to this presentation of the STM32L4 comparators. It covers the main features of the ultra-lowpower comparators and some

Graphical Control Panel User Manual

AN2581 Application note

Designing with a Microcontroller (v6)

Module: Arduino as Signal Generator

Timer/Counter with PWM

EIE/ENE 334 Microprocessors

Measuring Distance Using Sound

2014 Paper E2.1: Digital Electronics II

Topics Introduction to Microprocessors

EE445L Fall 2011 Quiz 2A Page 1 of 6

EE251: Thursday October 25

Motor Control Demonstration Lab

Portland State University MICROCONTROLLERS

Jaguar Motor Controller (Stellaris Brushed DC Motor Control Module with CAN)

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

Motor Control using NXP s LPC2900

Mechatronics Laboratory Assignment 3 Introduction to I/O with the F28335 Motor Control Processor

Low Energy Timer. AN Application Note. Introduction

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

Unit-6 PROGRAMMABLE INTERRUPT CONTROLLERS 8259A-PROGRAMMABLE INTERRUPT CONTROLLER (PIC) INTRODUCTION

8-bit Microcontroller with 512/1024 Bytes In-System Programmable Flash. ATtiny4/5/9/10

Generating DTMF Tones Using Z8 Encore! MCU

Project Final Report: Directional Remote Control

Exercise 5: PWM and Control Theory

Microcontrollers and Interfacing

HC08 SCI Operation with Various Input Clocks INTRODUCTION

EVDP610 IXDP610 Digital PWM Controller IC Evaluation Board

Product Family: 05, 06, 105, 205, 405, WinPLC, Number: AN-MISC-021 Terminator IO Subject: High speed input/output device

RL78 Motor Control. YRMCKITRL78G14 Starter Kit. Renesas Electronics Europe. David Parsons Application Engineering Industrial Business Group.

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

PSoC 4 Timer Counter Pulse Width Modulator (TCPWM)

AC Induction Motor (ACIM) Control using a Digital Signal Controller (DSC)

CS/ECE 6780/5780. Al Davis. Today s topics: Output capture Pulse Width Modulation Pulse Accumulation all useful options for Lab7 1 CS 5780

Select the single most appropriate response for each question.

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

CMOS Serial Digital Pulse Width Modulator INPUT CLK MODULATOR LOGIC PWM 8 STAGE RIPPLE COUNTER RESET LOAD FREQUENCY DATA REGISTER

EE445L Fall 2014 Quiz 2A Page 1 of 5

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

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

ME 6405 Introduction to mechatronics Fall Slide 1. Introduction Timer? Usage Electronics HC11 Conclusion. Timers

For reference only Refer to the latest documents for details

RX23T inverter ref. kit

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

Analog-to-Digital Converter. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

CHAPTER 4 CONTROL ALGORITHM FOR PROPOSED H-BRIDGE MULTILEVEL INVERTER

Timer A. Last updated 8/7/18

Microcontrollers: Lecture 3 Interrupts, Timers. Michele Magno

MICROPROCESSOR TECHNICS II

ECE251: Tuesday October 3 0

Transcription:

Objectives - To explore the Enhanced Capture Timer unit (ECT) of the MC9S12DP256B/C - To program a real-time clock signal with a fixed period and display it using the onboard LEDs (flashing light) - To produce a timing engine for a digital control application with a fixed sample rate of 1 khz Introduction Timers, counters as well as capture-and-compare mechanisms are fundamental to many microcontroller based mechatronics applications. For example, the drive system of a mobile robot often consists of a pair of DC-motors driven by Pulse Width Modulated (PWM) signals. Many microcontrollers therefore support the generation of these kinds of signals by incorporating specialist PWM units. The MC9S12DP256B/C includes an 8-channel PWM unit (Figure LM4-1). Figure LM4-1 The PWM unit of the MC9S12DP256B/C The operating principle of such a PWM unit is rather simple: A counter register is incremented with every falling edge (or rising edge or both) of the system bus clock signal. Upon reaching a first threshold an associated output pin is set high (or low) 1

and/or an interrupt is triggered. This threshold defines the duty cycle of the PWM signal (cf. Figure LM4-2). The counter register continues to be incremented until a second threshold is reached. This second threshold defines the period of the PWM signal. Upon reaching the period threshold, the associated pin is toggled again and the counter register is reset to zero. Altogether, this produces a square wave signal of a predefined period and with a programmable on/off phase (i. e. a PWM signal). counter 0xFFFF threshold 2 (period) threshold 1 (duty cycle) 0x0000... OFF ON... t 0 t 1 t 0 + T t Figure LM4-2 Generating PWM signals In this exercise we are going to program an internal timing signal with a fixed period. This is very similar to setting up a PWM unit. Most of the above described operating principle remains valid with the exception that we won t bother with setting up a duty cycle all we are interested in at this stage is the period of our timer signal. We will thus have to configure the Enhanced Capture Timer unit (ECT) to run at a fixed rate and to trigger an interrupt every time a pre-programmed counter value (period) is reached. To test our timer, we will install a simple interrupt service routine in which we will toggle one of the digital I/O pins. This produces a square wave signal with a period of two timer periods (one timer period for the on-phase, one timer period for the off-phase ջ two timer periods). The correct shape and period of this square wave signal will be verified using an oscilloscope. The Enhanced Capture Timer (ECT) unit Open the user guide of the Enhanced Capture Timer unit (ECT_18B8C.pdf) and familiarize yourself with the block diagram of this unit (Figure LM4-3). The basic timer consists of a 16-bit software-programmable up-counter, driven by a pre-scaled clock signal. In normal mode the timer keeps running until it is switched off explicitly. There also exists a modulus down counter. This type of counter decrements an associated counter register until it reaches 0x0000 (underflow), whereupon the initial starting value 2

is reloaded. The modulus down counter is therefore well-suited to the generation of fixed-period time base signals. Figure LM4-3 Block diagram of the ECT unit of the MC9S12DP256B/C One constraint of any timer application is the maximum period which can be achieved. This depends on two factors, namely the size of the counter register (here: 16 bit) as well as the maximum pre-scale divider. The latter is used to slow down the commonly very high bus clock frequency (here: 24 MHz). The slower the effective timer clock frequency, the longer periods we can realise. Figure LM4-4 shows the prescaler section of the ECT unit. It seems that the main timer can be run at a minimum timer clock frequency of f bus /128 = (24 10 6 )/128 Hz = 187.5 khz. The frequency of the modulus down counter, on the other side, can only be slowed down to f bus /16 = (24 10 6 )/128 Hz = 1.5 MHz. This means that the main timer can be used for periods of up to 0xFFFF x 1/(187.5 10 6 ) = 65535 x 1/(187.5 10 6 ) 0.35 seconds, whereas the modulus down counter only reaches 65535 x 1/(1.5 10 6 ) 43.7 ms. Figure LM4-4 Prescaler section of the ECT 3

Table LM4-1 lists all achievable periods for both the main timer as well as the 16-bit modulus down counter. Main timer Modulus down timer Prescaler Resolution Maximum period Resolution Maximum period 1 42 ns 2.73 ms 42 ns 2.73 ms 2 84 ns 5.46 ms 84 ns 5.46 ms 4 167 ns 10.9 ms 167 ns 10.9 ms 8 333 ns 21.8 ms 333 ns 21.8 ms 16 667 ns 43.7 ms 667 ns 43.7 ms 32 1.33 s 87.4 ms - - 64 2.67 s 174.8 ms - - 128 5.33 s 349.5 ms - - Table LM4-1 Programmable periods of the ECT As we would like to test our timer by flashing the on-board LED (PB0) we should try to make it run as slowly as possible. The maximum achievable period is 349.5 ms (circa 1/3 of a second). This should be sufficiently slow to be able to discern a distinct onphase followed by an equally long off-phase. We therefore choose to program the main timer to a period of 349.5 ms (counter value 0xFFFF). For a general function description of the ECT unit see chapter 4 of the corresponding user guide. Note: Even slower signals can be produced when reducing the bus clock frequency (default: 24 MHz). This can be done by reprogramming the phase locked loop (PLL) circuit within the Clock and Reset Generator (CRG) unit of the microcontroller. However, a slower running system will also need more time to evaluate an expression such as a transfer function or a filter equation. Implementation To implement a fixed period time base on the MC9S12DP256B/C we can make use of the automatic reload mechanism of timer channel 7 in output compare mode. To configure the ECT for this mode of operation we will have to set-up the following registers: (1) TIOS Timer Input Capture / Output Compare Setup register. This register determines whether a timer channel is used in input capture or output compare mode. Set-up channel 7 for output compare mode. (2) As we don t want to affect the output pins associated with timer channel 7 we will have to ensure that the output logic is switched off. Have a look at the Timer Control registers (TCTL1, TCTL2) as well as at the Output Compare 7 Mask register (OC7M) to find out how this can be done. Note that, depending on the reset value of a register, you may or may not have to modify anything. (3) The prescaler value will have to be programmed (Timer System Control Register 2, TSCR2). This register also allows you to enable the automatic resetting of the main timer register when a match occurs between the current value of the main timer register and the value programmed the timer register of in channel 7. Look for a bit called TCRE. 4

(4) The Timer Input Capture / Output Compare register of channel 7 (TC7) will have to be initialised to its maximum value of 0xFFFF. (5) The Timer Interrupt Enable Register (TIE) will certainly have to be initialised so that our interrupt service routine can be called. (6) Finally, the timer needs to be switched on by setting the Timer Enable Bit (TEN) in the Timer System Control Register 1 (TSCR1). Create an empty project based on stationery Dragon12_flat. Create the new source file timer.c and add it to project group Sources. Create a corresponding header file timer.h and add this to the same group. To save you some time, I ve uploaded a skeleton project onto myuni: Mechatronics IIIM ջ Course Documents ջ Tutorials ջ 9S12 ջ timer_interrupt Write a function TOC7_Init which sets up the ECT timer channel 7 for output compare mode. Write an interrupt service routine for channel 7 timer interrupt C7I. This ISR should toggle bit 0 of port B (connected to the on-board LED of the Dragon12). Don t forget to acknowledge the interrupt by clearing the appropriate flag in the Main Timer Interrupt Flag register (TFLG1). Install your interrupt service routine in the interrupt vector table (isr_vectors.c). Your main program should set-up port B as output (configure DDRB), call upon the initialisation routine TOC7_Init allow all interrupts to happen (asm cli) and finally enter an infinite loop in which it does nothing in particular ( for(;;); or while(1); ). Download and debug your program using the Hi-Wave debugger. Extension Modify your program to produce a square wave with a period of 1 khz and a 50% duty cycle (0.5 ms on, 0.5 ms off). The signal should be made available on pin 0 of port A. You will have to choose a suitable prescaler value (see Table LM4-1) as well as the corresponding threshold value to be written into the Timer Input Capture / Output Compare register of channel 7 (TC7). Verify your 1 khz timing engine using an oscilloscope. Can you see how the techniques introduced in this laboratory session can be used to implement a digital control system? 5