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

PIC failure, serial communication and watchdog
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gon
Guest







PIC failure, serial communication and watchdog
PostPosted: Fri Mar 10, 2006 4:07 am     Reply with quote

Hello,

i use a PIC 18F458 and i wondered if it was possible the make the PIC fail with serial communication ?

I send ascii characters to the PIC, and everythoing works, and it seems that if i type too 'fast' on the keyboard, the pic does not what it should, but it does not reset itself as well although the watchdog is on...

while(counter < 600)
{
restart_wdt();
if(kbhit()) init = getc();
else init = 0;
switch(init)
{
case 'A' : printf("\n\r case 0");
break;
case 'B' : printf("\n\r case 1");
break;
default : printf("\n\r case default");
break;
}
counter++;
delay_ms(100);
}

Would have any explanation or solution ?
Many thanks.
Best regards.
Gerrit



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

PostPosted: Fri Mar 10, 2006 4:30 am     Reply with quote

Hi Gon,

Try looking at overrun error serial port.

Or make your own interupt handler for serial communication.

Search the forum for ringbuffer en oer (overrun error)

Goodluck,

Gerrit
Gon
Guest







PostPosted: Fri Mar 10, 2006 7:03 am     Reply with quote

Ok, many thanks !

My problem is solved i think by handling the overrun error.

But it does not tell me why the watchdog does not reset the pic...
Gon
Guest







PostPosted: Mon Mar 13, 2006 3:38 am     Reply with quote

Is it possible that with an overrun error, the pic does not reset by watchdog ?
When i make it fail, I see that the interrrupts are still working, but the main programm is not running like it should, so could the main programm fail without resetting by watchdog and allowing the interrupts to work ?
Ttelmah
Guest







PostPosted: Mon Mar 13, 2006 4:19 am     Reply with quote

An 'overrun error', is triggered if you do not handle serial characters fast enough. Now the problem in your code, is that receipt of a single character, can result in fifteen characters being sent back. There are only a couple of characters of hardware buffering (at best) in each direction, so, if three characters arrive quickly, there will be a hardware overrun.
The hardware overrun itself, will not trigger a watchdog timeout. It only disables the UART, not the processor itself. You could write your code to force a watchdog timeout, by having it so that the restart_wdt call, is only called of the overrun error flag is not set. This is down to _you_.
better by far, to buffer the serial transmission, then thie problem would not arrive.

Best Wishes
Gon
Guest







PostPosted: Mon Mar 13, 2006 4:51 am     Reply with quote

Thank you very much Ttelmah for your answers.

So, you mean that although i have a restart_wdt() and that, in this case, the UART is disabled, my programm is still kind of running so it won't reset by watchdog, but not doing what it should do ?

I solved the serial problem and i think i won't have this case anymore but i need to understand really what was wrong !
Because in this case, the watchdog was not useful at all but it should be !
Ttelmah
Guest







PostPosted: Mon Mar 13, 2006 7:59 am     Reply with quote

Gon wrote:
Thank you very much Ttelmah for your answers.

So, you mean that although i have a restart_wdt() and that, in this case, the UART is disabled, my programm is still kind of running so it won't reset by watchdog, but not doing what it should do ?

I solved the serial problem and i think i won't have this case anymore but i need to understand really what was wrong !
Because in this case, the watchdog was not useful at all but it should be !

Exactly. The program will loop if no characters are arriving, and keep resetting the watchdog. The program is 'running', so no watchdog timeout occurs, but will never see any arriving characters, because the UART is itself 'locked up'. Adding the 'ERRORS' statement to the USE RS232 command, tells the code to check for such an overrun, and reset the UART.
What you could do, as a way of forcing a watchdog timeout, would be (for instance), to have a counter in the waiting loop, which is reset if a character is 'seen'. If the counter reaches some arbitrary value set by you, stop resetting the watchdog. This way if data is regularly expected, and does not arrive, you can force a restart.

Best Wishes
Gon
Guest







PostPosted: Mon Mar 13, 2006 8:38 am     Reply with quote

Hello,

Thanks again for answers.
This is exactly what i have done.

But last question : the trouble is if you look at my programm, i putted a
while(counter < 600), that means that when counter will be 600 (because the incrementation is done after), it should get out of this loop but it does not...
Does it mean that whatever the main programm has done, if an overrun error occurs, it is not doing anything else ?

Whatever if the UART is disabled, can't my counter makes it out of the loop ?
Ttelmah
Guest







PostPosted: Mon Mar 13, 2006 9:01 am     Reply with quote

There is not enough of your code, to know what is really likely to happen. First, the timings involved?. How fast is the PIC running?. What interval are characters likely to come at?. What is the baud rate?. What happens to the wacthdog, outide this loop?. How is 'counter' declared?. If (for instance), counter is declared as an int, then the loop will never exit since an int, cannot reach 600...

Best Wishes
Gon
Guest







PostPosted: Mon Mar 13, 2006 9:18 am     Reply with quote

Quote:
How fast is the PIC running?

#use delay(clock = 4000000)

Quote:
What interval are characters likely to come at?

It is when i decide, i connect a laptop to enter characters.

Quote:
What is the baud rate?

baud = 9600

Quote:
What happens to the watchdog, outide this loop?

The watchdog is still refreshed by another thing, but outside of the loop, it shoul output low the led that shows that it is out of the loop.

Quote:
How is 'counter' declared?. If (for instance), counter is declared as an int, then the loop will never exit since an int, cannot reach 600...


It is an int32 :p
Guest








PostPosted: Tue Mar 14, 2006 2:29 am     Reply with quote

UP !
Gon
Guest







Gon
PostPosted: Wed Mar 15, 2006 3:51 am     Reply with quote

Is the kbhit function still working, if uart is disabled ?

And please a suggestion for this :
Quote:
But last question : the trouble is if you look at my programm, i putted a
while(counter < 600), that means that when counter will be 600 (because the incrementation is done after), it should get out of this loop but it does not...
Does it mean that whatever the main programm has done, if an overrun error occurs, it is not doing anything else ?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: Gon
PostPosted: Wed Mar 15, 2006 5:09 am     Reply with quote

Gon wrote:
And please a suggestion for this :
Quote:
But last question : the trouble is if you look at my programm, i putted a
while(counter < 600), that means that when counter will be 600 (because the incrementation is done after), it should get out of this loop but it does not...
Does it mean that whatever the main programm has done, if an overrun error occurs, it is not doing anything else ?
How do you know it doesn't jump out of the loop? Did you wait long enough to see the end result?
600 * 10ms delay = 60 seconds
600 * printf("\n\r case default") = 10 seconds
-------------------
Total 70 seconds

Improve your test by printing the value of the counter variable:
Code:
  default : printf("\n\r default %ld", counter);
Gon
Guest







PostPosted: Wed Mar 15, 2006 5:14 am     Reply with quote

I tested thing a lot of time before, and do it every day maybe 50 times for a long time now, and i know this is working.
Gon
Guest







PostPosted: Wed Mar 15, 2006 5:19 am     Reply with quote

I will test it again i think i may be wrong in the time i should wait...
Hope so ...

Thanks for help! Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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