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 support@ccsinfo.com

Store Table in ROM with dsPIC30F

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



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

Store Table in ROM with dsPIC30F
PostPosted: Sun Apr 22, 2012 9:46 am     Reply with quote

Hello guys
hope all of you are good, sir i have a problem i want to store a static Table in the ROM then i want to call its element during execution,
by using the key word "const" i can achieve my goals in 16F / 18F PICs but in dsPIC30F it shows garbage values, please help me


Code:

#include <30F4012.h>

#FUSES NOWDT, NOPROTECT,NODEBUG, NOBROWNOUT, HS, NOPUT, PR                                       

#use delay(clock=20M, crystal)

unsigned int16 const Table[50] = {500, 600, 700, 100, .... 4000};   // gives garbage Values
//const unsigned int16 Table[] = {500, 600, 700, 100, .... 4000};   // gives garbage Values
//unsigned int16 Table[] = {500, 600, 700, 100, .... 4000};         // Works Perfect but it consumes all the RAM Space

unsigned int16 x;
unsigned int8 i;

void main()
 { 
 
  i=10;

  while(TRUE)
   {

    x = Table[i];

   }
 }
bells_electronics



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

PostPosted: Sun Apr 22, 2012 10:21 am     Reply with quote

it works fine when i use data type "unsigned int8"
Code:

const unsigned int8 Table[] = {50, 60, 70, 100, .... 200};   //50 elements


again it works when i don't use "Const" with "unsigned int16"
Code:

unsigned int16 Table[] = {50, 60, 70, 100, .... 200};   //50 elements


never runs on dsPIC30F
Code:

const unsigned int16 Table[] = {50, 60, 70, 100, .... 200};   //50 elements


but the Problem is that my Table elements are 16bit.

my compiler version is 4.057
bells_electronics



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

PostPosted: Sun Apr 22, 2012 8:44 pm     Reply with quote

any one? please Sir i need the solution Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 23, 2012 8:43 pm     Reply with quote

You didn't give us enough information to work on your problem. Your
test program is incomplete, and it's not compilable. You didn't tell us
exactly how the program fails. You just said "never runs on dsPIC30F "
or "in dsPIC30F it shows garbage values".

Post a short, complete, compilable test program. Example:
Code:

#include <18F4520.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

int16 const Table[4] = {0x0123, 0x4567, 0x89AB, 0xCDEF};

//================================
void main()
{
int8 i;

for(i = 0; i < 4; i++)
    printf("%lx \n\r", Table[i]);

while(1);
}

That program displays the following output (it's correct):
Code:

0123
4567
89ab
cdef


Post your test program, very similar to the one shown above.
Post the output that it displays.
bells_electronics



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

PostPosted: Mon Apr 23, 2012 10:13 pm     Reply with quote

this code displays correct values up to 2165 after that it starts showing garbage values
Code:

#include <30F4012.h>
#FUSES NOWDT, NOPROTECT,NODEBUG, NOBROWNOUT, HS, NOPUT, PR
#use delay(clock=20M, crystal)
#use rs232(baud=9600,parity=N,xmit=PIN_C13,rcv=PIN_C14,bits=8)

const unsigned int16 Table[256] = {
 624, 661, 697, 734, 771, 808, 844, 881, 918, 954, 991,1028,1064,1101,1138,1175,
1211,1248,1285,1321,1358,1395,1431,1468,1505,1542,1578,1615,1652,1688,1725,1762,
1798,1835,1872,1909,1945,1982,2019,2055,2092,2129,2165,2202,2239,2276,2312,2349,
2386,2422,2459,2496,2532,2569,2606,2643,2679,2716,2753,2789,2826,2863,2899,2936,
2973,3010,3046,3083,3120,3156,3193,3230,3266,3303,3340,3377,3413,3450,3487,3523,
3560,3597,3633,3670,3707,3744,3780,3817,3854,3890,3927,3964,4000,4037,4074,4111,
4147,4184,4221,4257,4294,4331,4367,4404,4441,4478,4514,4551,4588,4624,4661,4698,
4734,4771,4808,4845,4881,4918,4955,4991,5028,5065,5101,5138,5175,5212,5248,5285,
5322,5358,5395,5432,5468,5505,5542,5579,5615,5652,5689,5725,5762,5799,5835,5872,
5909,5946,5982,6019,6056,6092,6129,6166,6202,6239,6276,6313,6349,6386,6423,6459,
6496,6533,6569,6606,6643,6680,6716,6753,6790,6826,6863,6900,6936,6973,7010,7047,
7083,7120,7157,7193,7230,7267,7303,7340,7377,7414,7450,7487,7524,7560,7597,7634,
7670,7707,7744,7781,7817,7854,7891,7927,7964,8001,8037,8074,8111,8148,8184,8221,
8258,8294,8331,8368,8404,8441,8478,8515,8551,8588,8625,8661,8698,8735,8771,8808,
8845,8882,8918,8955,8992,9028,9065,9102,9138,9175,9212,9249,9285,9322,9359,9395,
9432,9469,9505,9542,9579,9616,9652,9689,9726,9762,9799,9836,9872,9909,9946,9983};   
unsigned int16 i;

// ======================================

void main()
 { 
  while(1)
   {
    for(i = 0; i < 256; i++)
     {
      printf("%lu \n\r", Table[i]);
      delay_ms(500);
     }
    puts(" ---------- ");
   } 
 }


if i remove the word "const" then it shows the correct values till the end
Code:

#include <30F4012.h>
#FUSES NOWDT, NOPROTECT,NODEBUG, NOBROWNOUT, HS, NOPUT, PR
#use delay(clock=20M, crystal)
#use rs232(baud=9600,parity=N,xmit=PIN_C13,rcv=PIN_C14,bits=8)

unsigned int16 Table[256] = {
 624, 661, 697, 734, 771, 808, 844, 881, 918, 954, 991,1028,1064,1101,1138,1175,
1211,1248,1285,1321,1358,1395,1431,1468,1505,1542,1578,1615,1652,1688,1725,1762,
1798,1835,1872,1909,1945,1982,2019,2055,2092,2129,2165,2202,2239,2276,2312,2349,
2386,2422,2459,2496,2532,2569,2606,2643,2679,2716,2753,2789,2826,2863,2899,2936,
2973,3010,3046,3083,3120,3156,3193,3230,3266,3303,3340,3377,3413,3450,3487,3523,
3560,3597,3633,3670,3707,3744,3780,3817,3854,3890,3927,3964,4000,4037,4074,4111,
4147,4184,4221,4257,4294,4331,4367,4404,4441,4478,4514,4551,4588,4624,4661,4698,
4734,4771,4808,4845,4881,4918,4955,4991,5028,5065,5101,5138,5175,5212,5248,5285,
5322,5358,5395,5432,5468,5505,5542,5579,5615,5652,5689,5725,5762,5799,5835,5872,
5909,5946,5982,6019,6056,6092,6129,6166,6202,6239,6276,6313,6349,6386,6423,6459,
6496,6533,6569,6606,6643,6680,6716,6753,6790,6826,6863,6900,6936,6973,7010,7047,
7083,7120,7157,7193,7230,7267,7303,7340,7377,7414,7450,7487,7524,7560,7597,7634,
7670,7707,7744,7781,7817,7854,7891,7927,7964,8001,8037,8074,8111,8148,8184,8221,
8258,8294,8331,8368,8404,8441,8478,8515,8551,8588,8625,8661,8698,8735,8771,8808,
8845,8882,8918,8955,8992,9028,9065,9102,9138,9175,9212,9249,9285,9322,9359,9395,
9432,9469,9505,9542,9579,9616,9652,9689,9726,9762,9799,9836,9872,9909,9946,9983};   
unsigned int16 i;

// ======================================

void main()
 { 
  while(1)
   {
    for(i = 0; i < 256; i++)
     {
      printf("%lu \n\r", Table[i]);
      delay_ms(500);
     }
    puts(" ---------- ");
   } 
 }
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Tue Apr 24, 2012 8:58 am     Reply with quote

Compiler problem.
Seriously, 4.057, was before V4 really started to work properly, It was about 4.070, before 90% of things worked right, and we are now up in the 4.124 area _over sixty releases latter_.....

Tried exactly your code on a current compiler, and it runs fine with const.

Best Wishes
bells_electronics



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

PostPosted: Tue Apr 24, 2012 11:27 am     Reply with quote

My compiler version is 4.057.

I see I need to upgrade my CCS C Complier.
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