Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 5th October 2007, 07:18 AM   (permalink)
Default

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?
Suraj143 is offline  
Old 5th October 2007, 07:30 AM   (permalink)
Default

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.
Pommie is offline  
Old 5th October 2007, 07:40 AM   (permalink)
Default

Oh I see now I got it thanks for that.
Suraj143 is offline  
Old 11th October 2007, 05:23 AM   (permalink)
Default

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
Suraj143 is offline  
Old 11th October 2007, 05:40 AM   (permalink)
Default

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:
TMR2 overflows on every 16 * 249 = 3984 cycles. 16 cycles missing to 4000.
The timer resets on the next increment after it matches PR2. So the actual time is 250*16. The sequence goes 0,1,...248,249,0,1 etc. The sequence 0 to 249 contains 250 values - think of the sequence 0 to 1 and you see that it contains 2 values.

Mike.
Pommie is offline  
Old 11th October 2007, 05:54 AM   (permalink)
Default

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
Suraj143 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
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



All times are GMT. The time now is 08:26 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker