Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microprocessors Timers

Similar presentations


Presentation on theme: "Microprocessors Timers"— Presentation transcript:

1 Microprocessors Timers
Syed Hussain , Muhamad Sohaib Arif and Albert Abad Microprocessors Timers COSC 524 By Albert Abad, Muhamad Sohaib Arif & Syed Hussain Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad Syed Hussain , Muhamad Sohaib Arif

2 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Timer - Physically timer is a register whose value is continually increasing up to 0,1,2,3, = Total 256 • After reaching its maximum value it starts over again. • All timers are independent. Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

3 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
PIC Microcontroller has three Timers Timer 0: 8-bit register TMR0 Timer 1: 16-bit register TMR1H | TMR1L Timer 2: 8-bit register TMR2 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

4 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Timer 0 (TMR0) Features: 8 bit register timer. We can set the bit register by using 1 and 0 to set the instructions that we need. Programmable Prescaler Read and write. We can change instructions anytime. • Internal and External clock. Internal is the clock ticking inside the PIC that we can call anytime. External is the clock outside the PIC that we can connect to RA4 / TOCKI Interrupt on overflow from FFh to 00h Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

5 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Prescaler in Timers To slow down a Timer that is incrementing, instead of incrementing each clock cycle it can be adjusted to every 2nd, 4th,8th We can use this prescaler to divide our timers clock. Prescaller is set here: With assigning 0 &1 to PS2,PS1 and PS0 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

6 External timer is connected to RA4/TOCKI
Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

7 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Timer0 Architecture Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

8 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
How the Timer0 works: RBPU (PORTB Pull-up) 0: Port B resistors pull ups disabled. 1: Port B resistors pull ups activated. INTEDG ( RB0/INT pin Interrupt Edge) 0: The RB0/INT interrupt will occur on the falling edge of the RB0/INT pin 1: The RB0/INT interrupt will occur on the rising edge of the RB0/INT pin T0CS (Timer 0 Clock Source) 0: Timer 0 clock source is the Internal instruction cycle clock (CLKO) 1: Timer 0 clock source is the RA4/TOCKI pin T0SE (Timer 0 Source Edge) – Used for external clock 0: Incremanet on high to low 1: increment low to high PSA 0: The prescaler is assigned to the Timer 0 module (TMR0) 1: The prescaler is assigned to the Watchdog timer (WDT) PS2,PS1,PS2 Prescaler Rate Bits Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

9 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
How the Timer0 works: Set the INTCON GIE= global interrupt, T0IE= Timer0 interrupt enabler and T0IF= Timer0 interrupt flag GIE: 0 ALL ITERRUPS ARE DISABLED, 1 ALL INTERRUPTS ENABLED T0IE : 1 = Enables the TMR0 interrupt 0 = Disables the TMR0 interrupt Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

10 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

11 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
To measure time: Reset the TMR0 register or write some well-known value to it; banksel OPTION_REG movlw b' ‘ ; = 128 movwf OPTION_REG bcf PORTB,4 movlw d‘100' movwf TMR0 Example : ( )*128 = 20,000 = 20milli Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

12 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Diagram for Timer 0 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

13 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
16 bit timer Time value is in TMR1L and TMR1H When TMR1L overflows, TMR1H starts incrementing When TMR1H overflows, the TMR1IF interrupt is enabled The interrupt can be enabled or disabled by setting or clearing TMR1IE bit in PIE1 Can also run in counter mode where it increments on every rising edge of the external clock input Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

14 Timer1 control T1CON register
U-0 R/W-0 _ T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON Bit 7 Bit 0 T1CKPS1:T1CKPS0: Timer1 input clock prescale select bits 11 means 1:8 prescale value while 00 means 1:0 presale value T1CKSCEN: Timer1 oscillator enable control bit T1SYNC: External clock synchronize bit 1 means do not synchronize the external clock and 0 means to synchronize the external clock TMR1CS: Timer1 clock source select bit 1 means external clock at RB6 will be used 0 means internal clock(Fosc/4) will be used TMR1ON: Timer1 on bit Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

15 Timer1 operation in timer mode
Timer mode is selected by clearing the TMR1CS. Meaning it is set to use the internal Fosc/4 source. Timer1 in counter mode Timer1 can be used in two counter modes: Synchronous and Asynchronous Both modes require an external clock inputs which we are not using in this course Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

16 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Timer 1 Architecture Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

17 Associated registers with Timer1
Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

18 Using timer1 with CCP Trigger
Timer1 can be used with the capture/control/PWM CCP module It has to be in either timer mode or synchronized counter mode where its value TMR1L and TMR1H are compared to CCPR1L and CCPR1H on every cycle CCP is out of scope for this presentation Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

19 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Timer2 is an 8 bit timer with a prescaler and postscaler This can be used as the PWM time-base for the CCP module It uses the ineranal clock Fosc/4 with a prescale options of 1:1, 1:4 and 1:16 which are selected using the P2CKPS1:P2CKPS0 bits of the Timer2 control(T2CON) register The value of the timer is compared to the PR2 register and resets to 00 when it reaches PR2 The output of timer1 goes through a 4-bit postscaler before generating an interrupt Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

20 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
The prescaler and postscaler values are cleared on writes to TMR2, T2CON and device reset. The TMR2 register itself is not cleared when T2CON is writen Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

21 Timer2 control (T2CON) register
U-0 R/W-0 _ TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 Bit 7 Bit 0 TOUTPS3:TOUTPS0: The postscalar select bits 0000 means 1:1 postscale, 0001 means 1:2 postscale and so on until 1111 which means 1:16 postscale TMR2ON: Timer2 on bit 1 means timer2 is on and 0 means timer2 is 0 T2CKPS1:T2CKPS0: Timer2 clock prescale select bits 00 means 1:1 prescale 01 means 1:4 prescale 1x means 1:16 prescale Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

22 Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad
Timer 2 Architecture Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad

23 Associated registers with Timer2
Timers by: Syed Hussain , Muhamad Sohaib Arif & Albert Abad


Download ppt "Microprocessors Timers"

Similar presentations


Ads by Google