PIC18F452 Timer adjustment

Similar documents
PIC18F452 Timer adjustment

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

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Using Timers of Microchip PIC18F Microcontrollers

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

Mod-5: PIC 18 Introduction 1. Module 5

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

ECE 354 Introduction to Lab 2. February 23 rd, 2003

The University of Texas at Arlington Lecture 7

evsjv `k cigvyy kw³ Kwgkb BANGLADESH ATOMIC ENERGY COMMISSION

Capstone Design Course. Lecture-2: The Timer

Chapter 09. Programming in Assembly

Lecture 9. Timer Operations and Programming

Arithmetic,logic Instruction and Programs

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

Electronics Data Sheets

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

Chapter 2. Overview of Architecture and Microcontroller-Resources

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

These 3 registers contain enable, priority,

Interrupts Peter Rounce - room 6.18

The University of Texas at Arlington Lecture 21_Review

THE 8051 MICROCONTROLLER

CENG-336 Introduction to Embedded Systems Development. Timers

Programmable Interval Timer CEN433 King Saud University Dr. Mohammed Amer Arafah

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

THE 8051 MICROCONTROLLER

Chapter 11: Interrupt On Change

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Interrupts Peter Rounce

General Purpose Programmable Peripheral Devices. Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Chapter 6 PROGRAMMING THE TIMERS

EE 367 Introduction to Microprocessors Homework 6

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning

Laboratory Exercise 4

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

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

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Instuction set

Microcomputer Technical Information

SOLUTIONS!! DO NOT DISTRIBUTE!!

Assembly Language Instructions

Embedded Systems Lab 2 - Introduction to interrupts

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.

8051 Microcontrollers

SCRAM Introduction. Philipp Koehn. 19 February 2018

timer 1 Fri Oct 13 13:00:

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

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING B.ENG (HONS) ELECTRICAL AND ELECTRONIC ENGINEERING EXAMINATION SEMESTER /2016

Description of the Simulator

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

ME 4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume.

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Midrange 8b PIC Microcontrollers. ECE Senior Design 14 February 2017

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

Micro-Controller: PIC16C74 < Part 5: Interrupt >

Micro II and Embedded Systems

ENE 334 Microprocessors

Lecture (04) PIC16F84A (3)

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

Performance & Applications

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

Department of Computer Science and Engineering

Decoders Wilfrid Laurier University

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

Speed Control of a DC Motor using Digital Control

An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal)

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

UNIT V MICRO CONTROLLER PROGRAMMING & APPLICATIONS TWO MARKS. 3.Give any two differences between microprocessor and micro controller.

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

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

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

PIC 16F84A programming (II)

INTRODUCTION OF MICROPROCESSOR& INTERFACING DEVICES Introduction to Microprocessor Evolutions of Microprocessor

The 8255A: Programmable Peripheral Interface

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

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

Computer Organization II CMSC 3833 Lecture 33

Interrupts on PIC18F252 Part 2

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

8051 microcontrollers

ECE Test #1: Name

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

DERTS Design Requirements (1): Microcontroller Architecture & Programming

Background. Virtual Memory (2/2) Demand Paging Example. First-In-First-Out (FIFO) Algorithm. Page Replacement Algorithms. Performance of Demand Paging

These three counters can be programmed for either binary or BCD count.

8/26/2010. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to Three Units of 8085

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

MICROPROCESSORS & MICRO CONTROLLER COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK

12-Dec-11. Gursharan Singh Maninder Kaur. Introduction to 8085 BLOCK DIAGRAM OF INTEL Introduction to Introduction to 8085

CPU Structure and Function

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

Accurate Time and Interrupts

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

NES FPGA Emulator. Sergio Morales Hector Dominguez Omar Torres Randy Truong Kevin Mitton

Transcription:

Wilfrid Laurier University February 10, 2012

Here s a code fragment for the timer:

Here s a code fragment for the timer: t i m e a d j equ d 65536 d 25000 +d 12 +2 movff TMR0L, templ ; read 16 b i t c o u n t e r movff TMR0H, temph ; get b u f f e r e d high h a l f movlw low t i m e a d j ; add time adjustment addwf templ, F movlw h igh t i m e a d j addwfc temph, F movff temph,tmr0h ; pre l o a d high h a l f movff templ,tmr0l ; w r i t e 16 b i t c o u n t e r b c f INTCON, TMR0IF ; c l e a r f l a g

Whether using polling or interrupts, this section of code is used to reload the timer after an overflow.

Whether using polling or interrupts, this section of code is used to reload the timer after an overflow. Following is an explanation of what it does, and why it s important.

Whether using polling or interrupts, this section of code is used to reload the timer after an overflow. Following is an explanation of what it does, and why it s important. For instance, the line timeadj equ d 65536 -d 25000 +d 12 +2 needs some explanation.

timer value at interrupt service From the interrupt, (or after the flag is polled), until it gets processed, some time passes.

timer value at interrupt service Probably only a few cycles, but important for precise timing.

ideal reload value

ideal reload value Interval desired is from ideal value to overflow (eg. FFFF)

must subtract current value from countdown interval For instance, for an interval of 25000 cycles, we would nominally want to reload with d 65536 -d 25000

must subtract current value from countdown interval We must subtract the time that happened before the interrupt service (or poll response).

movff TMR0L,templ First we must load the timer value, low byte first. This latches the high byte.

movff TMR0H,temph As we read the (latched) high timer byte, time is passing (2 cycles for this instruction).

movlw low adjust

movlw low adjust As we begin the subtraction, time is still passing (2 cycles for this instruction; 4 so far).

addwf templ,f (Actually, instead of subtracting, we add to the reload value.)

addwf templ,f Time is still passing (2 cycles for this instruction; 6 so far).

movlw high adjust

movlw high adjust Time is still passing (2 cycles for this instruction; 8 so far).

addwfc temph,f

addwfc temph,f Time is still passing (2 cycles for this instruction; 10 so far).

movff temph,tmr0h

movff temph,tmr0h Time is still passing (2 cycles for this instruction; 12 so far).

resynch delay When we rewrite the low byte, the timer will be updated...

resynch delay.. but there is a 2 cycle delay for the clock to resynch after re-loading.

resynch delay In total, there are 14 cycles used by the update, which must be subtracted from the desired interval.

resynch delay As above, these 14 cycles used by the update actually need to be added to the reload value.

resynch delay After the adjustment is complete, the timer flag must be cleared.

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536 the number of counts in a 16 bit sequence, including zero

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536 the number of counts in a 16 bit sequence, including zero interval length (in clock cycles)

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536 the number of counts in a 16 bit sequence, including zero interval length (in clock cycles) (eg. d 25000 )

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536 the number of counts in a 16 bit sequence, including zero interval length (in clock cycles) (eg. d 25000 ) + d 12

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536 the number of counts in a 16 bit sequence, including zero interval length (in clock cycles) (eg. d 25000 ) + d 12 to allow for the time for the arithmetic

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536 the number of counts in a 16 bit sequence, including zero interval length (in clock cycles) (eg. d 25000 ) + d 12 to allow for the time for the arithmetic + 2 to allow for the time for clock resynch

So, whether using polling or interrupts, after an overflow the timer has to be reloaded with a value of d 65536 the number of counts in a 16 bit sequence, including zero interval length (in clock cycles) (eg. d 25000 ) + d 12 to allow for the time for the arithmetic + 2 to allow for the time for clock resynch and then the flag must be cleared for the next interval.