CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RS232 problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
16LF73
Guest







RS232 problem
PostPosted: Tue Oct 07, 2008 9:23 am     Reply with quote

Chip: 16LF76 CCS version: 3.1110
Code:
#use Delay(Clock=153600,RESTART_WDT)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=n,bits=8,ERRORS)

I use RS232 to interface an OEM module. Timer1 interrupt is used for some background tasks (such as blinking LEDs etc)

Because the clock is slow (153.6K), I have to short the Timer1 routine to less than 2 ms, otherwise, PIC constantly misses RS232 input data (the received data is garbled). Even when Timer1 rountine is less than 1 ms, PIC still sometimes (about 2%) misses RS232 data.

Any suggestions?

PIC uses Timer0, right? Could I change the frequency of timer0 interrupt?

Regards,
Ttelmah
Guest







PostPosted: Tue Oct 07, 2008 10:23 am     Reply with quote

Seriously, at this clock, the system executes just 38400 instructions per second. 9600bps, means a character can arrive every 1/960th second, or every 40 instructions. The way you talk about the timer being used in the 'background', suggests you are using an interrupt. If so, 'no way' is it going to work reliably. The interrupt handler has a typical overhead of nearly 60 instructions...
Don't implement interrupts. Instead have a fast loop running that tests the RS232 received flag (if kbhit), receiving a character if one is waiting, then tests the timer interrupt flag, and services this if it has set. Clear it, and loop as fast as possible. However even doing this, if data arrives at high speed, and the timer routines take more than a very few instructions, expect to lose data.
You just don't have enough clock speed to do the jobs you want.

Best Wishes
16LF73
Guest







RS232 problem
PostPosted: Tue Oct 07, 2008 1:18 pm     Reply with quote

Ttelmath, Thanks for your reply.

Yes. Timer1 is using an interrupt (every 200 ms).

RS232 is using "both interrupt and loop" ------- when received the first char, PIC goes to RS232 ISR rountine, then tests (LOOP) the RS232 receiving flag to receive whole message. after received whole message, it exits RS232 ISR.
Ttelmah
Guest







PostPosted: Tue Oct 07, 2008 2:03 pm     Reply with quote

At your clock rate, it is going to take more than 1mSec, to even get into, and out of the interrupt routine. Even with the interrupt routine _itself_ being less than 1mSec, the total time in the ISR, is going to be perhaps 2.5mSec. It then takes moe than half a mSec to get into the RS232 ISR. This adds up to more than the total buffering available for the chip, hence data is lost. Hence my suggestion to not involve interrupt handling at all, but stay out in the 'main', and poll the interrupt bits. This is potentially much faster.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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