Electronic – Allocating more memory Space in controller

cc18picram

Chip: PIC18f26j50
Compiler: C18

My objective is to store values in a table in the RAM memory using structures and feed in the values which are quite large.

#include <p18F46J53.h>

 struct table
    { 
      float temp;
      float humidity;
      float pressure;

    }entry[300];

This is my sample code and I have to store such members into the controller's memory. This is for the purpose of monitoring the surrounding data of the atmosphere. And later dump this data into EEPROM.

But I am having trouble building the code as it give the following error:

Error – section '.udata_main.o' can not fit the section. Section
'.udata_main.o' length=0x000013ec

I tried searching Google for fixing this udata error and ended up with
How to Create Objects Larger than 256 Bytes with Microchip's MPLAB C18.

But this shows how to store each variable. How can I store structs in C18? Or is it impossible?

I'll try to be more specific. I found this method to store data greater than 255 bytes.

#pragma udata large_udata
unsigned char big_buff1[300];
unsigned char big_buff2[350];
#pragma udata

How can I store structures greater than that so that I would just need 3000 bytes at the for the table preparation?

I would prefer to use float but I can settle for using int/char.

I hope this makes things clearer.

Best Answer

EDIT: There are two issues - the structure array is too large for the memory, and the compiler cannot create variables larger than 256 bytes

Problem 1: Structure too large for RAM

The chip you are using has a RAM size of 3776 bytes (1) and the error says it requires 5100 bytes.

You either need a new chip with more RAM, or you must reduce the size of your table. I suggest storing you values as unsigned integers (2 bytes). If you need the decimal places, simply multiply by 10 to the power of the number of places. E.g. 3.157 becomes 3157.

Why do you need 300 values? Perhaps you can store to EEPROM more often and reduce this number. If you are just having a large number to do averaging, consider adding to an accumulator variable instead.

E.g.

TempAccum += temp;

Then after 300 readings

TempTotal = TempAccum / 300;
TempAccum = 0;

Problem 2: No variables larger than 256 bytes:

A solution was posted in the link in the question but that was for variables. Instead of a structure, use individual variables:

float temp[300];
float humidity[300];
float pressure[300];

To access the variables (according to the link) you need to use pointers. e.g.

float *tempPtr;
tempPtr = temp;
tempPtr[100] = some_value;