1

I have a PIC18F87J11 device and I'm supposed to create:
1) a high-priority ISR that's supposed to be triggered every 100ms
2) a low-priority ISR that's supposed to be triggered every 10ms

I have a basic knowledge about configuring a pre-scaler, in example for Timer0, it's

movlw b'00000010'
movwf T0CON

as manual page reads, this should configure Timer0 to 16bit counter, pre-scaler 1:8 (device's manual page 179). The problem is, I don't know how to determine the correct pre-scaler settings when I want 100ms intervals. Any help appreciated.

EDIT:
Okay, now I realize that I probably have way less idea about what I'm doing then I thought. I can't find relevant information in manual (and I'm sure it is there). I need to set up Timer0 to 100ms and Timer1 to 10ms.

cypher
  • 6,822
  • 4
  • 31
  • 48
  • @cyphy, can you give some information on oscillator speed? – Kortuk Nov 21 '11 at 11:32
  • I believe the oscillator speed is 10MHz, but I'm not really sure as there are way too many information in the manual which I don't understand. – cypher Nov 21 '11 at 11:46
  • However much reading you do I often find a divide by two or four I didnt see (with various microcontrollers not specifically the pic). I tend to start my understanding of a new timer by blinking an led or some gpio (and using a scope or voltmeter if no led is available) make the blink rate in seconds so that it can be compared to something with a second hand or a stopwatch, something with a known accuracy. Play with the prescalers and make sure you understand them, once the timer is understood then it is simple to pick any time interval with some level of expectation for success. – old_timer Nov 21 '11 at 14:33

1 Answers1

1

Here are you have ISR high-priority initiation rutine for TMR0.

At very begining of your MCPU initiation code you must define...

;Init TMR0 as 8 bit timer, overflow every 1024 CPU cycles if TMRxPrescaler4 is set
;{
TMRxPrescaler2      equ 0
TMRxPrescaler4      equ 1
TMRxPrescaler8      equ 2
TMRxPrescaler16     equ 3
TMRxPrescaler32     equ 4
TMRxPrescaler64     equ 5
TMRxPrescaler128    equ 6
TMRxPrescaler256    equ 7

    movlw   (1<<TMR0ON) + (1<<T08BIT) + TMRxPrescaler4
    movwf   T0CON
    bsf INTCON, TMR0IE       ;enable TMR0 overflow interrupt 
;};

After MCPU initiation don't forget to switch on interrupts...

    bsf     INTCON, GIE

ISR rutine:

ISR
    bcf INTCON, TMR0IF              ;demask TMR0 overflow interrupt
;your ISR code
    retfie  1

In ISR rutune count numbers of TMR0 overflows, for 10MHz CPU clock: 10000000 / 4 / 1024 = 2441.4 overflows for one second.

I recommend that you are using only one ISR rutine where you handle both events.

GJ.
  • 10,810
  • 2
  • 45
  • 62