TIMERS.

Slides:



Advertisements
Similar presentations
Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
Advertisements

م/محمد علي عطية حسين. Pin Diagram DescriptionPin Name Oscillator crystal input/external clock source input. OSC1/CLKIN Oscillator crystal output.OSC2/CLKOUT.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Introduction of Holtek HT-46 series MCU
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.
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.
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.
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
System Clocks.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
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
Interrupts, Counter and Timers. Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow.
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
I/O PORTS (Simplest Peripherals) PORT A: 6 bits wide (7th and 8th bit always read as 0) PORT B: 8 bits wide PORT C: 8 bits wide PORT D: 8 bits wide.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
Prepared by Eng. Musa Alyaman1 Chapter Seven Chapter Seven PIC16F87x.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
C Examples 1. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Microprocessors A practical approach Lesson 2 Hardware description and Delays.
Working with Time: Interrupts, Counters and Timers
PIC16F887.
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
Special Features. Device Configuration bits Revision Device Configuration bits Revision On-chip Power-on Reset (POR) Revision On-chip Power-on Reset (POR)
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
An Introduction to Embedded Systems, and the PIC Microcontroller Lecture 8: Interrupts The aims of this session are to explore the structure and application.
16F877A.
Chapter 9 PIC18 Timer Programming in Assembly
Why are Timer Functions Important?
Microprocessor Systems Design I
Microprocessors and Programming Department of Mechatronics Engineering
Chapter 10 PIC18 Serial Port Programming in Assembly
Microprocessor Systems Design I
Microprocessor Systems Design I
Micro-Controller: PIC16C74 < Architecture >
Interrupts, Counter and Timers
Microprocessor Systems Design I
AVR Addressing Modes Subject: Microcontoller & Interfacing
Microprocessors Timers
PIC 16F877.
RX Compare Match Timer (CMT)
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
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.
EE Embedded Systems Fall 2015
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.
8-bit Timer/Counter2 with PWM and Asynchronous Operation
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
EECE.3170 Microprocessor Systems Design I
INSTRUCTION SET.
8051 Micro Controller.
EECE.3170 Microprocessor Systems Design I
PIC18 Interrupt Programming
PIC18 Interrupt Programming
Timers Chapter 2.
Microprocessors and Programming Department of Mechatronics Engineering
Presentation transcript:

TIMERS

TIMER 0 MODULE • 8-bit timer/counter The Timer0 module has the following features: • 8-bit timer/counter • Readable and writable • 8-bit software programmable prescaler • Clock source selectable to be external or internal • Interrupt on overflow from FFh to 00h • Edge select for external clock

OPTION_REG Register (Address 81h,181h) PSA PS2 PS1 PS0 bit 3 PSA: Prescaler Assignment bit 1 = Prescaler is assigned to the WDT 0 = Prescaler is assigned to the Timer0 module bit 2:0 PS2:PS0: TMR0 Prescaler/WDT Postscaler Rate Select bits

bit 5 T0CS: TMR0 Clock Source Select bit T0ES PSA PS2 PS1 PS0 bit 5 T0CS: TMR0 Clock Source Select bit 1 = Transition on T0CKI pin 0 = Internal instruction cycle clock (CLKOUT) bit 4 T0SE: TMR0 Source Edge Select bit 1 = Increment on high-to-low transition on T0CKI pin 0 = Increment on low-to-high transition on T0CKI

TOSC=‘0’ Timer mode Timer0 module will increment every instruction cycle (without prescaler). TOSC=‘1’ Counter mode Timer0 will increment either on every rising or falling edge of the T0CKI pin. T0SE=‘0’ Rising edge T0SE=‘1’ Falling edge

Internal Clock/No Prescale After the TMR0 register has been written with the new value, TMR0 will not be incremented until the third instruction cycle later. Internal Clock/No Prescale Internal Clock/Prescale

T0 Interrupt The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h T0IF=‘1’ The interrupt can be masked by clearing bit T0IE The TMR0 interrupt cannot awaken the processor From SLEEP since the timer is shut-off during SLEEP.

T0IF=‘1’ Option Register PSA PS2 PS1 PS0 X X 0 X 0 0 0 0 RBPU INTEDG T0CS T0ES PSA PS2 PS1 PS0 X X 0 X 0 0 0 0 T0IF=‘1’

RBPU INTEDG T0CS T0ES PSA PS2 PS1 PS0 X X 1 0 0 0 0 0 T0IF=‘1’

T0IF=‘1’ Option Register PSA PS2 PS1 PS0 X X 1 0 1 0 0 0 RBPU INTEDG T0CS T0ES PSA PS2 PS1 PS0 X X 1 0 1 0 0 0 T0IF=‘1’

Changing Prescaler (WDT Timer0) CLRWDT ; Clear WDT and prescaler BSF STATUS, RP0 ; Bank1 MOVLW b'xxxx0xxx' ; Select TMR0, new prescale MOVWF OPTION_REG ; value and clock source BCF STATUS, RP0 ; Bank0

Changing Prescaler (Timer0 WDT) BSF STATUS, RP0 ;Bank1 MOVLW b'xx0x0xxx' ;Select clock source and prescale value MOVWF OPTION_REG ;other than 1:1 BCF STATUS, RP0 ;Bank0 CLRF TMR0 ;Clear TMR0 and prescaler BSF STATUS, RP1 ;Bank1 MOVLW b'xxxx1xxx‘ ;Select WDT, do not change prescale value MOVWF OPTION_REG ; CLRWDT ;Clears WDT and prescaler MOVLW b'xxxx1xxx' ;Select new prescale value and WDT BCF STATUS, RP0 ;Bank0 RBPU INTEDG T0CS T0ES PSA PS2 PS1 PS0

Timer0 Initialization (Internal Clock Source) CLRF TMR0 ; Clear Timer0 register CLRF INTCON ; Disable interrupts and clear T0IF BSF STATUS, RP0 ; Bank1 MOVLW 0xC3 ; PortB pull-ups are disabled, MOVWF OPTION_REG ; Interrupt on rising edge of RB0 ; Timer0 increment from internal clock ; with a prescaler of 1:16. BCF STATUS, RP0 ; Bank0 ; ; The TMR0 interrupt is disabled, do polling on the overflow bit T0_OVFL_WAIT BTFSS INTCON, T0IF GOTO T0_OVFL_WAIT ; Timer has overflowed RBPU INTEDG T0CS T0ES PSA PS2 PS1 PS0

Timer 1 Module

16 bit timer/counter module Interrupt bit flag TMR1IF(PIR1<0>) Prescaler 1,2,4,8 3 Modes operations: Timer Synchronous Counter Asynchronous Counter 0000h-FFFFh 0-65,535 TMR1H TMR1L

T1CON: Timer1 Control Register TMR1CS TMR1ON bit 1 TMR1CS: Timer1 Clock Source Select bit 1 = External clock from pin T1OSO/T1CKI (on the rising edge) 0 = Internal clock (FOSC/4) bit 0 TMR1ON: Timer1 On bit 1 = Enables Timer1 0 = Stops Timer1

bit 3 T1OSCEN: Timer1 Oscillator Enable bit T1SYNC bit 3 T1OSCEN: Timer1 Oscillator Enable bit 1 = Oscillator is enabled 0 = Oscillator is shut off. The oscillator inverter and feedback resistor are turned off to eliminate power drain bit 2 T1SYNC: Timer1 External Clock Input Synchronization Select bit When TMR1CS = 1: 1 = Do not synchronize external clock input 0 = Synchronize external clock input When TMR1CS = 0: This bit is ignored. Timer1 uses the internal clock when TMR1CS = 0.

bit 5:4 T1CKPS1:T1CKPS0: Timer1 Input Clock _____ T1CKPS1 T1CKPS0 bit 5:4 T1CKPS1:T1CKPS0: Timer1 Input Clock Prescale Select bits 11 = 1:8 Prescale value 10 = 1:4 Prescale value 01 = 1:2 Prescale value 00 = 1:1 Prescale value

Timer Mode TMR1CS=‘0’ Input clock to the timer is FOSC/4 T1SYNC (T1CON<2>), has no effect since the internal clock is always in sync.

Synchronized Counter Mode TMR1CS=‘1’ & T1SYNC=‘0’ Timer increments on every rising edge of clock input on the T1OSI pin when the oscillator enable bit (T1OSCEN) is set, or the T1OSO/T1CKI pin when the T1OSCEN bit is cleared. In this configuration, during SLEEP mode, Timer1 will not increment even if the external clock is present, since the synchronization circuit is shut off.

Asynchronized Counter Mode TMR1CS=‘1’ & T1SYNC=‘1’ Timer continues to increment asynchronously to the internal phase clocks Timer will continue to run during SLEEP and can generate an interrupt on overflow which will wake-up the processor For writes, it is recommended that the user simply stop the timer and write the desired values. A write contention may occur by writing to the timer registers while the register is incrementing. This may produce an unpredictable value in the timer register

Timer1 Block Diagram T1CON 0 0 0 0 0 X 0 0

Timer1 Block Diagram T1CON 0 0 0 0 0 0 1 0

Timer 2 Module

Timer 2 Module 8 bit timer TMR2 0h-ffh (0-255) T2CON 8 bit register PR2 Interrupt bit flag TMR2IF(PIR1<1>) Prescaler 1:1, 1:4, 1:16 Postscaler 1:1 – 1:16 One mode operation (Fosc/4)

T2CON bit 1:0 T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits 00 = Prescaler is 1 01 = Prescaler is 4 1x = Prescaler is 16

TMR2ON bit 2 TMR2ON: Timer2 On bit 1 = Timer2 is on 0 = Timer2 is off

bit 6:3 TOUTPS3:TOUTPS0: Timer2 Output 0000 = 1:1 Postscale _ TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 bit 6:3 TOUTPS3:TOUTPS0: Timer2 Output Postscale Select bits 0000 = 1:1 Postscale 0001 = 1:2 Postscale • 1111 = 1:16 Postscale

The prescaler and postscaler counters are cleared when any of the following occurs: • A write to the TMR2 register • A write to the T2CON register • Any device Reset (POR, MCLR Reset, WDT Reset or BOR) TMR2 is not cleared when T2CON is written. During sleep, TMR2 will not increment. The prescaler will retain the last prescale count, ready for operation to resume after the device wakes from sleep.

TIMER2 BLOCK DIAGRAM

MOVLW 0x72 ; Postscaler = 1:15, Prescaler = 1:16 CLRF T2CON ; Stop Timer2, Prescaler = 1:1, ; Postscaler = 1:1 CLRF TMR2 ; Clear Timer2 register CLRF INTCON ; Disable interrupts BSF STATUS, RP0 ; Bank1 CLRF PIE1 ; Disable peripheral interrupts BCF STATUS, RP0 ; Bank0 CLRF PIR1 ; Clear peripheral interrupts Flags ;============================================ MOVLW 0x72 ; Postscaler = 1:15, Prescaler = 1:16 MOVWF T2CON ; Timer2 is off BSF T2CON, TMR2ON ; Timer2 starts to increment ; ; The Timer2 interrupt is disabled, do polling on the overflow bit T2_OVFL_WAIT BTFSS PIR1, TMR2IF ; Has TMR2 interrupt occurred? GOTO T2_OVFL_WAIT ;NO, continue loop ; Timer has overflowed BCF PIR1, TMR2IF ; YES, clear flag and continue.