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

not enough RAM for all variables??

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



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

not enough RAM for all variables??
PostPosted: Mon Aug 01, 2005 5:49 am     Reply with quote

Does anyone know what the limit is on the amount of variables you can define? I listed my variables below (which I didn't think was a lot) which have prompted the "not enough RAM for all variables" error. I'd like to know just how many variables I have to eliminate? I know the "data" array is taking up a lot, but I'm using it to receive 9 BYTES of data over RS232. Also, maybe there is a better way of doing this?

Oh yeah, I am using a PIC16F84

Code:

int i;
int rud_pwm, elev_pwm, ail_pwm;
int data[9];
int ref;
double r, p, y;
double Kp, error;
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 01, 2005 6:42 am     Reply with quote

From the CCS manual:
Quote:
double Is a reserved word but is not a supported data type.
Tricky, I've no clue as to what the compiler will do with this. Fix this first.
Let's assume a double has the same size as a float, then you are allocating a total of 34 bytes. The PIC16F84A has 68 bytes of RAM so this shouldn't be a problem.

In many PIC16 parts the 'out of RAM' problem is caused by the RAM being spread over multiple banks, for the compiler to effectively address these banks you have to add the '#device *=16' directive to tell the compiler to use 16 bit addressing. Your processor has all RAM in a single bank so I don't think this is the cause of your error. You might try to add '#device *=8' at the top of your program, it won't hurt.
Mark



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

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

PostPosted: Mon Aug 01, 2005 6:44 am     Reply with quote

I can't believe that you are out of RAM with just those. The 16F84 has 128 bytes. double is not a valid datatype for CCS. Maybe that is causing the problem. Try changing the data type. What range do those values need to be? Refer to the CCS manual or help file to see the valid types and their ranges.
weg22



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

PostPosted: Mon Aug 01, 2005 6:54 am     Reply with quote

Yeah, I thought it had 64 bytes of memory. I tried your suggestions (i.e. changing double to float and the #device), but still no luck. One thing I didn't mention is that I am using interrupts - I am not sure how this effects the memory? Also, I am declaring 4 of those variables globally. I included the entire first part of my code to get a better idea of what I am doing...

Thanks in advance,
weg

Code:

#include <16F84.H>
#include <stdlib.h>
#include <math.h>

#define A0 PIN_A0
#define A1 PIN_A1
#define B0 PIN_B0
#define B1 PIN_B1

/*-----------------------------------------------------*/
/* No Watch Dog Timer (NOWDT)
/* No Protect
/* Power Up Timer (PUT)
/* 10 MHz Clock
/* RS232 define for PIC-IMU communication (IMU)
/* RS232 define for PIC-PC communication (PC)
/*-----------------------------------------------------*/
#fuses HS,NOWDT,NOPROTECT, PUT
#use delay(clock=10000000)
#use rs232(baud=38400, xmit=A1, rcv=A0)

int i;
int rud_pwm, elev_pwm, ail_pwm;

//Timer interrupt to generate PWM signals
#INT_TIMER0
void pwm_signal()
{
   //One of the parameters used to cause the interrupt to occur every 22.5 msec
   set_timer0(37); // 61 for 20 msec

   /*--------RUDDER 0 (right), 255 (left) --------*/
   output_high(B0); // generates initial high time ie 1 msec
   delay_us(1000);
   i=0;
   for(i=0;i<rud_pwm;i++) // generates remaining high time, varied by variable "pwm"
   {
      //use this to tune duty cycle
      delay_us(1);
   }
   output_low(B0);

   /*--------ELEVATOR 0 (up), 255 (down) --------*/
   output_high(B1); // generates initial high time ie 1 msec
   delay_us(1000);
   i=0;
   for(i=0;i<elev_pwm;i++) // generates remaining high time, varied by variable "pwm"
   {
      //use this to tune duty cycle
      delay_us(1);
   }
   output_low(B1);
}

main()
{
   int data[9];
   int ref;
   float r, p, y;
   float Kp, error;

   // enable timer interrupts
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);

   //the other parameter used to cause interrupt to occur every 20 msec
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);

   while(1)
   {
                             // main code is here
                 }
weg22



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

PostPosted: Mon Aug 01, 2005 7:07 am     Reply with quote

In addition to the last post, I found something else I thought was strange and thought this might help you help me :-) Executing the following:

r=1/2;
p=1/4;
y=1/3;

and compiling it, everything works nicely. However, if I do something a little more complicated:

r = 2*asin((data[3]*256 + data[4])/8192)*180/3.14; // roll angle
p = 2*asin((data[5]*256 + data[6])/8192)*180/3.14; // pitch angle
y = 2*asin((data[7]*256 + data[8])/8192)*180/3.14; // yaw angle

I get the "not enough RAM" error?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 01, 2005 7:56 am     Reply with quote

In general: Calculations with float variables require a lot of ROM and RAM, in processors with limited memory you should try to avoid using float at all.

I compiled your program and added some simple calculations using float additions, this resulted in a 64 to 81 bytes RAM usage. Adding a call to sin() increased the RAM usage to 134 bytes.

There is no way you will be able to optimize your current code so it will fit in a PIC16F84. Either use a chip with triple the amount of RAM, or change your code so it doesn't use floats.
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