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 CCS Technical Support

getc() conflict with watchdog delay

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



Joined: 03 May 2010
Posts: 2

View user's profile Send private message

getc() conflict with watchdog delay
PostPosted: Mon May 03, 2010 7:57 am     Reply with quote

I am currently using software UART to poll the RS232 line. Here is the RS232 setup and the fuction that is causing me issues:
Code:

#use delay(clock = 4000000, RESTART_WDT)

#use rs232(baud=38400,bits=8, xmit=PIN_C4, rcv=PIN_A4,RESTART_WDT)
#use standard_io(A)

unsigned char get_ch(void)
{
   long timeout=10;

   while(!kbhit() && (++timeout<180) );
   
   if(kbhit())   
      return getc();
   else
      return (0) ;
   
}


My current problem is that kbhit() is always returning a TRUE even if I am connecting the RS232 receive pin to a ground. This causes the function to jumpt straight to getc() and then the system will trigger the watchdog shortly after.

Through troubleshooting, i have observed that if I were to change the delay clock to 8mHz then the kbhit will function properly. System will start incrementing the timeout variable until kbhit is triggered.


Code:
#use delay(clock = 8000000, RESTART_WDT)


Now I need my code to work with 4mHz given all other interrupts were triggerred around those time sensitive setups. anyone can let me know where could the issue be?
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon May 03, 2010 9:04 am     Reply with quote

Pulling the receive pin to ground, will _make_ kbhit return 'true'. For TTL logic async serial (which is what the PIC receives), the 'idle' state is 5v. Kbhit returns 'true', when a start bit (0v), is seen on the line (for software serial), or 9 bit times later (for hardware serial).

Best Wishes
Ron_TippiX



Joined: 03 May 2010
Posts: 2

View user's profile Send private message

PostPosted: Mon May 03, 2010 9:32 pm     Reply with quote

you are absolutely right. I need to put the line to 5V and not to ground. I have tested with 5V and now I can see the system timeout properly. Will put a pull-up resistor and see how the system reacts.

thanks for the note.
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