Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

More fun with Timer/Counters
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
Embedded System Spring, 2011 Lecture 9: I/O Programming Eng. Wazen M. Shbair.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
The PIC uCs PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey Eng. Husam Alzaq The Islamic Uni. Of Gaza 9-1.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Taking timing further Chapter Nine 9.1 – 9.8 Dr. Gheith Abandah1.
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
The 8051 Microcontroller and Embedded Systems
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
Embedded System Spring, 2011 Lecture 3: The PIC Microcontrollers Eng. Wazen M. Shbair.
Lecture – 6 PIC18 Family Hardware Specifications 1.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
8051 timer/counter.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Timer/counter Chapter 12
ARM Timers.
System Clocks.
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Chapter 4 TIMER OPERATION
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Embedded System Spring, 2011 Lecture 4: The PIC Microcontrollers Eng. Wazen M. Shbair.
Embedded System Spring, 2011 Lecture 10: Arithmetic, Logic Instruction and Programs Eng. Wazen M. Shbair.
Timers /Counters Programming  The 8051 has 2 timers/counters: ○ timer/counter 0 ○ timer/counter 1 They can be used as 1. The timer is used as a time.
Time Measurement Capture Mode of the Capture/Compare/PWM module is used for time measurement. TMR1 or TMR3 16-bit value transferred to 16-bit capture.
Embedded System Spring, 2011 Lecture 5: The PIC Microcontrollers Eng. Wazen M. Shbair.
ELE22MIC Lecture 18 The AVR Sleep Modes The ATMEGA128’s Timer System
8051 Timer/Counter Lec note 7.
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
The 8051 Microcontroller and Embedded Systems
Today’s Lecture Unconditional branch instruction
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
Jump, Loop, and Call Instructions
The Silicon Laboratories C8051F020
The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi.
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Timer Programming in Assembly and C Prepared By:
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microcontrollers BME 201. Overview Microcontrollers Notation Registers Timer Concepts Equations.
TIMERS.
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
Chapter 9 PIC18 Timer Programming in Assembly
Chapter 10 PIC18 Serial Port Programming in Assembly
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Microprocessor Systems Design I
Microprocessors Timers
The PIC uCs PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey Eng. Husam Alzaq The Islamic Uni. Of Gaza 11-1.
EMT 348: Microcontroller Timer/counter
8051 Timers Prof. Rajiv R Bhandari.
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
Pugazhendhi.M 11/12/2018 TIMERS 11/12/2018 CCET CCET.
Timer.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
EECE.3170 Microprocessor Systems Design I
Timer Source: under
PIC18 Interrupt Programming
Timers Chapter 2.
Presentation transcript:

Embedded System Spring, 2011 PIC18 Timer Programming in Assembly and C Eng. Wazen M. Shbair

Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly to generate time delays Program the PIC18 timers in Assembly as event counters IUG- Embedded System

Introduction PIC18 has two to five timers These timers can be used as Depending on the family number These timers can be used as Timers to generate a time delay Counters to count events happening outside the uC

Programming timers 0 and 1 Every timer needs a clock pulse to tick Clock source can be Internal  1/4th of the frequency of the crystal oscillator on OSC1 and OSC2 pins (Fosc/4) is fed into timer External: pulses are fed through one of the PIC18’s pins  Counter Timers are 16-bit wide Can be accessed as two separate reg. (TMRxL & TMRxH) Each timer has TCON (timer Control) reg. 9-4

Timer0 registers and programming TMR0L & TMR0H are 8-bit Reg. MOVWF TMR0L MOVFF TMR0L, PORTB

T0CON (Timer0 control) register Each timer has a control register called TCON, to set various timer operation modes. ToCON is 8-bit register used to control of Timer0. Example If T0CON= 0000 1000 16-bit No prescaler Rising edge

Figure 9-2. T0CON (Timer0 Control) Register

T0CS(Timer0 clock source) This bit used to decide whether the clock source is internal or external. If T0CS=0 Then Fosc/4 is used as clock source, used for delay generation. If T0CS=1 the clock source is external and comes from an external source, used as event counter.

TMR0IF flag bit TMR0IF is (Timer0 interrupt flag) is a part of the INTCON (interrupt control) register. When te timer reaches its maximum value of FFFFH, it rolls over to 0000, and TMR0IF is set to 1 INTCON (Interrupt Control Register) has the TMR0IF Flag

Figure 9-4. Timer0 Overflow Flag

Characteristics and operations of 16-bit mode 16-bit timer, 0000 to FFFFH. After loading TMR0H and TMR0L, the timer must be started. Count up, till it reaches FFFFH, then it rolls over to 0000 and activate TMR0IF bit. Then TMR0H and TMR0L must be reloaded with the original value and deactivate TMR0IF bit.

Steps to program Timer0 in 16-bit mode to generate time delay Load the value into the T0CON register Load reg. TMR0H followed by reg. TMR0L with initial value Start the timer with instruction BSF T0CON, TMR0ON Keep monitoring the timer flag (TMR0IF) to see if it is raised. Stop the timer Clear the TMR0IF flag 3 Go Back to step 2 9-12

Figure 9-6. Timer Delay Calculation for XTAL = 10 MHz with No Prescaler General formula for delay calculation T = 4/(10MHz) = 0.4 usecond

Finding values to be loaded into the timer If we know the amount of timer delay , how to find the values needed for the TMR0H and TMR0L registers.

Finding values to be loaded into the timer

Prescaler and generating larger delay The size of delay depend on The Crystal frequency The timer’s 16-bit register. The largest timer happens when TMR0L=TMR0H=0 Prescaler option is used to duplicate the delay by dividing the clock by a factor of 2,4, 8,16, 32,64 ,128,256 If T0CON=0000 0101, then T = 4*64/f XTAL Osc ÷ 4 ÷ 64 TMRx 9-20

IUG-Embedded System 2011IUG- Embedded System Prescaler and generating larger delay IUG-Embedded System 2011IUG- Embedded System

IUG-Embedded System 2011IUG- Embedded System

IUG-Embedded System 2011IUG- Embedded System

Timer1 Programming Can be programmed in 16-bit mode only It has 2 bytes named as TMR1L and RMR1H It has also T1CON and TMR1IF The module incorporates its own low-power oscillator to provide an additional clocking option. Used as a low-power clock source for the microcontroller in power-managed operation.

IUG-Embedded System 2011IUG- Embedded System Figure 9-10. T1CON (Timer 1 Control ) Register IUG-Embedded System 2011IUG- Embedded System

Figure 9-11. (Interrupt Control Register) Contains the TMR1IF Flag

Counter Programming Used to counts event outside the PIC Increments the TMR0H and TMR0L registers T0CS in T0CON reg. determines the clock source, If T0CS = 1, the timer is used as a counter Counts up as pulses are fed from pin RA4 (T0CKI) What does T0CON=0110 1000 mean? If TMR1CS=1, the timer 1 counts up as clock pulses are fed into pin RC0

IUG-Embedded System 2011IUG- Embedded System External Source Internal Source 9-28 IUG-Embedded System 2011IUG- Embedded System

Using external Crystal for Timer1 clock Timer1 comes with two options, clock fed into T1CKI T1OSCEN=0 Clock from a crystal connected to T1OSI-T1OSO (additional) T1OSCEN=1 32 kHz Crystal is connected Used for saving power during SLEEP mode  doesn’t disable Timer1 while the main crystal is shut down

IUG-Embedded System 2011IUG- Embedded System

IUG-Embedded System 2011IUG- Embedded System

IUG-Embedded System 2011IUG- Embedded System

References Jie Hu , ECE692 Embedded Computing Systems , Fall 2010. PIC Microcontroller And Embedded Systems: using Assembly and C for PIC 18, M. Mazidi, R. McKinlay and D. Causey, Prentice Fall, 2008. Eng. Husam Alzaq, Embedded System Course, IUG, 2010 IUG- Embedded System 33