PDA

View Full Version : Re: PIC18F252



Steve_88
- 20th January 2008, 00:25
Hey Group,

I'm hung up on something really simple, I would like to be able to set a flag in software if the WDT causes a reset. I'm displaying the RCON register bits and getting no change in the value. The WDT is enabled and working i think because my led briefly goes out every few seconds. I've searched the list and just can't get it figured out,

Thanks,
Steve

Darrel Taylor
- 20th January 2008, 03:05
Hi Steve,

DEFINE NO_CLRWDT 1

Stops PBP from clearing the WDT, but it can't do anything about the bootloader.
As soon as the bootloader executes a clrwdt, it resets the TO timeout bit.

Without ICSP, or a bootloader that doesn't clear the WDT, you won't be able to detect a WDT timeout.
<br>

Steve_88
- 20th January 2008, 19:03
Hi Darrel,

Thanks for the info. If you have a minute, could you explain a little different? Is the boot loader software really interferring with the WDT? ...lol

I'm trying to use the WDT to escape from a SERIN command with timeout where the baud rate of the PIC and peripheral are different, maybe there is a better way?

Sincerely,

Steve

Darrel Taylor
- 20th January 2008, 19:50
Is the boot loader software really interfering with the WDT?I guess it depends on the bootloader.

Before answering last time, I imported the Mecanique loader for the 18F252 into MPLAB, just to make sure.

On any reset, there is a period of time that the loader waits for activity from the USART. If it sees activity, it jumps to the bootloader, and if not, it times out and jumps to the user program.

During that period, it has to make sure the WDT doesn't timeout, so it uses the CLRWDT instruction.

When CLRWDT is executed, it sets the RCON TO (timeout) bit to 1, which means that no timeout has occurred. Anytime you want to catch a WDT reset, you have to do it at the very beginning of the program, before any CLRWDT instructions have been executed. But since the bootloader itself resets it, you can't.


I'm trying to use the WDT to escape from a SERIN command with timeout where the baud rate of the PIC and peripheral are different, maybe there is a better way?

There are 2 better ways that I can think of.

1. Use ICSP instead of a bootloader.

2. Use SERIN2. Set a very long timeout period in the SERIN2 statement. Then use interrupts with a timer for the timeout period.

When the timeout expires, clear the PBP system variable that is tracking the SERIN2's timeout. Which should cause the SERIN2 statement to terminate.

If you decide to go route #2, I can search through the library to find out which system vars to use. But I would suggest just using ICSP.

hth,

Added:

3. Don't use the bootloader. Which frees up the USART. Then use the USART for the serial communications.

If the USART is receiving data at a different baud rate than expected, it will throw a Framing Error immediately, so you don't need to worry about the timeout.

Steve_88
- 21st January 2008, 17:02
Hi Darrel,

Thanks for the explanation, it makes sense now ;)

I think I'll leave the issue alone for now, it's not really critical for my project.

Thanks again,

Steve