View Index by Level
RANDOM PAGE

SITE SEARCH

LOG
IN

SIGN UP

HELP

Polling and Interrupts - TMR and PRE

To gain access to revision questions, please sign up and log in.

A2

Polling

Repeatedly reading a data port and testing the input data value.

  • The processor takes a measurement from a port/sensor at regular time intervals.
  • This happens, even if there has been no change in the connected device.
  • Guaranteed or predictable time slices are allocated to each device that is polled.

Polling is ...

  • simple to code
  • not very efficient because the polling happens even if the sensor reading has not changed
  • safe and reliable because the measurements happen at guaranteed time intervals

Interrupts

  • are hardware or software signals that trigger the interrupt subroutine to run.
  • only occur when needed.
  • are more efficient than polling but the timing is less predictable.
  • more difficult to code than polling.
  • the interrupt causes ...
    • the original process is paused and the return-address is saved onto the stack.
    • the interrupt code is run.
    • the original process is re-started using the return-address retrieved from the stack.

Timer Interrupts

Most processors have built-in timers which can be used to trigger processes when the timer interval ends.

Simulator Polling Example

CTRL+Click here to run the simulator.

Assm-Switches.gif

INIT:
    MOVW    0xFF       ; IIIIIIII
    MOVWR   TRISA      ; Set eight PORTA
                       ; pins to Input.
START:
    MOVRW   PORTA      ; Read PORTA
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    JMP     START

Simulator Timer Interrupt Example using TMR and PRE

The Timer and Prescaler Registers

Timer Example

CTRL+Click here to run the simulator.

START:
; =========================================
;   Initialise PRE and TMR
; =========================================
    MOVW    0X1     ; Copy 1 into ...
    MOVWR   PRE     ; ... the prescaler
    MOVW    0X08    ; Copy 8 into ...
    MOVWR   TMR     ; ... the timer

; =========================================
;   Poll the TMR flag (T)
; =========================================
POLL:
    MOVRW   SR      ; Copy SR into W
    ANDW    0x02    ; Bit mask
    JPZ     POLL

; ==========================================
; == This code runs when TMR reaches zero ==
; ==========================================
    NOP
    NOP
    NOP
    NOP
    JMP     START
; ==========================================

 

 

 

reviseOmatic V3     Contacts, ©, Cookies, Data Protection and Disclaimers Hosted at linode.com, London