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 support@ccsinfo.com

Please help, code attached.

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







Please help, code attached.
PostPosted: Wed Aug 07, 2002 10:35 am     Reply with quote

Hi all, I've tried to search the forums for an answer and I haven't seen anything that directly relates. Please point me in the right direction if this has already been covered.

My problem is that for some reason my PIC seems to be resetting in the middle of a function call. I have attached what code I can, there are function calls [GetDatum(), FillMatrix() and SolveMatrix()] that I cannot post due to confidentiality agreements. Some of these functions do some hefty math, but should have no relevance to the problem at hand, but I could be wrong.

Basically, heres the code:

#include <16F877.h> //specify processor
#device *=16 //pointer size
#use delay(clock=20000000) //crystal (20MHz)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=HOSTPC) //define RS232 pins

#define CTS PIN_B0
#define RTS PIN_B1
#define D1 PIN_B2
#define D2 PIN_B3
#define D3 PIN_B4
#define D4 PIN_B5
#define CI PIN_B6
#define CO PIN_B7

#use standard_IO(B) //dictate standard IO for port b
#use standard_IO(C) //dictate standard IO for port c

int8 CONST BOARD_TYPE = 0x50; //upper nibble of address byte
int8 CONST VERSION = 4; //version #
int8 CONST REVISION = 0; //revision #
int8 CONST NUM_CMDS = 3; //number of commands supported by this board
int8 CONST COLLECT = 1;
int8 CONST TIMING = 2;

and revision are defined
#define MATHPIC
#define DATAPORT input_b()
#define DATAMASK 0b00111100
#define BITSHIFT1 2
#define BITSHIFT2 2

float a1, a11, a12, a13, a21, a22, a23, a31, a32, a33; //pseudo matrix
float b1, b2, b3; //pseudo array

void main(){
int8 i=0; //loop iterator
int32 p,c; //previous and current data points
float r; //result

setup_adc_ports(NO_ANALOGS); //set the multiplexed analog pins to be digital I/O
fprintf(HOSTPC,"[Start]");

While(TRUE)
{ //infinite loop
p=GetDatum();
fprintf(HOSTPC,"[1 - \%lu]",p);
for(i=2;i<11;i++){
c=GetDatum();
FillMatrix(p,c,i-1);
fprintf(HOSTPC,"[\%i - \%lu]",i,c);
p=c;
}// next i
r=SolveMatrix();
fprintf(HOSTPC,"[\%f]",5.0);// ***
}//end while
}//end main

and here's the output which repeats consistently:
[Start][1 - 390][2 - 561][3 - 694][4 - 798][5 - 875][6 - 932][7 - 981][8 - 1016][9 - 1040][10 - 1063][5.000000[Start][1 - 390][2 - 561][3 - 694][4 - 798][5 - 875][6 - 932][7 - 981][8 - 1016][9 - 1040][10 - 1063][5.000000[Start]...

My question is, how does it print the [Start] more than once, and how does it do it in the middle of an fprintf call? When printing the [5.000000 there should be a closing bracket, I mean it's all part of the same call. The only explanation I can give my boss is that somehow the PIC is being reset during the middle of the call. Has anyone seen this before, and if so, is there some kind of work around I should know about. Generally I hate begging for help, but I've spent two days trying to fix this, and any help, even if its just to say that its just the way the world is and it can't be fixed will be appreciated.
___________________________
This message was ported from CCS's old forum
Original Post ID: 6145
R.J.Hamlett
Guest







Re: Please help, code attached.
PostPosted: Wed Aug 07, 2002 10:56 am     Reply with quote

:=Hi all, I've tried to search the forums for an answer and I haven't seen anything that directly relates. Please point me in the right direction if this has already been covered.
:=
:=My problem is that for some reason my PIC seems to be resetting in the middle of a function call. I have attached what code I can, there are function calls [GetDatum(), FillMatrix() and SolveMatrix()] that I cannot post due to confidentiality agreements. Some of these functions do some hefty math, but should have no relevance to the problem at hand, but I could be wrong.
:=
Obvious thing, without even looking at the code. What is the WDT being set to?. You are not adding a #fuses statement, so are presumably setting this manually at the programmer....
If this is timing out, the processor will reset. You can diagnose/verify what is going on, by replacing your 'start' printout with:
fprintf(HOSTPC,"Reason:- \%3d",restart_cause());
If you get a value of 8, then the watchdog has timed out.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 6146
robertm1771
Guest







Re: Please help, code attached.
PostPosted: Wed Aug 07, 2002 11:19 am     Reply with quote

I have a problem just like what you are saying my code seems to reset for no resion at all. But I know what code to chage to fix my problem. Here is the code I have to change to fix my problem. My code over all is taking up about 4K of the 8K ROM in the 16F876

This will make my code loop;

InitStepper () {

delay_ms(5);
printf(putc2,"BB6000PP");
printf(putc2,"YY10000RR");
printf(putc2,""XX6000RR)");
printf(putc2,"BB6000PP");
printf(putc2,"YY10000RR");
printf(putc2,""XX6000RR)");
printf(putc2,"B-S");
printf(putc2,"B+S");
printf(bputc," Ready ");
}

If I use this my code will function as it should

InitStepper () {

delay_ms(5);
printf(putc2,"B6000P");
printf(putc2,"Y10000R");
printf(putc2,"X6000R)");
printf(putc2,"B6000P");
printf(putc2,"Y10000R");
printf(putc2,"X6000R)");
printf(putc2,"B-S");
printf(putc2,"B+S");
printf(bputc," Ready ");
}

I have tried using #opt 0 to see if it would help and it does not.

So now I have 2 weeks of coding and alot of little bugs and I wonder if its my bugs or this POS PCW software.

Am getting ready to update to the newest version but I figure I will have the same problem. If an upgrade fixes my problem I will let you know


:=Hi all, I've tried to search the forums for an answer and I haven't seen anything that directly relates. Please point me in the right direction if this has already been covered.
:=
:=My problem is that for some reason my PIC seems to be resetting in the middle of a function call. I have attached what code I can, there are function calls [GetDatum(), FillMatrix() and SolveMatrix()] that I cannot post due to confidentiality agreements. Some of these functions do some hefty math, but should have no relevance to the problem at hand, but I could be wrong.
:=
:=Basically, heres the code:

:=My question is, how does it print the [Start] more than once, and how does it do it in the middle of an fprintf call? When printing the [5.000000 there should be a closing bracket, I mean it's all part of the same call. The only explanation I can give my boss is that somehow the PIC is being reset during the middle of the call. Has anyone seen this before, and if so, is there some kind of work around I should know about. Generally I hate begging for help, but I've spent two days trying to fix this, and any help, even if its just to say that its just the way the world is and it can't be fixed will be appreciated.
___________________________
This message was ported from CCS's old forum
Original Post ID: 6147
SpeeDem0n
Guest







Re: Please help, code attached.
PostPosted: Wed Aug 07, 2002 12:28 pm     Reply with quote

:=Obvious thing, without even looking at the code. What is the WDT being set to?. You are not adding a #fuses statement, so are presumably setting this manually at the programmer....
:=If this is timing out, the processor will reset. You can diagnose/verify what is going on, by replacing your 'start' printout with:
:=fprintf(HOSTPC,"Reason:- \%3d",restart_cause());
:=If you get a value of 8, then the watchdog has timed out.
:=
:=Best Wishes

First, let me thank you all for taking the time to read and post thoughts on my problem.

I am disabling the WDT and the Power up timer via the programmer. I'm using a PICSTART Plus and developing in the MPLAB IDE. I stuck with the MPLAB IDE since I used to code in Pic BASIC Pro and it didn't have it's own IDE. I switched to CCS PICC due to the fact that it supported 32 bit math/variables without any need for writing/calling assembly routines.

In any case, I replace the printing of start with the restart_cause(). The return value was 24, which I looked up in the device header to be NORMAL_POWER_UP. I've checked the power supply voltages and they are stable, and I have multiple boards w/ PICs on them in the same bus drawing from the same p/s and they run fine. Also, the symptoms go away if I comment out the fprintf(HOSTPC,"[\%f]",5.0).

I'm well aware that I may be doing some 'badnesses' in my math that would cause problems, but I would expect that if I were to fubar a pointer things would crash immediately, not in the middle of a built in function call.

I'll keep prodding my code and update if I find anything, and also check back here to see if some saintly genius has any pearls of wisdom.

Thanks in advance for any help.
___________________________
This message was ported from CCS's old forum
Original Post ID: 6151
Nicholas Kinnas
Guest







Re: Please help, code attached.
PostPosted: Thu Aug 08, 2002 8:54 am     Reply with quote

<font face="Courier New" size=-1>:=Hi all, I've tried to search the forums for an answer and I haven't seen anything that directly relates. Please point me in the right direction if this has already been covered.
:=
:=My problem is that for some reason my PIC seems to be resetting in the middle of a function call. I have attached what code I can, there are function calls [GetDatum(), FillMatrix() and SolveMatrix()] that I cannot post due to confidentiality agreements. Some of these functions do some hefty math, but should have no relevance to the problem at hand, but I could be wrong.
:=

From looking at your code, I would say you are crashing the processor on the call to print the float. You may need to cast the float. Or just try printing anything else at this point to see if it fixes your problem
:=Basically, heres the code:
:=
:=#include <16F877.h> //specify processor
:=#device *=16 //pointer size
:=#use delay(clock=20000000) //crystal (20MHz)
:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=HOSTPC) //define RS232 pins
:=
:=#define CTS PIN_B0
:=#define RTS PIN_B1
:=#define D1 PIN_B2
:=#define D2 PIN_B3
:=#define D3 PIN_B4
:=#define D4 PIN_B5
:=#define CI PIN_B6
:=#define CO PIN_B7
:=
:=#use standard_IO(B) //dictate standard IO for port b
:=#use standard_IO(C) //dictate standard IO for port c
:=
:=int8 CONST BOARD_TYPE = 0x50; //upper nibble of address byte
:=int8 CONST VERSION = 4; //version #
:=int8 CONST REVISION = 0; //revision #
:=int8 CONST NUM_CMDS = 3; //number of commands supported by this board
:=int8 CONST COLLECT = 1;
:=int8 CONST TIMING = 2;
:=
:=and revision are defined
:=#define MATHPIC
:=#define DATAPORT input_b()
:=#define DATAMASK 0b00111100
:=#define BITSHIFT1 2
:=#define BITSHIFT2 2
:=
:=float a1, a11, a12, a13, a21, a22, a23, a31, a32, a33; //pseudo matrix
:=float b1, b2, b3; //pseudo array
:=
:=void main(){
:= int8 i=0; //loop iterator
:= int32 p,c; //previous and current data points
:= float r; //result
:=
:= setup_adc_ports(NO_ANALOGS); //set the multiplexed analog pins to be digital I/O
:= fprintf(HOSTPC,"[Start]");
:=
:= While(TRUE)
:= { //infinite loop
:= p=GetDatum();
:= fprintf(HOSTPC,"[1 - \%lu]",p);
:= for(i=2;i<11;i++){
:= c=GetDatum();
:= FillMatrix(p,c,i-1);
:= fprintf(HOSTPC,"[\%i - \%lu]",i,c);
:= p=c;
:= }// next i
:= r=SolveMatrix();
:= fprintf(HOSTPC,"[\%f]",5.0);// ***
:= }//end while
:=}//end main
:=
:=and here's the output which repeats consistently:
:=[Start][1 - 390][2 - 561][3 - 694][4 - 798][5 - 875][6 - 932][7 - 981][8 - 1016][9 - 1040][10 - 1063][5.000000[Start][1 - 390][2 - 561][3 - 694][4 - 798][5 - 875][6 - 932][7 - 981][8 - 1016][9 - 1040][10 - 1063][5.000000[Start]...
:=
:=My question is, how does it print the [Start] more than once, and how does it do it in the middle of an fprintf call? When printing the [5.000000 there should be a closing bracket, I mean it's all part of the same call. The only explanation I can give my boss is that somehow the PIC is being reset during the middle of the call. Has anyone seen this before, and if so, is there some kind of work around I should know about. Generally I hate begging for help, but I've spent two days trying to fix this, and any help, even if its just to say that its just the way the world is and it can't be fixed will be appreciated. ___________________________
This message was ported from CCS's old forum
Original Post ID: 6180
robertm1771
Guest







Re: Please help, code attached.
PostPosted: Thu Aug 08, 2002 12:39 pm     Reply with quote

Well I downloaded version 3.105 of PCW and recompiled my code and it worked for me like a charm. I had version 3.098

I would try the upgraded software. (To bad the editor now places debugger marks for breaks and such next to your lines everytime I type a "y" or such)


:=:=Obvious thing, without even looking at the code. What is the WDT being set to?. You are not adding a #fuses statement, so are presumably setting this manually at the programmer....
:=:=If this is timing out, the processor will reset. You can diagnose/verify what is going on, by replacing your 'start' printout with:
:=:=fprintf(HOSTPC,"Reason:- \%3d",restart_cause());
:=:=If you get a value of 8, then the watchdog has timed out.
:=:=
:=:=Best Wishes
:=
:=First, let me thank you all for taking the time to read and post thoughts on my problem.
:=
:=I am disabling the WDT and the Power up timer via the programmer. I'm using a PICSTART Plus and developing in the MPLAB IDE. I stuck with the MPLAB IDE since I used to code in Pic BASIC Pro and it didn't have it's own IDE. I switched to CCS PICC due to the fact that it supported 32 bit math/variables without any need for writing/calling assembly routines.
:=
:=In any case, I replace the printing of start with the restart_cause(). The return value was 24, which I looked up in the device header to be NORMAL_POWER_UP. I've checked the power supply voltages and they are stable, and I have multiple boards w/ PICs on them in the same bus drawing from the same p/s and they run fine. Also, the symptoms go away if I comment out the fprintf(HOSTPC,"[\%f]",5.0).
:=
:=I'm well aware that I may be doing some 'badnesses' in my math that would cause problems, but I would expect that if I were to fubar a pointer things would crash immediately, not in the middle of a built in function call.
:=
:=I'll keep prodding my code and update if I find anything, and also check back here to see if some saintly genius has any pearls of wisdom.
:=
:=Thanks in advance for any help.
___________________________
This message was ported from CCS's old forum
Original Post ID: 6200
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