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

I can not use Ram area

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



Joined: 29 Jul 2011
Posts: 12

View user's profile Send private message

I can not use Ram area
PostPosted: Thu Sep 19, 2013 12:47 am     Reply with quote

I'm using ccs v4.114 compiler. I used dspic33fj32mc204. I realised that when my variables inreases ( 21 pieces int16 and 182 pieces int8 2 pieces float and some local variables) exceeds 256 byte my code does not work well. When compiling code at output message was Memory usage: ROM=40% RAM=17%-20%. I'm using now grater Ram sized dspic33fj64mc804. But still I can use same size 256 bytes. In this instance output message was Memory usage: ROM=21% RAM=2%-3%. I used #BUILD(STACK=0x3000:0x4000) for stack area. In this instance output message was Memory usage: ROM=21% RAM=26%-27%. Also I'm using #device *=16 but still I can not use more variable. What do you think about it? How can I use more variables?
_________________
trainee
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Sep 19, 2013 1:52 am     Reply with quote

1) You don't need so much stack.
The stack is used by temporary variables, not by general variables. Just specify a size, increasing it a little may well be necessary if you have large maths functions with other functions called inside, but better to let the compiler locate it. Goes on to '2'...
2) Are you using ICD?. Thing is that when debug is enabled, some RAM locations at the top of memory are reserved for the ICD. By forcing the stack to be located here, you could be creating problems. If you just specify the stack as a 'size', the compiler will automatically move it down to clear the reserved locations. So:
#BUILD (STACK=512)

is all that is needed.
3) *=16, has no meaning on any chip latter than a PIC16. Forget it. It is not even present, in the PCD manual. You are using an instruction from PCM/PCH. Hopefully the compiler will ignore it.
4) Now, the compiler you are using, is relatively early for these chips. There were some definite 'oddities' on the earlier compilers, but I must admit I was using compilers around this time with these chips, and no problems with KB RAM arrays. Are you using structures, or simple variables?. There were (and still are in some cases), 'issues' with some types of data structure. By the low 4.1xx compilers, 99% of stuff was working fairly well.

Now, I just compiled a ten line program, with the smaller of these chips, on your compiler version, setting up a 32*int16 array, and a 512*int8 array. Wrote random numbers to each location in the 512 byte array, and the accesses were correct. Then combined pairs of the bytes into the int16 array, and still OK. 54% RAM used.

Best Wishes
mehmetem



Joined: 29 Jul 2011
Posts: 12

View user's profile Send private message

PostPosted: Thu Sep 19, 2013 4:16 am     Reply with quote

Thank you for your kind attention and assistance.
1- I did not use large math functions. So I do not need so much stack.
2- I'm not using ICD.
Code:
 #include "D:\projects\tezgahKod\revX\AnaKart_2_804\33FJ64MC804.h"
 
 #device ADC=10;
 #device *=16                   //16 bit pointer
  #list
  #FUSES NOWDT                    //No Watch Dog Timer
 #FUSES NOWRTB                   //Boot block not write protected
 #FUSES NOBSS                    //No boot segment
 #FUSES PROTECT                 //Standard Code protection
 //#FUSES NOWRT                    //Program memory not write protected
 //#FUSES PR                       //Primary Oscillator
 #FUSES PR_PLL                   //Primary Oscillator with PLL
 #FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)

 
 #FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
 #FUSES NOOSCIO                  //OSC2 is general purpose output
 //#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
 #FUSES WINDIS                   //Watch Dog Timer in non-Window mode
 #FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
 #FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
 #FUSES WPOSTS6                 //Watch Dog Timer PostScalar 1:32768
 #FUSES PUT128                   //Power On Reset Timer value 128ms
// #FUSES NOALTI2C                 //I2C mapped to alternate pins
 #FUSES ALTI2C                 //I2C mapped to alternate pins
 #FUSES IESO                     //Internal External Switch Over mode enabled
 #FUSES NOIOL1WAY                  //Allows only one reconfiguration of peripheral pins
 #FUSES NODEBUG                  //No Debug mode for ICD
 //#FUSES NOCOE                    //Device will reset into operational mode
 #FUSES NOJTAG                   //JTAG disabled
 //#FUSES ICS1                     //ICD communication channel 1
 #FUSES NOPWMPIN                 //PWM outputs drive active state upon Reset
 #FUSES HPOL_HIGH                //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
    //PWM module high side output pins have active high output polarity
 #FUSES LPOL_HIGH                //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6)
    //PWM module low side output pins have active high output polar
   #use delay(clock=80179200)

I used #BUILD (STACK=512) Memory usage: ROM=21% RAM=5%-5%.
all of my variables:

Code:
  unsigned int16 MaxOnTime=100; //100 T2 tick 1mSn
  const unsigned int16 MaxDPTime=14; //70uSn Max Deep Impact time

  unsigned int16 yer;
  int8 *yerPtr=&(yer);
 

   
  unsigned int16 Timer2OvCounter=0;
  unsigned int16 Timer2Limit=1500;      //1000rpm

  unsigned int16 Rpm=0;
  volatile unsigned int16 DesRpm=1000;
  unsigned int16 ReadPressure=0;
 unsigned int16 ReadPressure2=0;
  unsigned int16 DesPressure=0;
  unsigned int16 PWM1Duty=0;
  unsigned int16 ReadTemp=0,Temperature=0;
  float VoltValTemp=0,time3totalVal=0.0,first=0.1,second=3;
  unsigned int8 DesTemp=40,TempContAuto=0,PumpOn=0;
  unsigned int16 PulseTime=0;
  unsigned int16 MeasureTime=3;//
  unsigned int16 TestTimer=0; 
   
  unsigned int8 TestMode=0;
  unsigned int8 SelectedEnjectors=0;
  unsigned int8 EnjPRSweeper=0;


  unsigned int8 nextTestStep=0; //
  volatile unsigned int8 EnjNr=1;
  volatile unsigned int8 onTestEnjNr=0;
 
  volatile unsigned int8 Tubes=3;   //1Enjection / 2Return  3 all

 volatile unsigned int8 EnjNrActive[4]={1,1,1,1};


 
 unsigned int16 MeasuredVolume=0;
  unsigned int16 ReadVolume=0;
 
  int8 *MeasuredVolumePtr=&(MeasuredVolume);
  unsigned int8 MeasuredVolumeL=0;
  unsigned int8 MeasuredVolumeH=0;

  unsigned int16 PumpVolume=0;
  unsigned int16 LastT3Val=0;
    unsigned int16 TotalT3Time=0;
    unsigned int16 TotalT3Time1=0;
   
    unsigned int8 T3Lap=0;

const int8 TxBufLength=90;
  char RDataTrain[6], TDataTrain[TxBufLength];
 
  unsigned int8 TxBufFirstIndis=0,TxBufLastIndis=0;//
  unsigned int8 RCommand[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  unsigned int8 RDatas[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},NewCommand=0;
 unsigned int8 ReceiveBufferIndis=0;
 unsigned int8 Bank00=0,Bank01=0,Bank10=0,Bank11=0;
 
 const int8 Heater=0x0A;            //
 const int8 Cooler=0x0B;            //cooler
 const int8 Fan   =0x0C;            //Fan
 
 const int8 Group1=1;               // selenoids
 const int8 Group2=2;               // relays and triacs
 
 const int8 EnjectorSweepId=0x52;
 const int8 Enj1R=0x1A,Enj1P=0x11;
 const int8 Enj2R=0x1B,Enj2P=0x12;
 const int8 Enj3R=0x1C,Enj3P=0x13;
 const int8 Enj4R=0x1D,Enj4P=0x14;
 
  const int8 FlowmeterReset=0x07;
 
 unsigned int8 QueryType=0;         //
 
 unsigned int8 AdcChNo=0;
   unsigned int8 t1AdcCheckTime=0;
   
    unsigned int8 SendTestResultsEn=0;
   unsigned int8 injectorTypeCode=1;
   unsigned int8 ClimCounter=0;
   unsigned int8 CLimRef=0;

3- I did not try *=16 effect.
4-I have only this compiler for now. I will be glad when I have a new compiler.
If it is necessary I can send all of my code. It is ridiculous I can use only a small area of RAM.
when my code works normally with
Code:
  float VoltValTemp=0,time3totalVal=0.0;

, when I append
Code:
  float VoltValTemp=0,time3totalVal=0.0,first=0.1,second=3;

My analogue readings and pwm outputs halted.
I can not understand how occurs this problem with only a couple variable appending.
_________________
trainee
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Sep 19, 2013 5:03 am     Reply with quote

I'd just declare yerPtr, as:

int8 *yerPtr;

and initialise it explicitly in the code. Same applies to your other pointers later.

Initialisation 'in declaration', is a thing that often didn't work. Could explain many problems.

I'd reorder the declarations. Do all the int16 declarations first. Then the int8 ones, and make sure that all int8 declarations are in multiples of 2. The DsPIC's require int16 values to start on a word boundary, and the compiler was not 100% capable of ensuring this happened at this point.

Why so many const declarations?. While good for something like a lookup table, for general values, why not use an enum, or a #define?. Latter uses no storage at all, while the const involves wasting ROM...

Get rid of PROTECT when developing. This just results in extra erase cycles being needed on the chip, using up lives. Only enable PROTECT, when the code is working...

Are you _sure_ about ICD?. If you are using MPLAB as a development environment (for example), this defaults to enabling ICD....

I'd suggest you step back. Throw away 90% of your code, and just try doing your data declarations. I'd suggest you have something else, like a "#define second = ????", causing the problem when you add this to the variable declarations.

Have compiled your data declarations, with your compiler version, and a basic chip setup for the MC204, still including another 576 bytes of other variables, and an up to 66% RAM usage.
mehmetem



Joined: 29 Jul 2011
Posts: 12

View user's profile Send private message

PostPosted: Thu Sep 19, 2013 7:13 am     Reply with quote

Ttelmah wrote:
I'd just declare yerPtr, as:

int8 *yerPtr;

and initialise it explicitly in the code. Same applies to your other pointers later.
Initialisation 'in declaration', is a thing that often didn't work. Could explain many problems.

I applied this. But did not help.
Ttelmah wrote:

I'd reorder the declarations. Do all the int16 declarations first. Then the int8 ones, and make sure that all int8 declarations are in multiples of 2. The DsPIC's require int16 values to start on a word boundary, and the compiler was not 100% capable of ensuring this happened at this point.

I applied this. This was my first problem. if there is any single int8 my ADC's stops.
Ttelmah wrote:

Why so many const declarations?. While good for something like a lookup table, for general values, why not use an enum, or a #define?. Latter uses no storage at all, while the const involves wasting ROM...

I applied this. You're right. When I converting variables to constants I have this mistake.
Ttelmah wrote:


Get rid of PROTECT when developing. This just results in extra erase cycles being needed on the chip, using up lives. Only enable PROTECT, when the code is working...

I applied this. Thank you
Ttelmah wrote:

Are you _sure_ about ICD?. If you are using MPLAB as a development environment (for example), this defaults to enabling ICD....

I'm not sure. But I am not using MPLAB as a development environment.
Ttelmah wrote:

I'd suggest you step back. Throw away 90% of your code, and just try doing your data declarations. I'd suggest you have something else, like a "#define second = ????", causing the problem when you add this to the variable declarations.

I applied this. Thank you
Ttelmah wrote:


Have compiled your data declarations, with your compiler version, and a basic chip setup for the MC204, still including another 576 bytes of other variables, and an up to 66% RAM usage.


My new variable list:
Code:

  #ZERO_RAM
#BUILD (STACK=512)
 
 
  unsigned int16 MaxOnTime=100; //100 T2 tick 1mSn
  unsigned int16 yer;
   
  unsigned int16 Timer2OvCounter=0;
  unsigned int16 Timer2Limit=1500;      //1000rpm

  unsigned int16 Rpm=0;
  volatile unsigned int16 DesRpm=1000;
  unsigned int16 ReadPressure=0;
  unsigned int16 ReadPressure2=0;
  unsigned int16 DesPressure=0;
  unsigned int16 PWM1Duty=0;
  unsigned int16 ReadTemp=0,Temperature=0;
  unsigned int16 PulseTime=0;
  unsigned int16 MeasureTime=3;//3
  unsigned int16 TestTimer=0;
  unsigned int16 MeasuredVolume=0;
  unsigned int16 ReadVolume=0;
 
  unsigned int16 PumpVolume=0;
  unsigned int16 LastT3Val=0;
  unsigned int16 TotalT3Time=0;
  unsigned int16 TotalT3Time1=0;

  float VoltValTemp=0,time3totalVal=0.0,first=0.1,second=3;

  volatile int8 *yerPtr;
  volatile int8 *MeasuredVolumePtr;

  volatile unsigned int8 EnjNrActive[4]={1,1,1,1};
  unsigned int8 RCommand[30]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  unsigned int8 RDatas[30]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

  char RDataTrain[6];
  #define TxBufLength 90
  char TDataTrain[TxBufLength];
 
  unsigned int8 NewCommand=0;
  unsigned int8 DesTemp=40;
 
  unsigned int8 TempContAuto=0;
  unsigned int8 PumpOn=0;

  unsigned int8 TestMode=0;
  unsigned int8 SelectedEnjectors=0;
 
  unsigned int8 EnjPRSweeper=0;
  unsigned int8 nextTestStep=0; //
 
  volatile unsigned int8 EnjNr=1;
  volatile unsigned int8 onTestEnjNr=0;
 
  volatile unsigned int8 Tubes=3;   //1Enjection / 2Return  3 all
  unsigned int8 T3Lap=0;

  unsigned int8 MeasuredVolumeL=0;
  unsigned int8 MeasuredVolumeH=0;
 
  unsigned int8 TxBufFirstIndis=0,TxBufLastIndis=0;//l
 
  unsigned int8 Bank00=0,Bank01=0,Bank10=0,Bank11=0;
 
  unsigned int8 QueryType=0;         //
  unsigned int8 ReceiveBufferIndis=0;
 
  unsigned int8 AdcChNo=0;
  unsigned int8 t1AdcCheckTime=0;
   
  unsigned int8 SendTestResultsEn=0;
  unsigned int8 injectorTypeCode=1;
 
  unsigned int8 ClimCounter=0;
  unsigned int8 CLimRef=0;
 

 #define MaxDPTime  14              //70uSn Max Deep Impact time
 #define Heater     0x0A            //

 #define Cooler     0x0B             //
 #define Fan        0x0C             //Fan
 
 #define Group1     1                // selenoid
 #define Group2     2                // relay triac
 
 #define EnjectorSweepId    0x52
 
 #define Enj1R      0x1A
 #define Enj1P      0x11
 #define Enj2R      0x1B
 #define Enj2P      0x12
 #define Enj3R      0x1C
 #define Enj3P      0x13
 #define Enj4R      0x1D
 #define Enj4P      0x14
 
 #define FlowmeterReset     0x07

My compiler for 804 Memory usage: ROM=21% RAM=5%-5%
Thank you very much.
_________________
trainee
mehmetem



Joined: 29 Jul 2011
Posts: 12

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 2:03 am     Reply with quote

I have a problem; with
Code:
float VoltValTemp=0, time3totalVal=0.0, first=0.1;

running code with

Code:
 float VoltValTemp=0;
  float time3totalVal=0.0;
  float first=0.1;
does not works. This is very absurd. Same code when compiled some times runs some times does not run.
I think I forget something important.[/code]
_________________
trainee
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 3:03 am     Reply with quote

It almost certainly means there is a syntax error somewhere miles earlier.

The compiler has a habit (getting slightly less in the newer versions), when certain types of syntax error occur, of 'ploughing on', then giving a completely different error dozens (even hundreds) of lines later, at the point where one of it's internal expansion tables 'overflows', because of the earlier error.

This is why you will see a lot of the 'old hands', recommending using other syntax testing tools like LINT, to check the basic code.

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 7:54 am     Reply with quote

I don't hear a clear description of ovserved problems.

"My analogue readings and pwm outputs halted" is the clearest, but still vague because the issue apparently
wasn't traced anyhow. Why pwm stops? Registers altered, chip rebooted, particular variables changed unintended?

I know that you might sometimes experience infrequent random errors that are hard to trace. But in your case,
there seems to be obvious issues. Debugging is the method to trace them down to the primary cause.
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