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

Baffled with this problem

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



Joined: 10 Oct 2011
Posts: 24

View user's profile Send private message

Baffled with this problem
PostPosted: Thu Dec 08, 2011 10:08 am     Reply with quote

The following code does not set the values to the the data structure zone. MAXZONE is equal to 6. The i (int8) variable is printed to the LCD and works correctly. zone[0].off_t when printed shows uninitialized data. If I use zone[0].off_t in the loop it works. Looks like a CCS bug but I wanted to confirm it. I'm running 4.127.

Code:
   if(time_t.hour==0) { // Load default or use saved?
      lcd_gotoxy(2,2);
      lcd_putc("LOADING DEFAULTS");
      for(i=0; i<MAXZONE; i++) {
         printf(lcd_putc,"%u ",i);
         zone[i].off_t=10;
         zone[i].on_t=5;
         zone[i].pk_off_t=5;
         zone[i].flt_flsh_t=2;
         zone[i].flt_flsh_c=1;
         zone[i].fld_flsh_t=3;
         zone[i].fld_flsh_c=5;
         zone[i].flt_flsh_cyc=0;
         zone[i].fld_flsh_cyc=0;
         zone[i].drain_t=3;
      }   
      //save_param(); // Save zone settings to flash
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Dec 08, 2011 10:33 am     Reply with quote

It sounds as if you are using a debugger of some sort?.
How is zone declared?.
A variable has a value once declared, even if nothing has been written to it. Normally all binary 1's. The message suggests the debugger doesn't understand the code that CCS generates to access an offset variable. If you use a fixed index, a direct access to memory will be performed (which the debugger presumably understands), but using a variable it'll be done using indirect access.
Try printing the variables with printf, rather than the debugger.

Best Wishes
snock



Joined: 10 Oct 2011
Posts: 24

View user's profile Send private message

PostPosted: Thu Dec 08, 2011 12:10 pm     Reply with quote

I should have said so, but I am indeed using printf (to the LCD) to print out the data. I am not using a debugger but rather loading the code with the ICD-U64 to a PIC24FJ64GB106. I don't use the ICD for anything other than program loading at this point. I also have tried using a literal, ie zone[0].off_t, rather than the i variable. It works using the literal but of course I would like to use the for loop to stuff in the default data. The i variable is not used globally either not to mention I tried using different variable names with no success.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Dec 08, 2011 1:29 pm     Reply with quote

OK.
Still the question of how zone is declared, and where?.

Best Wishes
snock



Joined: 10 Oct 2011
Posts: 24

View user's profile Send private message

PostPosted: Thu Dec 08, 2011 1:37 pm     Reply with quote

It's declared before main() so it's global.
Code:

// * ZONE CONTROL STRUCTURE ****************************************************
struct z_type {
   unsigned int32 dose_c;        // Dose counter for zone
   unsigned int32 on_t;          // On time (minutes, def=5 min)
   unsigned int32 off_t;         // Off time (minutes, def=115 min)
   unsigned int32 pk_off_t;      // Peak off time (minutes, def=115 min)
   unsigned int32 drain_t;       // Drain timer to keep zone / field valve open
   unsigned int32 flt_flsh_t;    // Filter flush time (seconds, def=20 sec)
   unsigned int32 flt_flsh_c;    // Filter flush counter (def=1 cycle)
   unsigned int32 flt_flsh_cyc;  // Cycle counter for flush valve
   unsigned int32 fld_flsh_t;    // Field flush time (minutes, def=1 min)
   unsigned int32 fld_flsh_c;    // Field flush counter (def=20 cycles)
   unsigned int32 fld_flsh_cyc;  // Cycle counter for field valve
   unsigned int8 num_zone;
} zone[6];
// *****************************************************************************
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Dec 08, 2011 1:49 pm     Reply with quote

As with every problem of this kind, can you reproduce it in a compact example application? If so, please show it.
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 08, 2011 9:25 pm     Reply with quote

While I think the code as given should work (as in, I don't see anything wrong with it), I'd still do it a little differently:
Code:
if(time_t.hour==0) { // Load default or use saved?
       lcd_gotoxy(2,2);
       lcd_putc("LOADING DEFAULTS");
       zone[0].off_t=10;
       zone[0].on_t=5;
       zone[0].pk_off_t=5;
       zone[0].flt_flsh_t=2;
       zone[0].flt_flsh_c=1;
       zone[0].fld_flsh_t=3;
       zone[0].fld_flsh_c=5;
       zone[0].flt_flsh_cyc=0;
       zone[0].fld_flsh_cyc=0;
       zone[0].drain_t=3;
       for(i=1; i<MAXZONE; i++) {
          printf(lcd_putc,"%u ",i);
          zone[i]=zone[0];
       }   
       //save_param(); // Save zone settings to flash
That should still work, but should be a lot smaller since the compiler isn't calculating lots of zone[i].
_________________
Andrew
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Fri Dec 09, 2011 3:27 am     Reply with quote

I don't know if this is the cause, but there are/have been some issues with structures and arrays of structures that are greater than 256 bytes long.

In your case a single instance of a structure is 45 bytes: 11 int32s @ 4 bytes each plus an int8. These may be aligned to 4 byte boundaries, or possibly 2 byte on a PIC24, so effectively in an array of them they may look like 48/46 bytes each: 45 bytes with 3 or 1 padding bytes. That's more likely on other processors, such as ARMs, and certainly on PCs. Your array is 6 of these, so its either 270 bytes or 288 if its padded. Either way one of the structures crosses a 256 byte boundary. The trouble may be related to indexing finding the offset of a structure correctly, but then individual members are not correctly addressed due to indexing limitations... or something.

I detect a hint of a "coding standard" in your code. One that assumes all variables will be 32 bit unless otherwise stated. Do all these variable really NEED to be 32 bit, or is it just a "standard"? If not, then careful sizing may solve the problem, and will certainly reduce RAM requirements and improve performance if nothing else.

You are also using descriptive suffixes which confused me. I see time_t and automatically assume it means time type, as is the conventional. Reading on, I see it must mean its a variable holding a time, _c meaning holding a count and so on. I am sure you know what it means, its just that it clashes with other more widely used conventions, which makes your code difficult to read. This tends to make me think you are working to some style guide that proscribes this stuff, and maybe the int 32s too....

RF Developer.
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