![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi just a quick question. I know that when interrupt occurred it’s going to the org 0004h statement. To go to the interrupt routine does it needs any extra cycles? I mean For ex: if I in a 2 cycles instruction when Interrupt occurred does it go suddenly or after completing that 2 cycle is it going? | |
| |
| | (permalink) |
| If it is executing a single cycle instruction when the IRQ occurs then it takes 2 or 3 cycles, 0 or 1 to complete the current instruction and 2 to execute the call to 0x004. If it is executing a 2 cycle instruction then it will take 3 to 4 cycles. If it is a sychronous IRQ, such as a timer, then it will take the shorter time. Mike. | |
| |
| | (permalink) |
| Oh I see now I got it thanks for that. | |
| |
| | (permalink) |
| Hi Mike I went through your code it worked well. I understood everything except one.This code using TMR2, then whats the point of writing to TMR0 highlighted in red? TMR2 overflows on every 16 * 249 = 3984 cycles. 16 cycles missing to 4000. Code: List p=16F628A include <P16F628A.inc> errorlevel -302 __config 3F18h cblock 20h W_Temp,S_Temp,TIME endc #define LED PORTB,0 org 0000h goto Start ;*********** ;ISR routine ;*********** org 0004h movwf W_Temp swapf STATUS,W movwf S_Temp btfss PIR1,TMR2IF goto Away bcf PIR1,TMR2IF incf TIME,F movf TIME,W andlw 7fh xorlw .125 btfss STATUS,Z goto Away btfss TIME,7 goto $+4 clrf TIME bcf LED ;turn OFF led goto Away clrf TIME bsf TIME,7 bsf LED ;turn ON led Away swapf S_Temp,W movwf STATUS swapf W_Temp,F swapf W_Temp,W retfie ;******************************* ;Initialisation -setup the ports ;******************************* Start bsf STATUS,RP0 clrf TRISB movlw b'0000011' ;set prescaller to 16 movwf OPTION_REG bsf INTCON,GIE bcf STATUS,RP0 clrf PORTB movlw b'00000110' ;prescaler = 16 movwf T2CON bsf STATUS,RP0 bsf PIE1,TMR2IE movlw .249 movwf PR2 bcf STATUS,RP0 bsf INTCON,PEIE Hang nop goto Hang end | |
| |
| | (permalink) | |
| There is no need to setup timer0, I left the write to option register there incase you needed the other bits that are also setup by writing to option (WPUs, WDT etc.). The write to INTCON is required so that timer2 interrupts will work. Quote:
Mike. | ||
| |
| | (permalink) |
| You got it what I was thinking exactly. That’s what I need. Thanks for your superb codings. I won’t get a help like this from any where. Worth of thanks You are the best | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Using Oscilloscopes | mechie | Electronic Theory | 9 | 29th November 2007 10:49 PM |
| Pic16F7XX transmission interrupt problem | Tzvik | Micro Controllers | 1 | 27th January 2006 02:01 AM |
| HANDLING THE INTERRUPT. | alamy | Micro Controllers | 6 | 26th March 2005 04:37 PM |
| HELP!! INTERRUPT PROBLEM | aidantmurphy | Micro Controllers | 3 | 26th January 2005 07:52 PM |
| Interrupt on GP Change problem | Dan East | Micro Controllers | 2 | 22nd May 2004 06:12 PM |