I want to understand how the PIC instruction timing works. I've written the code below, and it toggles PORTB, pin 3. I analyze the results with an oscilloscope.
The PIC runs on 8MHz internal clock = 2MHz instruction clock (i.e. 500ns/single word instruction).
The oscilloscope shows me square waves with a period of 14*500ns.
My questions are:
- I want to match the observed square wave with the corresponding instructions. My idea is if I start at a rising edge I would say I've toggled LATB soo my chain of events is
btg -> retfie -> nop -> (now i'm guessing..) goto 0x000008 -> nop -> goto highPriInt -> nop -> btg
Is this correct? another idea would be
btg -> retfie -> nop -> nop (in loop) -> something for 1 cycle -> goto highPriInt -> nop -> btg
Question 2:
I never reset any interrupt flags but the highPriInt is called all the time. I know the 'retfie' command resets GIE bit but I thought I would have to clear the TMR0IF bit before another Timer interrupt could occur??
Best regards R
ORG 0x000000 ; Action on reset goto main ORG 0x000008 ; High priority interrupt vector goto highPriInt ORG 0x000018 ; Low priority interrupt vector goto lowPriInt main: clrf PORTB ; Clear port B clrf TRISB ; Set all as outputs movlw 0xFF ; Set Fosc to 8MHz iorwf OSCCON, 1 movlw 0x5F ; Setup Timer0, not started yet! movwf T0CON bsf INTCON, 5 ; Enable Timer0 interrupts bsf INTCON, 7 ; Enable globla interrupts bsf T0CON, 7 ; Enable Timer0 loop: nop bra loop highPriInt: btg LATB, 3 ; Toggles Port B pin 3 retfie lowPriInt: retfie END