Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem facing in timer interrupts

Status
Not open for further replies.

Disha Karnataki

Full Member level 5
Full Member level 5
Joined
Jul 20, 2013
Messages
249
Helped
9
Reputation
18
Reaction score
8
Trophy points
18
Location
india
Visit site
Activity points
2,231
this is the code in asm written
i.e the code written here is: it will display 55h & aah with some delay in between them on port1 & a timer is set. So when timer interrupts there will isr execution. here is the code:
Code:
org 0000h
ljmp main
org 000bh               //start of isr 
clr tf0
lcall delay
mov p1,#00h
lcall delay
mov p1,#88h
reti
org 0030h
main:
mov p1,#00h
mov tmod,#01h						   //timer initialisation
mov ie,#82h             //interrupt initialization													   
up:mov p1,#055h						  //
lcall delay							//
lcall delay						  //		displaying 55h, aah with some delay
mov p1,#0aah							//
lcall delay								  //
setb tr0        //starts the timer
sjmp up
delay:mov r0,#0f0h
l1:mov r0,#0ffh		   //creating some delay
k1:djnz r0,k1
djnz r1,l1
ret
end

explaination :initailly before timer interrupts there is continuous display of 55h & aah on port p1 and when timer interrupts then in isr routine 00h & 88h is displayed.

problem facing: here the timer interrupt is not at all ending it is not coming out of the isr routine inspite of writing RETI(it is an instruction to written from interrupt) only once it is executing the main program & then it is ending up in isr routine & is not terminating at all.
please help.
 
Last edited by a moderator:

You forgot to turn off the timer by "clr tr0". That's why it can't get out of interrupt.
And your timer doesn't have any significant role here. Here's your code below reorganized a little bit neatly, but you need to look onto some mistakes, such as your ISR code needs a jump to another vector address & there's no R1 register under delay subroutine.....

Code:
org 0000h
jmp	main

org 000bh ;start of isr 
jmp	ISR

org 0030h
main:
mov p1,#00h
mov tmod,#01h	 ;timer initialisation
mov ie,#82h ;interrupt initialization

up:
mov p1,#055h	 ;
lcall delay	 ;
lcall delay	 ;	 displaying 55h, aah with some delay
mov p1,#0aah	 ;
lcall delay	 ;
setb tr0 ;starts the timer
sjmp up

delay:
mov r1,#0f0h
l1:mov r0,#0ffh	 ;creating some delay
k1:djnz r0,k1
djnz r1,l1
ret

ISR:
clr tf0
clr tr0
lcall delay
mov p1,#00h
lcall delay
mov p1,#88h
reti

end
 
is this code correct to find motor rpm??
Code:
org 0000h
ljmp main
org 000bh
clr tr0				 //isr for timer to create 1 second delay
djnz r0,l12
mov p1,a   
clr ie.2		  //clearing external interrupt once 1 sec is over
reti
l12:
mov tl0,#00h
mov th0,#00h
//inc a
reti
org 0013h
inc a						  //isr for external interrupt1
reti	
org 0100h
main:mov p1,#00h
mov p3,#0ffh
mov tmod,#01h
mov th0,#00h
mov tl0,#00h
mov a,#00h
lcall delay
lcall delay
lcall delay
lcall delay
mov p1,#0aah		   //just to cause a delay before the motor completly assumes it's speed
lcall delay
mov p1,#55h
lcall delay
lcall delay
lcall delay				

mov r0,#0eh              // r0=14 for 1sec delay
mov ie,#86h				//
w1:setb tr0				 //	  starting timer
cjne r0,#00h,w1			   //		  making timer to overflow flag 14 times to make a delay of 1 second
oi:mov p1,a					 //
sjmp oi
delay:mov r3,#0ffh
l:mov r1,#0ffh
s:mov r2,#0ffh		   
k:djnz r2,k
djnz r1,s
djnz r3,l
ret
end

- - - Updated - - -

see my code written on motor rpm & just tell me whether it's correct or no
 
Last edited by a moderator:

If you want one sec delay using interrupt then you have to set timer so that it interrupts every 1 sec. If it is not possible then create timer to interrupt every 500 ms and use a counter to count the no. of interrupts. If 2 interrupts of 500 ms occur then it will be 1 sec. Don't use any delays or loop inside ISR.

To count RPM, you have to use external interrupt with timer interrupt. Start timer and stop timer after say 250 ms. Use a counter and increment in on every external interrupt. If the count is 100 in 250 ms then use it to calculate RPM (for 60 sec).
 

yes i have used one timer interrupt & one external interrupt, here i am doing a pov on ac fan & the ucontroller is mounted on the fan as i also want to know rpm of the fan when pcb is mounted so i was writing this program. I have used delay intially because fan will need some time to come to it's original speed if i ""would not"" have had used initially delays & would have directly enabled the timer then it would not give me exact speed so here in this program initially i making it to display 0aah & 055h & then timer is enabled till then the fan will be in it's actual speed. The uc mounted on the fan will count the rpm of the fan's motor.
 

i have a ir photodiode mounted on uc 8051 for p3.3 pin(& have configured it as ext interrupt1) & then there is ir led placed(not on fan assembly) & then as fan rotates ir photodiode gives pulses to 8051 & then those pulses are used to find out rpm of the fan on which the whole setup is mounted inorder to know the rpm of the fan with mounted pcb & other stuff.
Actually the rating of the motor is given as 1250rpm but due to the mounting assembly there is possibility of lowered speed that is why i want to know the actual rpm of the motor with all stuff mounted.
 

i have changed the way i am doing this i.e the pov assembly is mounted on the board & then i have taken another microcontroller with ir photodiode attached to it & led is mounted on fan's wing & uc(not the one on fan) is noting down the rpm.
and so here is the code but is displaying different values at different times when resetted

org 0000h
ljmp main
org 000bh
ljmp isrt0
org 0013h
ljmp isrint1
reti
org 0100h
main:mov p1,#00h
mov p3,#0ffh
mov tmod,#11h
mov th0,#00h
mov th0,#00h
mov a,#00h
mov r0,#0eh //this is to create 1s delay
mov ie,#86h //enabling timer & external interrupt1
w1:setb tr0
cjne r0,#00h,w1
oi:mov p1,a //moving the interrupted value once 1s is over
sjmp oi
isrt0:
clr tr0
djnz r0,l12
mov p1,a
clr ie.2 //clearing extarnal interrupt once one sec is over here program is executed only once
reti
l12:
mov th0,#00h
mov tl0,#00h
reti

isrint1:
inc a
reti
end
 

i am doing a counter programing in 8051 using asm language inorder to count pulses at p3^4 pin for 1second here i have programmed one timer as timer & another timer as counter when i simulate this program it is working fine but it's showing different count on hardware when i reset at different instance please figure out what is problem in my programing.

org 0000h
ljmp main
org 001bh
ljmp isrt1 //isr routine
org 0100h
main:mov p1,#00h
mov p3,#0ffh
mov tmod,#15h //timer0 as counter & timer1 as timer
mov ie,#88h //timer interrupt for timer1
mov th1,#00h
mov tl1,#00h
mov r0,#0eh //for 1 second delay
setb tr0
k1:setb tr1 //start timer
cjne r0,#00h,k1
clr tr0
o1:mov p1,tl0
sjmp o1
isrt1: //isr routine
clr tr1
djnz r0,l12
l12: //creating 1 second delay
mov th1,#00h
mov tl1,#00h
reti
end
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top