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 CCS Technical Support

PIC - hanging again !

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
darren logan
Guest







PIC - hanging again !
PostPosted: Mon Dec 30, 2002 5:21 am     Reply with quote

Hi all,

Hope you had a turkey-tastic christmas.

You may recall a previous post of mine regarding my PIC hanging during eeprom_reads whilst timer2 is interrupting in the background.
I solved this by disabling timer2 during the eeprom reads.

Now I have another hanging problem. As well as timer2 chugging away, I have an RS485 channel rda interrupt.
If I continuously communicate with the PIC via the RS485 channel, at some point my PIC hangs.. just like it did with the timer2 problem mentioned above. At 1st I thought it maybe the eeprom_reads again, so I disabled the rda interrupt during the reads... this did not work.

I am wondering whether my code is not getting all the serial characters which are placed in the RX buffer.. i.e. perhaps my buffer is filling up (3 chars i believe ???) and this hangs the PIC for some reason ???. Can't see how.
How do I clear the buffer in software ? (apart from reading the RX buffer ???).

Any other thoughts ?

Regards,
Darren
___________________________
This message was ported from CCS's old forum
Original Post ID: 10324
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: PIC - hanging again !
PostPosted: Mon Dec 30, 2002 8:24 am     Reply with quote

Please define your definition of "hanging-up". Is the PIC resetting, code seems to just stop, peripherials seem to quit working?

:=Hi all,
:=
:=Hope you had a turkey-tastic christmas.
:=
:=You may recall a previous post of mine regarding my PIC hanging during eeprom_reads whilst timer2 is interrupting in the background.
:=I solved this by disabling timer2 during the eeprom reads.
:=
:=Now I have another hanging problem. As well as timer2 chugging away, I have an RS485 channel rda interrupt.
:=If I continuously communicate with the PIC via the RS485 channel, at some point my PIC hangs.. just like it did with the timer2 problem mentioned above. At 1st I thought it maybe the eeprom_reads again, so I disabled the rda interrupt during the reads... this did not work.
:=
:=I am wondering whether my code is not getting all the serial characters which are placed in the RX buffer.. i.e. perhaps my buffer is filling up (3 chars i believe ???) and this hangs the PIC for some reason ???. Can't see how.
:=How do I clear the buffer in software ? (apart from reading the RX buffer ???).
:=
:=Any other thoughts ?
:=
:=Regards,
:=Darren
___________________________
This message was ported from CCS's old forum
Original Post ID: 10332
R.J.Hamlett
Guest







Re: PIC - hanging again !
PostPosted: Mon Dec 30, 2002 4:05 pm     Reply with quote

:=Hi all,
:=
:=Hope you had a turkey-tastic christmas.
:=
:=You may recall a previous post of mine regarding my PIC hanging during eeprom_reads whilst timer2 is interrupting in the background.
:=I solved this by disabling timer2 during the eeprom reads.
:=
:=Now I have another hanging problem. As well as timer2 chugging away, I have an RS485 channel rda interrupt.
:=If I continuously communicate with the PIC via the RS485 channel, at some point my PIC hangs.. just like it did with the timer2 problem mentioned above. At 1st I thought it maybe the eeprom_reads again, so I disabled the rda interrupt during the reads... this did not work.
:=
:=I am wondering whether my code is not getting all the serial characters which are placed in the RX buffer.. i.e. perhaps my buffer is filling up (3 chars i believe ???) and this hangs the PIC for some reason ???. Can't see how.
:=How do I clear the buffer in software ? (apart from reading the RX buffer ???).
:=
:=Any other thoughts ?
It could be a communication overrun.
The PIC sets the bit 'OERR', if the port overruns. In the data sheet, you then find the lovely description, that if this bit is set, further reception is disabled. The bit does not clear when you read the data. Instead you have to manually clear it, by clearing CREN, and then resetting it.
Hence your communication would die, and not recover in this situation.
Code something like this (you'll have to set up the definitions for the respective bits and bytes).

//In the receive code.
if (OERR) {
//Here read the port enough to clear the overrun -
//if necessary throw the data away.
while (RCIF) {
RCIF=0;
// put the data wherever you want here.
chr=RCREG;
}
CREN=0;
CREN=1;
}
else {
//Normal receive here


}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10336
Tomi
Guest







Re: PIC - hanging again !
PostPosted: Tue Dec 31, 2002 2:13 am     Reply with quote

The code below is nearly equivalent with the ERRORS option in #use RS232 directive Smile (ERRORS handles framing errors, too)

:=Code something like this (you'll have to set up the definitions for the respective bits and bytes).
:=
:=//In the receive code.
:=if (OERR) {
:= //Here read the port enough to clear the overrun -
:= //if necessary throw the data away.
:= while (RCIF) {
:= RCIF=0;
:= // put the data wherever you want here.
:= chr=RCREG;
:= }
:= CREN=0;
:= CREN=1;
:=}
:=else {
:= //Normal receive here
:=
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10349
darren logan
Guest







Re: PIC - hanging again !
PostPosted: Tue Dec 31, 2002 4:23 am     Reply with quote

Hello,

Thanks for the suggestions so far. I will try these asap.

PIC = 16F870, clock = 4.0MHz, PCM = 3.112

My definition of hanging is simply "getting totally stuck". Not within a loop, not resetting just stuck dead at some point.
My project has a few LEDs on it which the PIC flashes and these stop flashing. I also output data serially on another RS232 port. This data stops coming out.

I am assuming it is the interrupts causing the problem. Timer2 is running continuously:

Clock = 4.0MHz

setup_timer_2(T2_DIV_BY_16,216,16);

#int_timer2
timer2_isr() { // Timer 2 interrupt service routine (time counter)

if(ticktime--==0) {
ticktime=17;
secs++;
seccount++;
if(sysvalues[0] \% 2==0) {
edvtimer++;
if(edvtimer==sysvalues[6]) { // EDV pulse time expired
bit_clear(*6,2); // so turn off valve
}
}
if(secs==60) {
secs=0;
mins++;
if(mins==60) {
mins=0;
if(servicedone<65535) {
servicedone++;
serviceupdate=true;
}
}
}
}
}

Serial data is sent to the PIC from the PC once a second, and the PIC responds:

#int_rda
rda_isr() { // RS485 serial char in service routine

string[RS485StrPointer]=fgetc(RS485);

if(string[RS485StrPointer]==':') {
RS485StrPointer=1;
}
else {
RS485StrPointer++;
if(RS485StrPointer>=21) {
RS485StrPointer=0;
if(string[0]==':') {
DoSerialProcess=true;
}
}
}
}

The problem is that this kind of bug/error is very difficult to pin down (with just the MPLAB simulator to debug with).
What I really need is some kind of real time viewer.

To top it all off, I don't know whether it's my code or a compiler bug !.

In either case, this is really starting to frustrate me and time is running out to get this project finished.

Can anyone suggest a way to trap/debug the problem I am seeing ????. Which registers do you think I should be looking at ???

Stats for this project:

ROM used: 1899 (93\%)
Largest free fragment is 149
RAM used: 81 (63\%) at main() level
115 (90\%) worst case
Stack: 5 worst case (4 in main + 1 for interrupts)

Im using PCM 3.112 and wonder whether I really should purchase the latest edition. If I do, there is no guarantee that the problem will be solved and I cannot afford to spend this kind of cash on PCW.
If I buy PCM on it's own, does this integrate into MPLAB or do I need to buy PCW to work in MPLAB ???
Will a new PCM work in an older PCW IDE ?

(Im looking for the cheapest option to upgrade !!)

Like I say, this is really getting me down and I'd really appreciate help.

Should I really stick my neck out and ask if someone could e-mail me a new edition of PCM for me to try ????. If it works then I will not hesitate to delete it and purchase my own version. Fair is fair.

Regards,
Darren
___________________________
This message was ported from CCS's old forum
Original Post ID: 10352
Tomi
Guest







Re: PIC - hanging again !
PostPosted: Tue Dec 31, 2002 9:57 am     Reply with quote

:= if(ticktime--==0) {

I would use "if (!(--ticktime)) {" so the pre-decrement variant. In standard C "ticktime--==0" does the comparison and THEN decrements ticktime (like "*p++" does something with *p and then increments p).

Additionally, with 3.112 I have had a same problem, especially in some cases Timer2 could stop by corrupting a control register.
In my current code I call "Setup_timer2()" periodically (it is safe because it writes only the appropriate control registers again and again).

:=Serial data is sent to the PIC from the PC once a second, and the PIC responds

Try to use ERRORS option.

Finally, if you have some LEDs then you can flash them (separate LED for all periodics) e.g. negate a LED state every time the PIC enters into int_timer2, turn on a LED when the 1st char of the RS-485 packet is entered and turn off when the EOR is reached, etc.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10357
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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