Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Similar documents
Timer1 Capture Mode:

ECE Homework #10

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

More Fun with Timer Interrupts

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

Speed Control of a DC Motor using Digital Control

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Using Timers of Microchip PIC18F Microcontrollers

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

EE 361L Digital Systems and Computer Design Laboratory

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Interrupts on PIC18F252 Part 2

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

These 3 registers contain enable, priority,

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

Section 14. Timer1 HIGHLIGHTS. Timer1. This section of the manual contains the following major topics:

Flow Charts and Assembler Programs

The MCU s Pulse. Internal clock or oscillator to synchronize operation. One clock cycle = 1 TOSC = 1/fOSC. t TOSC

Capture Mode of Pic18F252

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Timer 32. Last updated 8/7/18

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

Interrupts. Embedded Systems Interfacing. 08 September 2011

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Contents. PIC Mini Data Sheets

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

EE 308 Spring Exam 1 Feb. 27

The MC9S12 Timer Input Capture Function

Accurate Time and Interrupts

Lecture (03) PIC16F84 (2)

Embedded System Design

SRF08 Ultra sonic range finder

Tel: Fax:

Analog Output with a Digital to Analog Converter

Team 8: Robert Blake Craig Goliber Alanna Ocampo

The MC9S12 Timer Output Compare Function Making an event happen at specific time on the HC12 The MC9S12 Output Compare Function

Capturing the Time of an External Event Input Capture Subsystem

TIMSK=0b ; /* enables the T/C0 overflow interrupt in the T/C interrupt mask register for */

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

What happens when an HC12 gets in unmasked interrupt:

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

Chapter 11: Interrupt On Change

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

Relay. bit4 bit5 bit6 bit7

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

ME 6405 Introduction to Mechatronics

Human Response Timer

The MC9S12 Input Capture Function

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

Binary Outputs and Timing

NOTICE: 1, the timing for Start, Stop, ACK, NACK, write and read is same as I2C

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

ELEG3923 Microprocessor Ch.9 Timer Programming

Embedded Systems Module. 6EJ505. C Tutorial 3: using the ICD3 rev tjw

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

BME 361 Biomeasurement Laboratory Demonstration Biomedical Engineering Program University of Rhode Island June 10, 2015

Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz III

Department of EIE / Pondicherry Engineering College. Timer/Counters. Department of EIE / Pondicherry Engineering College 1

Basic Embedded Software C Review Using MPLAB SIM. Loops. Embedded Systems Interfacing. 25 August 2011

Using Input Capture on the 9S12

Simon. Final Project Report December 11, 2009 E155. Julia Karl and Kirsten McAfee

Measuring Duty Cycles with an Intel MCS-51 Microcontroller

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 F²MC-FR FAMILY 32-BIT MICROCONTROLLER MB91460 RELOAD TIMER APPLICATION NOTE

PIC Discussion By Eng. Tamar Jomaa

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

UBC104 Embedded Systems. Review: Introduction to Microcontrollers

Microcontroller Overview

CENG-336 Introduction to Embedded Systems Development. Timers

Lecture (04) PIC 16F84A programming I

Kit Contents. Getting Started Kits. Board. Board

ELCT 912: Advanced Embedded Systems

dspic Interrupts The Interrupt Control and Staus Registers are :- ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 1

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2013

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

80C51 Block Diagram. CSE Overview 1

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

Remote Controlled KitchenAid Mixer for the Clients at ADEC. Appendices. Arnaud Bacye Karina Dubé Justin Erman Matthew Martin

Introduction to the MC9S12 Hardware Subsystems

Embedded programming, AVR intro

Embedded Systems and Software

LCD. Configuration and Programming

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 FR FAMILY 32-BIT MICROCONTROLLER MB91460 REAL TIME CLOCK APPLICATION NOTE

ECE Homework #3

The new HP-01. Inside the HP-01

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

Chapter 09. Programming in Assembly

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

The University of Texas at Arlington Lecture 21_Review

Systems Programming. Lecture 11 Timers

8051 Timers. Class 7 EE4380 Fall Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Transcription:

Timer0..Timer3 Timers are pretty useful: likewise, Microchip provides four different timers for you to use. Like all interrupts, you have to Enable the interrupt, Set the conditions of the interrupt, and then Do something when the interrupt happens (check the interrupt flag) These hoops are summarized in the following table for all four timer interrupts. Interrupt Description Input Conditions Enable Flag Timer 0 Trigger after N events N = 1.. 2 24 100ns to 1.67 sec RA4: TOCS = 1 TMR0IF Timer 1 Timer2 Trigger after N events N = 1.. 2 19 100ns to 0.52 sec Interupt every N clocks (OSC/4) N = 1.. 65,535 100ns to 6.55ms OSC/4: TOCS = 0 RC0 TMR1CS = 1 OSC/4 TMR1CS = 0 OSC/4 N = (PS)(Y) T0CON = 0x88: PS = 1 T0CON = 0x80: PS = 2 T0CON = 0x81: PS = 4 T0CON = 0x82: PS = 8 T0CON = 0x83: PS = 16 T0CON = 0x84: PS = 32 T0CON = 0x85: PS = 64 T0CON = 0x86: PS = 128 T0CON = 0x87: PS = 256 TMR0 = -Y N = (PS)(Y) T1CON = 0x81: PS = 1 T1CON = 0x91: PS = 2 T1CON = 0xA1: PS = 4 T1CON = 0xB1: PS = 8 TMR1 = -Y N = A * B * C A = 1..16 (T2CON 3:6) B = 1..256 (PR2) C = 1, 4, 16 (T2CON 0:1) TMR0ON = 1 TMR0IE = 1 TMR0IP = 1 TMR1ON = 1 TMR1IE = 1 TMR1IP = 1 T2E = 1 TMR2IE = 1 TMR1IF TMR2IF Timer 3 Trigger after N events N = 1.. 2 19 100ns to 0.52 sec RC1 TMR3CS = 1 OSC/4 TMR3CS = 0 N = (PS)(Y) T3CON = 0x81: PS = 1 T3CON = 0x91: PS = 2 T3CON = 0xA1: PS = 4 T3CON = 0xB1: PS = 8 TMR3 = -Y TMR3ON = 1 TMR3IE = 1 TMR3IP = 1 TMR3IF Timer0, Timer1, and Timer3 are slightly different than Timer2. Each of these three are very similar, so let's take Timer0 for example. The input to Timer0 can be either the on-board clock (10MHz) or an external pin. This lets you interrupt every N edges for an external event or every N clocks. The input goes to a frequency divider, PS, which drops the frequency by 2 N for N = 0 to 8. The output of the divider then goes to a 16-bit counter, TMR0. When the counter wraps around from 0xFFFF to 0x0000, a Timer0 interrupt is triggered. 10MHz Clock T0CS=0 PS TMR0 RA4 T0CS=1 1,2,4,..,256 16-bit counter Interupt when TMR0 goes from 0xFFFF to 0x0000 Timer0 Interrupt is triggered every 100 to 2 24 clocks (1.67 seconds) JSG - 1 -

Default Timer0 Rate with PS = 1: For example, turn on Timer0 With a prescalar of 1 And toggle RC0 every interrupt When Timer0 interrupts, you know that TMR0 = 0x0000 Wrap around is what triggers the interrupt. The next interrupt won't happen again for another 65,536 clocks (216 counts). This results in Timer0 interrupting every 6.5536ms (the default rate for Timer0). if (TMR0IF) // Main Routine void main(void) TRISA = 0; TRISB = 0; TRISC = 0; TRISD = 0; ADCON1 = 0x0F; // set up Timer0 with PS = 1 T0CS = 0; T0CON = 0x88; TMR0ON = 1 TMR0IE = 1 TMR0IP = 1 // turn on all interrupts GIE = 1; // Do nothing. Interrupts do all the work. while(1) PORTB = PORTB + 1; JSG - 2 -

Signal at RC0: Default Timer0 Interrupt Rate with PS = 1: 65,536 Clocks Timer0 Interrupt every 1ms Example 2: Change the interrupt service routine to if (TMR0IF) TMR0 = -10000; Timer0 with N = 10,000 (1.00 ms) JSG - 3 -

When Timer0 interrupts, TMR0 = 0x0000. Wrapping around to zero is what causes the interrupt. By changing TMR0 to -10,000, you are setting up the next interrupt to happen 1ms in the future (10,000 clocks). This results in RC0 toggling every 10,000 clocks. Measuring the time it takes to trigger an interrupt: Actually, TMR0 toggles every 10,000 clocks - plus however many clocks it takes to trigger the interrupt and get to that line of code. To see how long this takes, the following code is used: unsigned int N = 100; if (TMR0IF) TMR0 = -N; You would expect RC0 to toggle every 100 clocks (N = 100). Actually, it toggles every 150 clocks (15us). This tells you it takes about 50 clocks to trigger an interrupt. Timer0 with N = 100. RC0 toggles every 150 clocks - telling you that it takes 50 clocks to call the interrupt. JSG - 4 -

Playing Note D5: 587.33Hz Example 3: Generate the note D5 (587.33Hz) on RC0. The number of clocks between interrupts should be N = 10,000,000 2 Hz = 8513.1017 Change the previous code to: unsigned int N = 8513-50; if (TMR0IF) TMR0 = -N; and you get almost the exact frequency you wanted. Timer0 interrupts are way easier that Timer2 interrupts (or figuring out the timing using assembler). Timer0 with N = 8513-50 (587.33Hz) JSG - 5 -

Measuring Time to 100ns You can also use Timer0 to measure time to 100ns. For example, measure the time of the routine Wait_ms(1000); Here you have a problem: the longest time TMR0 can measure is 6.55ms (65,536 clocks). To measure longer times, create a 32-bit counter: The low 16-bits are TMR0 The high 16-bits are stored in a variable, TIME Every Timer0 interrupt, add 0x10000 to TIME (one Timer0 overflow). In the main routine then Record the time before calling Wait_ms(1000) Record the time after call it, and Take the difference. Note that you also have to modify the LCD_Out() routine to display long integers (changes in red) LCD Routine (modified) void LCD_Out(unsigned long int DATA, unsigned char N) unsigned char A[10], i; for (i=0; i<10; i++) A[i] = DATA % 10; DATA = DATA / 10; for (i=10; i>0; i--) if (i == N) LCD_Write('.'); LCD_Write(A[i-1] + '0'); Interrupt Service Routine: unsigned long int TIME; if (TMR0IF) TIME = TIME + 0x10000; Main Routine: Main loop while(1) TIME0 = TIME + TMR0; Wait_ms(1000); TIME1 = TIME + TMR0; LCD_Move(0,0); LCD_Out(TIME1 - TIME0, 7); // time before call // time after call // time difference JSG - 6 -

The time it takes to execute Wait(1000) as measured using Timer0 interrupts. Note that you can measure time to an obscene number of decimal places using Timer interrupts. JSG - 7 -