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

Tired of RAM problems (several PICs)

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








Tired of RAM problems (several PICs)
PostPosted: Fri Oct 28, 2005 12:10 am     Reply with quote

Hello,

I'm using PCWH Compiler (PCB/PCM 3.222 and PCH 3.219), and I'm working with several types of PICs. I'll only expose the RAM problems I have with PIC16F917, because I've the same problem with my other PICS (PIC18F8490, for example):

have a configuration.h where I define all the global variables I use. It depends where I define that variables that it works fine or not. For example:



#define tiempo_antirebotes 2
#define skew_reloj 3030

#define bot_ctrl_out pin_b3
#define bot_clk_out pin_c5
#define bot_data_out pin_d2

#define secuencia_pitido_subir 1
#define secuencia_pitido_bajar 10
#define secuencia_pitido_planta 20

#define UNCICLO delay_us(200);
#define MEDIOCICLO delay_us(100);
#define CUARTOCICLO delay_us(50);

#define tiempo_colocacion 100
#define tiempo_led_can 6
#define tiempo_funcion 7

#define ack 0b10101010
#define num_retx 16
#define tiempo_retx 6
#define num_max_retx_can 64

#define apagar_todos 90
#define boton_pulsado_cabina 91

#define boton_2 2
#define boton_1 1
#define boton_3 4
#define boton_4 8
#define pitido_botonera 128

enum {mensaje_fotocelula1,mensaje_fotocelula2,mensaje_fotocelula3,mensaje_peso_ochenta,mensaje_peso_cien,
mensaje_pulso_subir,mensaje_pulso_bajar,mensaje_pextra1,mensaje_pextra2,mensaje_abrir_puertas1,mensaje_pedir_tiempo_reapertura,estado_inicial,
mensaje_reloj_techo,mensaje_peticion_cierra_puertas,luz_cabina,mensaje_boton_abre_puertas,
mensaje_techo_exceso_carga,mensaje_sonido_llegada,mensaje_zumbador,
inversion_y_detecta_placas_CPR,parpadeo_todos_menos_1_planta,parpadeo_1_planta,apagar_todos_menos_1_planta,encender_todos_menos_1_planta,
encender_1_planta,apagar_1_planta};//,apagar_todos,boton_pulsado_cabina}; /* Mensajes al techo */

int buffer_state=0;

//VARS reloj
int segundo,minuto,hora,dia,mes,anio;
int veces_arrancado;

int cuenta_reloj;

boolean apagar=false;
boolean exceso_carga=false;

boolean encendido_pitido=false;
int temporizador_pitido;
int secuencia_pitido;
int contador_cierra_puertas;
int16 tiempo_bloqueo_reapertura_puertas;
int temporizador_led_pesacargas;



int1 boton_pulsado;



int timer_foto1,timer_foto2,timer_foto3,timer_ochenta,timer_cien,timer_ps,timer_pb,timer_pextra,timer_pextra2,timer_cierra_puertas,timer_abre_puertas;

boolean estado_anterior_foto1=0,estado_anterior_foto2=0,estado_anterior_foto3=0,estado_anterior_ochenta=0,estado_anterior_cien=0,estado_anterior_ps=0,estado_anterior_pb=0,estado_anterior_pextra=0,estado_anterior_pextra2=0,estado_anterior_cierra_puertas=0,estado_anterior_abre_puertas=0;

//BOTONERAS
//CONTROL_PLACAS

int numero_de_plantas;



int1 aux_bit_control;
int timer_led_can,timer_zumbador,timer_simulacion_boton;


int numero_de_placas_detectadas,numero_de_placas_detectadas_anterior;
int senti_acude;
int planta_senti_acude;
int aux_led_salida;

int1 ctrl,clk;



int funcion_botonera=0;
int temporizador_funcion=tiempo_funcion;
int estado_secuencia;


int1 enviar_mensaje_techo=0;

int1 modo_funcionamiento;
int1 activada_funcion=0;




//VARIABLES CANBUS
int timer_led;
int donde_insertar;

int num_rtx_bajo_nivel;

int1 mensaje_es_respuesta;
int1 recibida_inicializacion_cpu;
int1 seleccionado_buffer_tx;


#define MAX_PLACAS 13
#define TAM_BUFFER 8

//CONTROL_PLACAS
int mensaje[8];
int buffer_txcan[TAM_BUFFER][10];
int estado_pulsadores[MAX_PLACAS];
int salida_datos[MAX_PLACAS];



if I compile like this, I get 76% ROM and 52% RAM, but the "salida_datos[]" array is crushed during the execution of the program.

but if I change the conf.h like that:


#define tiempo_antirebotes 2
#define skew_reloj 3030

#define bot_ctrl_out pin_b3
#define bot_clk_out pin_c5
#define bot_data_out pin_d2

#define secuencia_pitido_subir 1
#define secuencia_pitido_bajar 10
#define secuencia_pitido_planta 20

#define UNCICLO delay_us(200);
#define MEDIOCICLO delay_us(100);
#define CUARTOCICLO delay_us(50);

#define tiempo_colocacion 100
#define tiempo_led_can 6
#define tiempo_funcion 7

#define ack 0b10101010
#define num_retx 16
#define tiempo_retx 6
#define num_max_retx_can 64

#define apagar_todos 90
#define boton_pulsado_cabina 91

#define boton_2 2
#define boton_1 1
#define boton_3 4
#define boton_4 8
#define pitido_botonera 128

enum {mensaje_fotocelula1,mensaje_fotocelula2,mensaje_fotocelula3,mensaje_peso_ochenta,mensaje_peso_cien,
mensaje_pulso_subir,mensaje_pulso_bajar,mensaje_pextra1,mensaje_pextra2,mensaje_abrir_puertas1,mensaje_pedir_tiempo_reapertura,estado_inicial,
mensaje_reloj_techo,mensaje_peticion_cierra_puertas,luz_cabina,mensaje_boton_abre_puertas,
mensaje_techo_exceso_carga,mensaje_sonido_llegada,mensaje_zumbador,
inversion_y_detecta_placas_CPR,parpadeo_todos_menos_1_planta,parpadeo_1_planta,apagar_todos_menos_1_planta,encender_todos_menos_1_planta,
encender_1_planta,apagar_1_planta};//,apagar_todos,boton_pulsado_cabina}; /* Mensajes al techo */

int buffer_state=0;

//VARS reloj
int segundo,minuto,hora,dia,mes,anio;
int veces_arrancado;

int cuenta_reloj;

boolean apagar=false;
boolean exceso_carga=false;

boolean encendido_pitido=false;
int temporizador_pitido;
int secuencia_pitido;
int contador_cierra_puertas;
int16 tiempo_bloqueo_reapertura_puertas;
int temporizador_led_pesacargas;



int1 boton_pulsado;



int timer_foto1,timer_foto2,timer_foto3,timer_ochenta,timer_cien,timer_ps,timer_pb,timer_pextra,timer_pextra2,timer_cierra_puertas,timer_abre_puertas;

boolean estado_anterior_foto1=0,estado_anterior_foto2=0,estado_anterior_foto3=0,estado_anterior_ochenta=0,estado_anterior_cien=0,estado_anterior_ps=0,estado_anterior_pb=0,estado_anterior_pextra=0,estado_anterior_pextra2=0,estado_anterior_cierra_puertas=0,estado_anterior_abre_puertas=0;

//BOTONERAS
//CONTROL_PLACAS

int numero_de_plantas;



int1 aux_bit_control;
int timer_led_can,timer_zumbador,timer_simulacion_boton;


int numero_de_placas_detectadas,numero_de_placas_detectadas_anterior;
int senti_acude;
int planta_senti_acude;
int aux_led_salida;

int1 ctrl,clk;



int funcion_botonera=0;
int temporizador_funcion=tiempo_funcion;
int estado_secuencia;


int1 enviar_mensaje_techo=0;

int1 modo_funcionamiento;
int1 activada_funcion=0;


#define MAX_PLACAS 13
int estado_pulsadores[MAX_PLACAS];
int salida_datos[MAX_PLACAS];


//VARIABLES CANBUS
int timer_led;
int donde_insertar;

int num_rtx_bajo_nivel;

int1 mensaje_es_respuesta;
int1 recibida_inicializacion_cpu;
int1 seleccionado_buffer_tx;


#define TAM_BUFFER 8


//CONTROL_PLACAS
int mensaje[8];
int buffer_txcan[TAM_BUFFER][10];




Then I get 77%ROM and 52% RAM, and it works fine.

My question is: Is there any rule to define arrays? Because here I can solve the problem, but I have much more problems with the PIC18F8490, because I've a lot of arrays and a lot of text strings allocated in RAM that take strange values if I don't define them at a correct position in the conf.h file, and I don't know how to define them...

please HELP!!!
picoto



Joined: 28 Oct 2005
Posts: 5

View user's profile Send private message

PostPosted: Fri Oct 28, 2005 12:18 am     Reply with quote

By the way, at the first case, I cant set MAX_PLACAS to 42 before get the "not enough RAM" message,

at the second case, I can define only 26

Please I'm desperated with this problem, it's driving my crazy Sad
picoto



Joined: 28 Oct 2005
Posts: 5

View user's profile Send private message

PostPosted: Fri Oct 28, 2005 12:20 am     Reply with quote

Another data i've forgotten, i'm programming with ICD-U40 V.202
Ttelmah
Guest







PostPosted: Fri Oct 28, 2005 3:03 am     Reply with quote

The definitions should work fine on the 18 chips. For the 'getting trashed' part, I'd say look more carefully at your code. The problem has all the signs of perhaps estado_pulsadores, overrunning the area defined for it. You have remembered that C arrays are zero referenced (so if 'MAX_PLACAS' is 10, the highest element you can access is 9).
For the 'not enough RAM' message, on the 16 chips, have you got *=16?.

Best Wishes
picoto



Joined: 28 Oct 2005
Posts: 5

View user's profile Send private message

PostPosted: Fri Oct 28, 2005 3:12 am     Reply with quote

Thank you very much for your answer

I'm pretty sure I don't write outside the array, but I'll take a second look.

Yes, I've the *=16, the problem is that I get the "not enough RAM" depending the position I define the arrays

Weird problem Rolling Eyes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 28, 2005 9:55 am     Reply with quote

You have a large number of global variables. That may be the reason
why the compiler is having difficulty partitioning the RAM.
Normally, you should use local variables instead of so many globals.
Then the compiler can re-use some of the RAM when the locals are
no longer needed.

Look at my post at the end in this thread. It explains how to use
the #locate directive to help the compiler allocate RAM when you
are getting "out of RAM" errors.
http://www.ccsinfo.com/forum/viewtopic.php?t=20605
picoto



Joined: 28 Oct 2005
Posts: 5

View user's profile Send private message

PostPosted: Wed Nov 02, 2005 12:23 am     Reply with quote

Thank you very much, I'll try to remove as global variables I can, and then try to allocate the arrays manually Smile

I'll tell you the result...
picoto



Joined: 28 Oct 2005
Posts: 5

View user's profile Send private message

PostPosted: Wed Nov 02, 2005 5:39 am     Reply with quote

It seems that works better, I've no problems with the arrays now Smile

Thank you very much!!! Very Happy
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