Page 1 of 1

Pic still freezing

Posted: Fri Oct 26, 2012 6:59 pm
by Desdewit
Hi Guys

Please see if you can help this is getting very annoying :evil: :evil:
I cannot get my pic to stop freezing after receiving rs232 data for a while. Could this be a flowcode or pic error?
It seems that the only way to get it running again is by doing a reset. (And that I do not want to do.)
The bytes are received in strings of 84 bytes every 500ms, after every 14 bytes I must do a checksum and make sure byte 8 of each 14 is 0 then 1 then 2, 3, 4 and 5.
Sometimes it will run for a long time before freezing.

I'm using a Pic18f252 with hardware & software Usart.
19660800Hz Crystal
V3 Development board HP488
Maxim232

Received data sample:

001 000 010 129 255 001 001 000 000 000 000 000 000 140
001 000 010 129 000 001 001 001 000 000 000 077 188 151
001 000 010 129 001 001 001 002 000 000 000 019 017 180
001 000 010 129 002 001 001 003 000 000 000 019 136 045
001 000 010 129 003 001 001 004 000 000 000 019 178 089
001 000 010 129 004 001 001 005 000 000 000 019 136 049

Re: Pic still freezing

Posted: Fri Oct 26, 2012 9:42 pm
by kersing
Making your program available so we can test might help...

Re: Pic still freezing

Posted: Sat Oct 27, 2012 7:42 am
by Desdewit
Hi Kersing

I've attatched the file.

Re: Pic still freezing

Posted: Sat Oct 27, 2012 9:49 am
by Enamul
Hi,
It should work now..RXINT can't work without peripheral interrupt enable. If you use RXINT you don't need to wait so long for data, 1 time out should be fine but for safety I put 5. Let me know how you are getting..

Re: Pic still freezing

Posted: Sat Oct 27, 2012 10:56 am
by Desdewit
Thanks Enamul

So far the pic does not freeze even after an error.
Do you know why the pic freezes if the peripheral interrupt are not enabled?
Do you know if there is a specific reason why flowcode does not enable the peripheral interrupt when RXInt are chosen?

Re: Pic still freezing

Posted: Sat Oct 27, 2012 11:39 am
by Enamul
It was a bug in Flowcode and Ben posted a fix for all FCDs but seems that you didn't notice that and lots of other user like you didn't notice that.

Re: Pic still freezing

Posted: Wed Oct 31, 2012 3:41 pm
by Benj
Hello,

Is the device still freezing for you? It sounded from what you posted like the problem had been resolved.

My guess is that the freezing is caused by a stack overflow (too many jumps away from main) in which case enabling the software stack should solve this problem. Search the forums for software stack and you should find the solution to allow you to do this.

Another cause could be that code is being executed and then the interrupt kicks in and tries to call the same piece of code which can lead to corrupted variable values etc when you return to the original routine. To get around this try setting a flag in the interrupt macro and then servicing the flag somewhere in your main routine. Circular buffers may be an option if you need interrupt data to accumilate until you are free to process it.

Re: Pic still freezing

Posted: Wed Oct 31, 2012 5:43 pm
by Desdewit
Hi Ben

Sorry about the confusion, the program is in two parts with one (Hardware TX & RX) & one (Software TX & Rx). At first the two programs were running separately with problems that Enamul help solved, but when I combined the two programs a whole new set of errors & warning messages started again

Serious Warning: Possible sw stack corruption, function 'FC_CAL_UART_Delay_1' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_us' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

I've tried solving the problem by adding -swcs 6 2 to the Parameters like suggested in the forums but then receive "Error: Failed to open:6" ". Error: Failed to open:2."

Re: Pic still freezing

Posted: Wed Oct 31, 2012 6:07 pm
by Benj
Hello,

Are you sure you put the additional parameters into the linker params text field and not the compiler one.

Re: Pic still freezing

Posted: Wed Oct 31, 2012 8:38 pm
by Desdewit
Hi Benj

This is the line from my Linker/Assembler Parameters:

-ld "C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib" libc.pic16.lib rand.pic16.lib float.pic16.lib "%f.obj" -t PIC%p -d "%d" -p "%f"-swcs 6 2

Please confirm that this is correct?

If I change my receive routine like this the warning messages are gone and so far the program keeps running, but I get more receiving errors.
Are there anything you can see wrong with this part of my routine that might cause the receive errors?
I’ve tested the program with 4Mhz & 19.6608Mhz Crystal @ 9600 baud.
I’m using RB0Int with software usart for this part of the routine

Re: Pic still freezing

Posted: Fri Nov 02, 2012 11:41 am
by Desdewit
Hi

If I use hardware and software RS232 on a 18f252 & disable “RXint” while using “RB0int” to receive and then later disable “RB0int” and enable “RXint” and so on, will it cause any type of problems :?:

Re: Pic still freezing

Posted: Fri Nov 02, 2012 12:14 pm
by Benj
Hello,
-ld "C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib" libc.pic16.lib rand.pic16.lib float.pic16.lib "%f.obj" -t PIC%p -d "%d" -p "%f"-swcs 6 2
This looks to be correct to me.
If I use hardware and software RS232 on a 18f252 & disable “RXint” while using “RB0int” to receive and then later disable “RB0int” and enable “RXint” and so on, will it cause any type of problems :?:
Cant see any issues with doing this as long as you don't mind missing data if both UARTS receive at exactly the same time. The hardware UART should buffer up to 2 bytes anyway so as long as you service the software UART as the data is coming in then you should be ok.