|
|
View previous topic :: View next topic |
Author |
Message |
Gon Guest
|
PIC failure, serial communication and watchdog |
Posted: Fri Mar 10, 2006 4:07 am |
|
|
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
|
|
Posted: Fri Mar 10, 2006 4:30 am |
|
|
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
|
|
Posted: Fri Mar 10, 2006 7:03 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 3:38 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 4:19 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 4:51 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 7:59 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 8:38 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 9:01 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 9:18 am |
|
|
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
|
|
Posted: Tue Mar 14, 2006 2:29 am |
|
|
UP ! |
|
|
Gon Guest
|
Gon |
Posted: Wed Mar 15, 2006 3:51 am |
|
|
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
|
Re: Gon |
Posted: Wed Mar 15, 2006 5:09 am |
|
|
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
|
|
Posted: Wed Mar 15, 2006 5:14 am |
|
|
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
|
|
Posted: Wed Mar 15, 2006 5:19 am |
|
|
I will test it again i think i may be wrong in the time i should wait...
Hope so ...
Thanks for help! |
|
|
|
|
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
|