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

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

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

LM4: The timer unit of the MC9S12DP256B/C

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

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

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

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

Select the single most appropriate response for each question.

EE 308 Spring 2006 FINAL PROJECT: INTERFACING AND MOTOR CONTROL WEEK 1 PORT EXPANSION FOR THE MC9S12

Chapter 6 PROGRAMMING THE TIMERS

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

CHAPTER III THE FPGA IMPLEMENTATION OF PULSE WIDTH MODULATION

Using the Z8 Encore! XP Timer

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

ECE 4510/5530 Microcontroller Applications Midterm Review

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

Lab 5 Timer Module PWM ReadMeFirst

Topics Introduction to Microprocessors

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

MICROCONTROLLER TUTORIAL II TIMERS

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

EECS 270: Lab 7. Real-World Interfacing with an Ultrasonic Sensor and a Servo

Project Board Game Counter: Digital

Microprocessor & Interfacing Lecture Programmable Interval Timer

TKT-3500 Microcontroller systems


Exercise 3: Sound volume robot

Grundlagen Microcontroller Analog I/O. Günther Gridling Bettina Weiss

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

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

EXAMINATION PAPER EMBEDDED SYSTEMS 6EJ005 UNIVERSITY OF DERBY. School of Computing and Technology DATE: SUMMER 2003 TIME ALLOWED: 2 HOURS

EE 314 Spring 2003 Microprocessor Systems

HT1620 HT1621 HT1622 HT16220 HT1623 HT1625 HT1626 HT1627 HT16270 COM

ATmega16A Microcontroller

HW D2: Sequential Logic, Counters, Debounce

ECE251: Tuesday October 3 0

ELCT 912: Advanced Embedded Systems


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

Using the HT66F016L and the HT66F50 to Implement Remote Encoding and Decoding

Microcontroller: Timers, ADC

EE 308 Lab Spring 2009

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

1 Contents 2 2 Overview 3 3 Hardware Interface 4 4 Software Interface Register Map Interrupts 7

EE251: Thursday October 25

Design of double loop-locked system for brush-less DC motor based on DSP

IZ602 LCD DRIVER Main features: Table 1 Pad description Pad No Pad Name Function

Lecture 12 Timer Functions

EE445L Fall 2011 Quiz 2A Page 1 of 6

MM58174A Microprocessor-Compatible Real-Time Clock

INTERFACING WITH INTERRUPTS AND SYNCHRONIZATION TECHNIQUES

The SOL-20 Computer s Cassette interface.

MICROPROCESSORS A (17.383) Fall Lecture Outline

LSI/CSI LS7290 STEPPER MOTOR CONTROLLER. LSI Computer Systems, Inc Walt Whitman Road, Melville, NY (631) FAX (631)

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

Chapter 7: Systems for Frequency Generation

Written by Hans Summers Wednesday, 15 November :53 - Last Updated Wednesday, 15 November :07

DAC A (VCO) Buffer (write) DAC B (AGC) Buffer (write) Pulse Code Buffer (write) Parameter Buffer (write) Figure A.1. Receiver Controller Registers

Measuring Distance Using Sound

Interfacing Sensors & Modules to Microcontrollers

HT162X HT1620 HT1621 HT1622 HT16220 HT1623 HT1625 HT1626 COM

MCU Reset and Oscillator Circuits Application Note

A Programmable Clock Generator Based on Xilinx CoolRunner

HT162X HT1620 HT1621 HT1622 HT16220 HT1623 HT1625 HT1626 COM

I2C Encoder. HW v1.2

Electric Bike BLDC Hub Motor Control Using the Z8FMC1600 MCU

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

S3C9442/C9444/F9444/C9452/C9454/F9454

Application Note. Introduction. AN2219/D Rev. 0, 12/2001. Using PLL to Indicate Oscillator Start-Up Performance during Power On Reset

HT1621. HT1621 RAM Mapping 32x4 LCD Controller for I/O MCU

Microcontrollers: Lecture 3 Interrupts, Timers. Michele Magno

Laboratory Exercise 1 Microcontroller Board with Driver Board

Block Diagram , E I F = O 4 ) + J H 6 E E C + E H? K E J +,, H E L A H * E = I + E H? K E J + + % 8,, % 8 +, * * 6 A. H A G K A? O

I hope you have completed Part 2 of the Experiment and is ready for Part 3.

XGATE Library: PWM Driver Generating flexible PWM signals on GPIO pins

CSE 3215 Embedded Systems Laboratory Lab 5 Digital Control System

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

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

Castle Creations, INC.

STELLARIS ERRATA. Stellaris LM3S8962 RevA2 Errata

Built-in LCD display RAM Built-in RC oscillator

R/W address auto increment External Crystal kHz oscillator

EE 308 Spring 2013 The MC9S12 Pulse Width Modulation System

Houngninou 2. Abstract

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

DASL 120 Introduction to Microcontrollers

8253 functions ( General overview )

Design and Construction of PIC-based IR Remote Control Moving Robot

HD44102D. (Dot Matrix Liquid Crystal Graphic Display Column Driver) Features. Description. Ordering Information

PCF2129 Integrated RTC/TCXO/Crystal

Programming and Interfacing

CS/ECE/EEE/INSTR F241 MICROPROCESSOR PROGRAMMING & INTERFACING MODULE 8: I/O INTERFACING QUESTIONS ANUPAMA KR BITS, PILANI KK BIRLA GOA CAMPUS

PATENTED. PAT No. : HT1622/HT1622G RAM Mapping 32 8 LCD Controller for I/O MCU. Features. General Description.

ZKit-51-RD2, 8051 Development Kit

ENGR-2300 Electronic Instrumentation Quiz 3 Spring Name: Solution Please write you name on each page. Section: 1 or 2

First Optional Homework Problem Set for Engineering 1630, Fall 2014

DTMF receiver for telephones

logic system Outputs The addition of feedback means that the state of the circuit may change with time; it is sequential. logic system Outputs

Graphical Control Panel User Manual

Transcription:

Hardware Flags and the RTI system 1

Need for hardware flag Often a microcontroller needs to test whether some event has occurred, and then take an action For example A sensor outputs a pulse when a model train approaches a crossing The MCU must sense this pulse and then lower the crossing gate sensor MCU To make sure that it doesn t miss the input pulse, the MCU must continually read the input signal very rapidly This means that it can t do anything else (e.g., sensing and controlling other gates) 2

Hardware flag Instead of continuously reading an input signal, it is much more efficient to have the input signal set a hardware flag (i.e., a flip-flop) Then the MCU can occasionally read the flip-flop and tell that the event occurred it doesn t have to catch the input pulse when it happens No need to rapidly poll the input V DD (ie, logic 1) D flip-flop D Q Computer tests flag Device sets flag (on rising edge of input signal) CLR Computer clears flag We assert CLR to force the flip-flop to zero (this is an asynchronous control input) 3

Timing for the two methods Rapidly polling input signal read signal detect signal time n input set? y output control signal Occasionally polling hardware flag flag set? y n do other useful things read flag detect flag time output control signal clear flag 4

Recall that input/output ports are assigned to memory addresses Input is done by reading to that address Output is done by writing to that address A hardware flag looks like a bit in a memory location You can sense whether the flag is set by reading that bit You can clear the flag by writing to that bit Memory mapped IO 5

Flag Reading and Clearing You read a flag by reading the bit from the data bus If a read occurs to that address, signal R/W is set to 1 V DD D Q Data bus Event signal CLR You clear a flag by writing a 1 to that bit on the data bus If a write occurs to that address, signal R/W is set to 0 R/W Note: you clear a flag (ie, set it to zero) by writing a 1 to it (nonintuitive!) 6

Timer flags Flags are set by many kinds of events Some are caused externally (e.g., by an input signal) Others are caused internally Timers are an example of an internal event A counter automatically counts up every clock tick When it reaches a certain value, a flag is set This is a much better way to estimate time than using delay loops! Doesn t waste (as many) CPU cycles Can be more accurate 7

Example: RTI System Real Time Interrupt (RTI) system provides a periodic timer Clock divider is set in register RTICTL The period (in units of OSCCLK cycles) is determined by bits RTR0..RTR6 when timeout occurs, the RTIF flag (a flipflop) is set RTIF Counter RTR6:RTR0 Frequency divider RTICTL OSCCLK reset: 7 6 5 4 3 2 1 0 0 RTR6 RTR5 RTR4 RTR3 RTR2 RTR1 RTR0 0 1 0 0 0 0 0 0 Figure 6.16 CRG RTI control register (RTICTL) 8

N The period (in units of OSCCLK cycles) is (N+1)*2 (M+9), where N is the bit field RTR3 through RTR0 Table 6.4 RTI interrupt period (in units of OSCCLK cycle) RTR[3:0] 0000 ( 1) 0001( 2) 0010 ( 3) 0011 ( 4) 0100 ( 5) 0101 ( 6) 0110 ( 7) 0111 ( 8) 1000 ( 9) 1001 ( 10) 1010 ( 11) 1011 ( 12) 1100 ( 13) 1101 ( 14) 1110 ( 15) 1111 ( 16) M is the bit field RTR6 through RTR4 000 (off) 001 (2 10 ) 2 10 2 2 10 3 2 10 4 2 10 5 2 10 6 2 10 7 2 10 8 2 10 9 2 10 10 2 10 11 2 10 12 2 10 13 2 10 14 2 10 15 2 10 16 2 10 010 (2 11 ) 2 11 2 2 11 3 2 11 4 2 11 5 2 11 6 2 11 7 2 11 8 2 11 9 2 11 10 2 11 11 2 11 12 2 11 13 2 11 14 2 11 15 2 11 16 2 11 RTR[6:4] 011 (2 12 ) 2 12 2 2 12 3 2 12 4 2 12 5 2 12 6 2 12 7 2 12 8 2 12 9 2 12 10 2 12 11 2 12 12 2 12 13 2 12 14 2 12 15 2 12 16 2 12 M 100 (2 13 ) 2 13 2 2 13 3 2 13 4 2 13 5 2 13 6 2 13 7 2 13 8 2 13 9 2 13 10 2 13 11 2 13 12 2 13 13 2 13 14 2 13 15 2 13 16 2 13 101 (2 14 ) 2 14 2 2 14 3 2 14 4 2 14 5 2 14 6 2 14 7 2 14 8 2 14 9 2 14 10 2 14 11 2 14 12 2 14 13 2 14 14 2 14 15 2 14 16 2 14 110 (2 15 ) 2 15 2 2 15 3 2 15 4 2 15 5 2 15 6 2 15 7 2 15 8 2 15 9 2 15 10 2 15 11 2 15 12 2 15 13 2 15 14 2 15 15 2 15 16 2 15 111 (2 16 ) 2 16 2 2 16 3 2 16 4 2 16 5 2 16 6 2 16 7 2 16 8 2 16 9 2 16 10 2 16 11 2 16 12 2 16 13 2 16 14 2 16 15 2 16 16 2 16 M=0 means RTI off 9

RTI Flag CRGFLG register RTIF is bit 7 of CRGFLG Check this bit to see if a timeout has occurred Reset the flag by writing a 1 to that bit 7 6 5 4 3 2 1 0 RTIF - - - - - - - reset 0 0 0 0 0 0 0 0 CRGFLG Register There are other flags in bits 6:0... their names aren t shown 10

A note about clocks An external crystal is used to generate a square wave called OSCCLK In our board it is 8 MHz This goes into a phase-locked loop (PLL) circuit which increases the frequency to 48 MHz makes it stable (v.s. jitter, skew, etc) The PLL clock is divided by 2 to make the 24 MHz E-clock But the RTI system uses the original 8 MHz OSCCLK OSCCLK (8 MHz) E-clock (24 MHz) Colpitts oscillator circuit 11

Example Set up the RTI system to generate periodic timeouts at intervals of approximately 0.01 second 12

Example Set up the RTI system to generate periodic timeouts at intervals of approximately 0.01 second Solution: The desired frequency of timeouts is 100 Hz We want to get the 8 MHz OSCCLK frequency down to 100 Hz So divide by a factor of 8 MHz/100 Hz = 80000 80000 is 10*8000, and 8000 is about 2^13 We can get this by setting N=9, M=4 So RTR[3:0] = 9, RTR[6:4] = 4 Code: RTICTL = 0x49; 0x49 in binary is 01001001 13

Example N = 1001 2 = 9 10 Table 6.4 RTI interrupt period (in units of OSCCLK cycle) RTR[3:0] 0000 ( 1) 0001( 2) 0010 ( 3) 0011 ( 4) 0100 ( 5) 0101 ( 6) 0110 ( 7) 0111 ( 8) 1000 ( 9) 1001 ( 10) 1010 ( 11) 1011 ( 12) 1100 ( 13) 1101 ( 14) 1110 ( 15) 1111 ( 16) 000 (off) 001 (2 10 ) 2 10 2 2 10 3 2 10 4 2 10 5 2 10 6 2 10 7 2 10 8 2 10 9 2 10 10 2 10 11 2 10 12 2 10 13 2 10 14 2 10 15 2 10 16 2 10 010 (2 11 ) 2 11 2 2 11 3 2 11 4 2 11 5 2 11 6 2 11 7 2 11 8 2 11 9 2 11 10 2 11 11 2 11 12 2 11 13 2 11 14 2 11 15 2 11 16 2 11 RTR[6:4] 011 (2 12 ) 2 12 2 2 12 3 2 12 4 2 12 5 2 12 6 2 12 7 2 12 8 2 12 9 2 12 10 2 12 11 2 12 12 2 12 13 2 12 14 2 12 15 2 12 16 2 12 100 (2 13 ) 2 13 2 2 13 3 2 13 4 2 13 5 2 13 6 2 13 7 2 13 8 2 13 9 2 13 10 2 13 11 2 13 12 2 13 13 2 13 14 2 13 15 2 13 16 2 13 M = 100 2 = 4 10 101 (2 14 ) 2 14 2 2 14 3 2 14 4 2 14 5 2 14 6 2 14 7 2 14 8 2 14 9 2 14 10 2 14 11 2 14 12 2 14 13 2 14 14 2 14 15 2 14 16 2 14 110 (2 15 ) 2 15 2 2 15 3 2 15 4 2 15 5 2 15 6 2 15 7 2 15 8 2 15 9 2 15 10 2 15 11 2 15 12 2 15 13 2 15 14 2 15 15 2 15 16 2 15 111 (2 16 ) 2 16 2 2 16 3 2 16 4 2 16 5 2 16 6 2 16 7 2 16 8 2 16 9 2 16 10 2 16 11 2 16 12 2 16 13 2 16 14 2 16 15 2 16 16 2 16 14

Example What s the slowest period for the RTI system, assuming a 8 MHz OSC clock? 15

Example What s the slowest period for the RTI system, assuming a 8 MHz OSC clock? Solution: From the table, 16*(2^16) is the slowest period This is 2^20, or about 10^6 cycles At 0.125 us per cycle, this is 0.125 sec So we get about 8 timeouts per second 16

Example - heartbeat Flash an LED at a rate of about 1 per second I.e., turn on for one second, then turn off for 1 sec This is kind of a heartbeat indicator by which you can tell your program is running The slowest RTI timeout rate is 8/second So we only want to take an action every 8 th timeout We will have to keep a count of timeouts Every time we sense a timeout, we increment the counter When the counter reaches 8, we reset the counter to zero and toggle the LED PT0 17

Example - heartbeat (continued) Psuedocode Set up PT0 for output Set up RTI rate for slowest rate initialize count = 0 while (true) while (RTIF is clear) do nothing clear RTIF by writing a 1 to it increment count end if count = 8 toggle PT0 count = 0 end 18

C code Example - heartbeat (continued) int count = 0; DDRT = 0x01; // Set up PT0 for output RTICTL = 0x7f; // Set up slowest RTI rate while (1) { while (!(CRGFLG & 0x80)) ; // wait till RTIF set // Clear RTIF by writing a 1 to it. // Writing 0 s to other flag bits doesn t affect them. // Don t do CRGFLG = 0x80; this will clear other flags CRGFLG = 0x80; } count++; if (count == 8) { PTT ^= 0x01; count = 0; } // toggle PT0 19

Example wag tail Assume PWM channel 4 is set up to control a servo motor, such that duty = 10 moves the motor all the way left, and duty = 20 moves the motor all the way right. Gradually move the motor from all the way left to all the way right over a period of about 20 seconds. Approach: We ll use the RTI system to generate timeouts every ~0.125 seconds (i.e., 8 per second). We will need to increment the duty cycle 10 times over 20 seconds. Or, increment it once every 2 seconds. Each RTI timeout occurs about 0.125 seconds, so in 2 seconds we have 2.0/0.125= 16 timeouts Every 16 th timeout, increase the PWM duty cycle a little more 20

Example wag tail (continued) // Some code to set up PWM channel 4 follows... // : // Set up RTI system to generate timeouts at the slowest rate. The period // is about 0.125 seconds. RTICTL = 0x7f; // longest possible period // We will need to increment the duty cycle 10 times over 20 seconds. // Or, increment it once every 2 seconds. Each RTI timeout occurs // every 0.125 seconds, so in 2 seconds we have 2.0/0.125 = 16 timeouts. PWMDTY4 = 10; for (i=0; i<10; i++) { for (j=0; j<16; j++) { while (!(CRGFLG & 0x80)) ; } CRGFLG = 0x80; } PWMDTY4++; // wait for RTI timeout // Clear RTIF by writing a 1 to it // increment duty time 21

Summary / Questions A hardware flag is just a flip-flop. When an event occurs (i.e., a signal is received), the flag is set. Then the computer can read the flag later and see that the event had occurred. An example of a system that sets a hardware flag is the RTI system. It is just a periodic timer. Why is the flag system better than just directly sensing the event, for example by continuously reading an input pin? 22