| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Einly 
 
 
 Joined: 10 Sep 2003
 Posts: 60
 
 
 
			            
 
 | 
			
				| delay_us |  
				|  Posted: Tue May 03, 2005 9:47 am |   |  
				| 
 |  
				| Dear all, 
 I am using 2 timer interrupt in my program (timer 0 and timer 1). Timer 0 is used to count for 1s. In this 1 second interval, timer 1 is used to count the pulses that is received. I would like to use Pin B0 interrupt which will set Pin C0 high for 7us. If I have a delay_us(7) in the pin B0 interrupt routine, will this affect the other timers operation? What will happen during the delay_us(7) line?
 
 Thanks a lot
 _________________
 Einly
 |  | 
	
		|  | 
	
		| rwyoung 
 
 
 Joined: 12 Nov 2003
 Posts: 563
 Location: Lawrence, KS  USA
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Tue May 03, 2005 10:04 am |   |  
				| 
 |  
				| Using the delay_us, delay_ms and delay_cycles functions inside interrupt service routines is generally a bad idea. 
 Unless you are writing your own interrupt handler there is a significant chance you will increase the latency of other interrupts because you have blocked them with a dead-head loop of NOPs inside another ISR.
 
 ISRs should be short and to the point.  Get in and get out of the ISR as quickly as you can.
 _________________
 Rob Young
 The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue May 03, 2005 12:13 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | If I have a delay_us(7) in the pin B0 interrupt routine, will this affect the other timers operation? What will happen during the delay_us(7) line?
 | 
 The relative affect of a 7 usec delay also depends upon your oscillator
 frequency.   If you are using a 4 MHz crystal, then one instruction cycle
 takes 1 usec.    Just to get in and out of an interrupt service routine
 will take at least 50 usec, due to the length of the CCS interrupt
 dispatcher routine.    Let's say your other code in the isr takes 10 usec
 then you now have 60 usec just to process your interrupt.   Adding 7
 more usec to that, really isn't going to hurt anything.
 |  | 
	
		|  | 
	
		|  |