Constants In Program Memory Issues

Although PIC24 has 3 bytes per instruction, you can only store data in 2 of them. Therefore program memory usage is 3x actaul data size.

C30 uses 16 bits for pointers. By default it expects all constants to be in 32K of program memory address space. This is a limitation but its done because its a 16 bit device. Actually the compiler should provide an option to just deal with storing and accessing constants in > 32K, but it doesn’t so get over it. The help section you want is ‘Managed PSV Access ‘. This is a good respource:

Working example of usage:

__psv__ const BYTE __attribute__((space(psv))) table1[] = {1, 3, 5, 7, 9};
__psv__ const BYTE *p_character_data;

p_character_data = &data_table[0];
p_character_data += 200;
b_temp = *p_character_data++;
b_temp = *p_character_data++;

Will read the values correctly. You can also pass pointers as long as all are declared as __psv___ (even though when viewing the value of the pointer in a watch windows it will be shown as 16 bit – it is actually 32bit)

Doing this you can use > 32K of constants, but remember each constant must be < 32K. Also bear in mind that there is an irq limitation - see help if your using constants in an IRQ.

Simple Pointers Declaration Solution

Change the CONSTANT define to this:

#define  CONSTANT       __psv__ const

You still need to deal with the other issues, but at least all the pointers are now being declared right.

Pointers To Functions

Again, is you need to deal with the 16 bit issue

Use this of the function definition:

      CONSTANT BYTE get_font_values_arial_14 (WORD character) __attribute__((space(prog)));

or this for the function itself

      CONSTANT BYTE __attribute__((space(prog))) get_font_values_arial_14 (WORD character)
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.