View previous topic :: View next topic |
Author |
Message |
Ron_TippiX
Joined: 03 May 2010 Posts: 2
|
getc() conflict with watchdog delay |
Posted: Mon May 03, 2010 7:57 am |
|
|
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: 19546
|
|
Posted: Mon May 03, 2010 9:04 am |
|
|
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
|
|
Posted: Mon May 03, 2010 9:32 pm |
|
|
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. |
|
|
|