  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			Cam Bruce
 
 
  Joined: 08 Sep 2003 Posts: 8
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| RTCC messing up RS232 ? | 
			 
			
				 Posted: Thu Nov 08, 2001 4:20 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Well, there went the afternoon....
 
I tried to add serial output to a previous program. I find that the baud rate out is slower than what I specify in #use rs232...
 
 
I have simplified the code down to this, and I get a jumpy square wave, at about 900Hz out C6
 
If I remark out the ENABLE_INTERRUPTS(INT_RTCC); line, everything works fine...clean square wave at 1200Hz
 
 
I want to use the WDT, so setup_counters defaults to RTCC_DIV_1.
 
And, I plan to use the Seconds counter to take readings every 15 min.
 
Any suggestions?
 
 
#include <16F877.H>
 
#fuses HS,NOPROTECT,noWDT,PUT,NOLVP	//WDT disabled for testing, NEEDS re-enabled
 
#use delay(clock=4000000)		//USING A 4MHz CRYSTAL
 
#use standard_io(C)
 
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C4)
 
 
#byte porta=5			//These lines define the Ports.
 
#byte portb=6
 
#byte portc=7
 
#byte portd=8
 
#byte porte=9
 
 
#define INTS_PER_SECOND 3906	// (4000000/(4*256))
 
LONG	SECONDS=0;			//a running real time counter.  starts at 0 on reset, counts forever.
 
long	int_count;		//interrupts left before a second has gone by.
 
////////////////////////////////////////////////////////////
 
////	THE NEXT LINES ARE THE RTCC INTERRUPT ROUTINE.	////
 
#int_rtcc				// This function is called every time
 
clock_isr()				// the RTCC (timer0) overflows (255->0).
 
{					// For this program this is 3906 times
 
if(--int_count==0)			// per second with a 4MHz crystal.
 
	{++SECONDS;
 
	int_count=INTS_PER_SECOND;	//set counter up to 3906 again.
 
	}
 
}
 
////	END OF INTERRUPT SERVICE ROUTINE		////
 
////////////////////////////////////////////////////////////
 
 
 
////////////////////////////////////////////////////////////
 
 
main() 
 
{
 
SETUP_COUNTERS(RTCC_INTERNAL,WDT_2304MS);//...2.304 Sec before Watch dog Reset. 
 
enable_interrupts(global);
 
ENABLE_INTERRUPTS(INT_RTCC);		//RTCC (Timer0) used for real time clock.
 
while(true)				//for testing
 
	putc(0x55);			//for testing
 
 
}					//end of Main.
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 1023 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: RTCC messing up RS232 ? | 
			 
			
				 Posted: Thu Nov 08, 2001 5:52 pm     | 
				     | 
			 
			
				
  | 
			 
			
				:=I tried to add serial output to a previous program. I find that the baud rate out is slower than what I specify in #use rs232...
 
:=
 
:=I have simplified the code down to this, and I get a jumpy square wave, at about 900Hz out C6
 
:=If I remark out the ENABLE_INTERRUPTS(INT_RTCC); line, everything works fine...clean square wave at 1200Hz
 
---------------------------------------------------------
 
 
If you use a software USART, the timing of the pulses is
 
controlled by software delay loops.  If you have an interrupt
 
occuring during that delay loop, then the delay will be longer
 
than intended.  
 
 
Two possible solutions:
 
1.  Use the hardware USART.
 
2.  Disable interrupts when using the software USART.
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 1024 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			Cam Bruce
 
 
  Joined: 08 Sep 2003 Posts: 8
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: RTCC messing up RS232 ? | 
			 
			
				 Posted: Fri Nov 09, 2001 8:23 am     | 
				     | 
			 
			
				
  | 
			 
			
				:=:=I tried to add serial output to a previous program. I find that the baud rate out is slower than what I specify in #use rs232...
 
:=:=
 
:=:=I have simplified the code down to this, and I get a jumpy square wave, at about 900Hz out C6
 
:=:=If I remark out the ENABLE_INTERRUPTS(INT_RTCC); line, everything works fine...clean square wave at 1200Hz
 
:=---------------------------------------------------------
 
:=
 
:=If you use a software USART, the timing of the pulses is
 
:=controlled by software delay loops.  If you have an interrupt
 
:=occuring during that delay loop, then the delay will be longer
 
:=than intended.  
 
:=
 
:=Two possible solutions:
 
:=1.  Use the hardware USART.
 
:=2.  Disable interrupts when using the software USART.
 
 
That makes sence.
 
I think I'll go with disabling the interrupts during the serial data.
 
Does that mean the delay_ms() and Delay_us() will also interfere with the RTCC?
 
Thanks Again  Cam
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 1033 | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
  | 
   
 
  
Powered by phpBB © 2001, 2005 phpBB Group
  
		 |