View previous topic :: View next topic |
Author |
Message |
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
WDT |
Posted: Fri Apr 02, 2010 7:23 am |
|
|
Hello,
I have a little problem, my PIC works well and WTD works. I test it by changing timing and as long as it is WDT<256 my PIC loops forever during start - so I know WDT works. However when I send 999 calls over RS232 with interval of <=5ms it hangs some times and WDT never resets the unit. I use 18F4520 and PCH - any clues what could cause such thing?
Initial setup as follows:
Code: |
...
#fuses MCLR, BROWNOUT , NOPROTECT, WDT256, HS, PUT, NOCPD
...
void main() {
int ...
int ...
...();
setup_wdt(WDT_ON);
disable_interrupts(GLOBAL);
set_timer0(0);
set_rtcc(0);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RTCC);
setup_timer_0(RTCC_EXT_L_TO_H| RTCC_DIV_256);
setup_adc_ports( ALL_ANALOG );
setup_adc_ports(AN0_TO_AN7);
setup_adc(ADC_CLOCK_DIV_8);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(int_rda);
...
while...{
}
}
|
Thank you. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 02, 2010 9:57 am |
|
|
Post a small compilable program that shows the problem, and post
your compiler version. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Fri Apr 02, 2010 6:12 pm |
|
|
PCH 4.104
will do some program and post in later on.
Thank you _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Fri Apr 02, 2010 10:22 pm |
|
|
I have found a problem and I think it will affect any pic on hardware UART.
So it is as follows:
I send 999 messages without any break (not even 1ms) so as my speed goes 19200 over rs485 the delay between each message is almost nothing.
Then processor is receiving data, processing it and as is meant to do it tries to send an answer. An this is a problem because I hit it almost instantly with another message on RX. It is in half of sending a thing when my IRQ kicks on and breaks TX. Then whole CPU hangs. It must be a hardware thing because WDT stops working as well. I imagine setting TX up and in the same time get RX going. Because of half duplex on rs485 the bus is getting high and UART is bombarded with wrong potentials and crashing whole unit.
So in TX routine I have added:
Code: |
if (!kbhit()) {
disable_interrupts(int_rda);
comms_TX_high();
printf("%c",TX);
comms_TX_low();
enable_interrupts(int_rda);
}
|
and it fixed the problem.
Thank you _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
|