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

[closed] Big array issue ???
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

[closed] Big array issue ???
PostPosted: Tue Dec 06, 2016 7:44 am     Reply with quote

hello,

I'm working on a project using 18F47J53, and I get Something very Strange :

Here is an example of my code :
Code:
#include <18F47J53.h>
#device ADC=16

#fuses HSPLL,SOSC_HIGH,NOCLOCKOUT,NOFCMEN
#fuses WDT128,PLL1,PLLEN,STVREN,NODEBUG,NOCPUDIV
#use delay(clock=48 MHz,crystal=4 MHz,restart_wdt)

#define LED_G_pin                      pin_B2
#define LED_R_pin                      pin_D4 

#define LED_G(x)                       output_bit(LED_G_pin,x)
#define LED_R(x)                       output_bit(LED_R_pin,x)
   

// int DISPLAY [1024];

int32 TIMER0_Seconde = 0;
#INT_TIMER0
void  TIMER0_isr(void)
{
   set_timer0(18661);         // 1s overflow
   TIMER0_Seconde++;
}

void blink(){
   LED_R(1);
   delay_ms(100);
   LED_R(0);
   delay_ms(100);
}


int sequence_B_state = -1;
int32 sequence_B_Seconde_last = 0;
void sequence_B(void){
   int32 delta = 0;
   
   if(TIMER0_Seconde<sequence_B_Seconde_last)
      sequence_B_Seconde_last = TIMER0_Seconde;
   
   delta = (TIMER0_Seconde-sequence_B_Seconde_last);
   
   if(delta >= 7){
      blink();
      sequence_B_Seconde_last = TIMER0_Seconde;
   }
}

void main() {
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);      //1,4 s overflow
   setup_wdt(WDT_OFF);
   
   
   LED_R(0);
   LED_G(0);
   
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
       
   sequence_B_state = 1;
   
   while(true){
      restart_wdt();
     
      // Sequences
      sequence_B();
         
     
   }
   reset_cpu();
}


with this code, the red led should blink every 7s.

like this it works.

bit if I uncomment:
Code:
int DISPLAY [1024];

the led become crazy

So I guess the issue is from using a big array, but I don't understand what is the problem here ...

someone has an idea ?
someone else experiment this issue ?

I'm using V5.064

thanks for your help


Last edited by spilz on Wed Dec 07, 2016 7:57 am; edited 1 time in total
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 8:25 am     Reply with quote

by the way, this code never works on V5.008
I don't know why ...
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 8:41 am     Reply with quote

it's OK for
Code:
int DISPLAY [222];
or less

if it can help ...
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 9:20 am     Reply with quote

There is a generic problem with what you are trying to do. Maths on a 32bit value that is updated by an interrupt. If an interrupt occurs during the maths, the results will be totally screwed.

You need to either disable interrupts during the maths, or copy the value to a local version, and verify this is right before proceeding.

Why it should change with the array, is probably 'incidental'. I'd suspect the variables are being placed into a later bank, and so become slower to access, and increase the likelyhood of problems.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 9:29 am     Reply with quote

re V5.008 was real early and had a lot of 'bugs' in it....
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 9:30 am     Reply with quote

What do you mean by "maths" ?

I don't understand what you suggest to do to verify with local variable
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 9:47 am     Reply with quote

I have to agree with Temtronic. 5.008, was 'beta' at best.
Unfortunately, it is also one of the 'ripped off' versions of CCS that is commonly on the web. Nasty suspicion that this may be a lot of your problems.

On variables, anything larger than an int8, must always be treated for anything arithmetic (this includes comparisons), as if it may change during the maths.

Code:

    int32 local_copy;

    do {
       local_copy=value_updated_by_interrupt;
    } while (local_copy!=value_updated_by_interrupt);

    //or
    disable_interrupts(GLOBAL);
    local_copy=value_updated_by_interrupt; //or do the maths here
    enable_interrupts(GLOBAL);
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 9:53 am     Reply with quote

Oh i see,
I understand better
I'm going to try it
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 10:03 am     Reply with quote

I tried both, but Nothing works :(
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 10:14 am     Reply with quote

Does that include having changed the compiler?.

I'm very puzzled, since in another thread you talk about using a 5.05x version.
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 10:19 am     Reply with quote

the PC I'm using right now has V5.064 (no more V5.05x)
I tried V5.008 on an other PC from a friend, just to test
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 11:13 am     Reply with quote

Quote:
I tried both, but Nothing works :(

I think you should post your revised program. We don't know for sure
if you implemented Ttelmah's suggestion correctly.
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 12:34 pm     Reply with quote

I tried this :
Code:
#include <18F47J53.h>
#device ADC=16

#fuses HSPLL,SOSC_HIGH,NOCLOCKOUT,NOFCMEN
#fuses WDT128,PLL1,PLLEN,STVREN,NODEBUG,NOCPUDIV
#use delay(clock=48 MHz,crystal=4 MHz,restart_wdt)

#define LED_G_pin                      pin_B2
#define LED_R_pin                      pin_D4 

#define LED_G(x)                       output_bit(LED_G_pin,x)
#define LED_R(x)                       output_bit(LED_R_pin,x)
   

int DISPLAY [1024];

int32 TIMER0_Seconde = 0;
#INT_TIMER0
void  TIMER0_isr(void)
{
   set_timer0(18661);         // 1s overflow
   TIMER0_Seconde++;
}

void blink(){
   LED_R(1);
   delay_ms(100);
   LED_R(0);
   delay_ms(100);
}


int sequence_B_state = -1;
int32 sequence_B_Seconde_last = 0;
void sequence_B(void){
   int32 delta = 0;
   int32 TIMER0_Seconde_loc;
   
   do{
      TIMER0_Seconde_loc = TIMER0_Seconde;
   }while(TIMER0_Seconde_loc != TIMER0_Seconde);
   
   if(TIMER0_Seconde_loc<sequence_B_Seconde_last)
      sequence_B_Seconde_last = TIMER0_Seconde_loc;
   
   delta = (TIMER0_Seconde_loc-sequence_B_Seconde_last);
   
   if(delta >= 7){
      blink();
      sequence_B_Seconde_last = TIMER0_Seconde_loc;
   }
}

void main() {
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);      //1,4 s overflow
   setup_wdt(WDT_OFF);
   
   
   LED_R(0);
   LED_G(0);
   
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
       
   sequence_B_state = 1;
   
   while(true){
      restart_wdt();
     
      sequence_B();
         
     
   }
   reset_cpu();
}

and this :
Code:
#include <18F47J53.h>
#device ADC=16

#fuses HSPLL,SOSC_HIGH,NOCLOCKOUT,NOFCMEN
#fuses WDT128,PLL1,PLLEN,STVREN,NODEBUG,NOCPUDIV
#use delay(clock=48 MHz,crystal=4 MHz,restart_wdt)

#define LED_G_pin                      pin_B2
#define LED_R_pin                      pin_D4 

#define LED_G(x)                       output_bit(LED_G_pin,x)
#define LED_R(x)                       output_bit(LED_R_pin,x)
   

int DISPLAY [1024];


int32 TIMER0_Seconde = 0;
#INT_TIMER0
void  TIMER0_isr(void)
{
   set_timer0(18661);         // 1s overflow
   TIMER0_Seconde++;
}

void blink(){
   LED_R(1);
   delay_ms(100);
   LED_R(0);
   delay_ms(100);
}


int sequence_B_state = -1;
int32 sequence_B_Seconde_last = 0;
void sequence_B(void){
   int32 delta = 0;
   int32 TIMER0_Seconde_loc;
   
   disable_interrupts(GLOBAL);
   TIMER0_Seconde_loc = TIMER0_Seconde;
   enable_interrupts(GLOBAL);
   
   if(TIMER0_Seconde_loc<sequence_B_Seconde_last)
      sequence_B_Seconde_last = TIMER0_Seconde_loc;
   
   delta = (TIMER0_Seconde_loc-sequence_B_Seconde_last);
   
   if(delta >= 7){
      blink();
      sequence_B_Seconde_last = TIMER0_Seconde_loc;
   }
}

void main() {
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);      //1,4 s overflow
   setup_wdt(WDT_OFF);
   
   
   LED_R(0);
   LED_G(0);
   
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
       
   sequence_B_state = 1;
   
   while(true){
      restart_wdt();
     
      sequence_B();
         
     
   }
   reset_cpu();
}


don't forget I have no issue if I comment
Code:
int DISPLAY [1024];
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 3:17 pm     Reply with quote

I'm trying to duplicate your problem in hardware.
Can you tell me what rate or pattern "LED_R_pin" is supposed to blink at ?
Describe it in detail, because I'm getting strange results with the array
commented out.

Also, I have to go out now and won't be back for 3-4 hours. If it isn't
fixed during that time, I'll work on it when I get back.
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 3:33 pm     Reply with quote

It's :
pin -> resistor 100 ohm -> led red -> ground
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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