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

i have freezing prolem

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







i have freezing prolem
PostPosted: Sun Jul 09, 2006 12:51 pm     Reply with quote

i have some design which is added below and code but i have a problem that in high EM field the pic 16f877a can freeze. But ı think i must tell that some of same design was working for a year but some of them are freezing


#if defined(__PCM__)
#include <16F877A>
#fuses HS,WDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=4000000 , restart_wdt)
#endif

#include<lcdnewe>

#define parametersAd 8
#define multiplier 16

//pin definition
#define MOTOR PIN_C0
#define FAN PIN_C2
#define CIRCULATION PIN_C3
#define DIRECTION PIN_C4
//pin definition

//time variable
int workTime;
int32 seconds;
int times;
short mode; // surme yada bekleme olması 0 bekleme 1 surme
int timeVariableAdd[2] = {1,2}; // [0] bekleme [1] surme
//time variable

//menu variable
char menuItem[25];
int selection = 0;
int tempVariableAdd[3] = {5,6,7};//0 sirkulasyon,1 durma,2 calışma
char menuIndex[3];
//menu variable

//temp variable
int temp = 0;
int value = 0;
int16 tempSum = 0;
short situation; //0 ust deger altı 1 ust deger ustu
//temp variable

short begining;
short reverse;
int parameters;//situation changed 0,




void readTemp()
{
restart_wdt();

value = read_adc();
if (tempSum == 0)
tempSum = value;
else
{
if (!(value <tempSum> (tempSum / times + 5)))
tempSum += value;
else
tempSum += (int)(tempSum/(times-1));
}


restart_wdt();

return;
}

void menu(int slc)
{
restart_wdt();

switch(slc)
{
case 0:
strcpy(menuItem ,"KAZAN SICAKLIK");
strcpy(menuIndex ,"C");
break;
case 1:
strcpy(menuItem ,"BEKLEME SURESI");
strcpy(menuIndex ,"dk");
break;
case 2:
strcpy(menuItem ,"CALISMA SURESI");
strcpy(menuIndex ,"sn");
break;
/* case 3:
strcpy(menuItem ,"BEKLEME SURESI 2");
strcpy(menuIndex ,"dk");
break;
case 4:
strcpy(menuItem ,"CALISMA SURESI 2");
strcpy(menuIndex ,"sn");
break;*/
case 3:
strcpy(menuItem ,"SIRKULASYON POMPA");
strcpy(menuIndex ,"C");
break;
case 4:
strcpy(menuItem ,"DURMA SICAKLIGI");
strcpy(menuIndex ,"C");
break;
case 5:
strcpy(menuItem ,"CALISMA SICAKLIGI");
strcpy(menuIndex ,"C");
break;
case 6:
strcpy(menuItem ,"GERI CEVIRME");
strcpy(menuIndex ," ");
break;
}

restart_wdt();
}

void controlSituation(int temperature)
{
parameters = read_eeprom(parametersAd);

restart_wdt();

if( (situation || begining) && read_eeprom(tempVariableAdd[2]) >= temperature)
{
if(!mode)
{
situation = 0;
output_high(FAN);
bit_set(parameters,0);
restart_wdt();
write_eeprom(parametersAd,parameters);
restart_wdt();
mode = 0;
begining = 0;
seconds = 0;
}
}

if(!situation && (read_eeprom(tempVariableAdd[1]) <temperature>= read_eeprom(tempVariableAdd[0]) && !input(CIRCULATION))
output_high(CIRCULATION);
if (temperature <read_eeprom>= 15)
{
bit_clear(parameters,0);

restart_wdt();

write_eeprom(parametersAd,parameters);

restart_wdt();


if(read_eeprom(timeVariableAdd[1]))
{
restart_wdt();
seconds = 0;
restart_wdt();
driveMotor(read_eeprom(timeVariableAdd[1]));
restart_wdt();
return;
}
}
}
else
{
if((read_eeprom(timeVariableAdd[mode]) || read_eeprom(timeVariableAdd[!mode])) && !situation)
{
restart_wdt();

//restart_wdt();

if(mode)
{

restart_wdt();

if (seconds >= workTime)
{
restart_wdt();
output_low(MOTOR);
seconds = 0;
mode=!mode;

restart_wdt();

}
}
else
{
if (seconds >= (int32)(60*(int32)(read_eeprom(timeVariableAdd[mode]))))
{
restart_wdt();

driveMotor(read_eeprom(timeVariableAdd[!mode]));
restart_wdt();
}
}
}
}
}
}

return;
}



#INT_RB
void menuItems()
{
int gecici;
int gecici2;
int tempselection;
int valueb;
valueb = input_b();
delay_ms(40);
if (valueb == input_b())
{
valueb = valueb - (valueb%16);

restart_wdt();


switch (valueb)
{
case 0xE0:
if (selection < 3 && selection)
{
tempselection = selection - 1;
gecici = read_eeprom(timeVariableAdd[tempselection]);
restart_wdt();
if (gecici <255>= 3)
{
restart_wdt();
if (selection == 6)
{
reverse = 1;
output_low(MOTOR);
restart_wdt();
output_high(DIRECTION);
restart_wdt();
delay_ms(1000);
restart_wdt();
output_high(MOTOR);
restart_wdt();
}
else
{
tempselection = selection - 3;
gecici = read_eeprom(tempVariableAdd[tempselection]);

restart_wdt();
if (selection == 5)
{
gecici2 = read_eeprom(tempVariableAdd[tempselection - 1]);
if (gecici2 > gecici+1)
{
++gecici;
write_eeprom(tempVariableAdd[tempselection],gecici);

restart_wdt();
}
}
else
{
if (gecici < 255)
{
++gecici;
write_eeprom(tempVariableAdd[tempselection],gecici);

restart_wdt();
}
}

lcd_gotoxy(3,2);
printf(lcd_putc," %u ",gecici);
}
}
lcd_gotoxy(9,2);
printf(lcd_putc,menuIndex);
break;


case 0xB0:

if (selection <3> 0)
{
--gecici;
write_eeprom(timeVariableAdd[tempselection],gecici);

restart_wdt();
}

lcd_gotoxy(3,2);
printf(lcd_putc," %u ",gecici);
}
if (selection >= 3)
{
if (selection == 6)
{
reverse = 1;
restart_wdt();
output_low(MOTOR);
restart_wdt();
output_high(DIRECTION);
restart_wdt();
delay_ms(1000);
restart_wdt();
output_high(MOTOR);
restart_wdt();
}
else
{
tempselection = selection - 3;
gecici = read_eeprom(tempVariableAdd[tempselection]);
if (selection == 4)
{
gecici2 = read_eeprom(tempVariableAdd[tempselection + 1]);
if (gecici2 <gecici> 0)
{
--gecici;
restart_wdt();
write_eeprom(tempVariableAdd[tempselection],gecici);
restart_wdt();
}
}
else
{
if (gecici > 0)
{
--gecici;
restart_wdt();
write_eeprom(tempVariableAdd[tempselection],gecici);
restart_wdt();
}
}

lcd_gotoxy(3,2);
printf(lcd_putc," %u ",gecici);
}
}
lcd_gotoxy(9,2);
printf(lcd_putc,menuIndex);
break;


case 0xD0:

if (selection == 6)
selection = 0;
else
++selection;

menu(selection);
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,menuItem);

restart_wdt();

if (!selection)
{
lcd_gotoxy(3,2);
printf(lcd_putc," %u ",temp);
}
if (selection <3>= 3)
{
tempselection = selection - 3;
restart_wdt();
gecici = read_eeprom(tempVariableAdd[tempselection]);
restart_wdt();
lcd_gotoxy(3,2);
printf(lcd_putc," %u ",gecici);
}

lcd_gotoxy(9,2);
printf(lcd_putc,menuIndex);
if(selection == 6)
{
lcd_gotoxy(1,2);
lcd_putc(" ");
}
break;


case 0x00:
restart_wdt();
if (selection == 0)
selection = 6;
else
--selection;

menu(selection);
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,menuItem);

restart_wdt();

if (!selection)
{
lcd_gotoxy(3,2);
printf(lcd_putc," %u ",temp);
}

restart_wdt();

if (selection <3>= 3)
{
tempselection = selection - 3;
gecici = read_eeprom(tempVariableAdd[tempselection]);
lcd_gotoxy(3,2);
printf(lcd_putc," %u ",gecici);
}

restart_wdt();

lcd_gotoxy(9,2);
printf(lcd_putc,menuIndex);

if(selection == 6)
{
lcd_gotoxy(1,2);
lcd_putc(" ");
}

break;
}
}

restart_wdt();
return;

}


void main()
{
set_tris_b(0xFF);

restart_wdt();

lcd_init();
set_timer0(0);

restart_wdt();

setup_timer_0 (RTCC_DIV_256 );

restart_wdt();


enable_interrupts(INT_TIMER0);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);

restart_wdt();

setup_adc_ports( AN0_AN1_VREF_VREF);
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );

restart_wdt();

mode = 0;
times = 0;
seconds = 0;
begining = 1;
reverse = 0;

restart_wdt();

menu(selection);
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,menuItem);

restart_wdt();

delay_ms(50);
readTemp();
lcd_gotoxy(3,2);
printf(lcd_putc," %u ",value);
lcd_gotoxy(9,2);

restart_wdt();

printf(lcd_putc,menuIndex);

delay_ms(2000);

controlSituation(value);

while(TRUE)
{
restart_wdt();
}
}
Ttelmah
Guest







PostPosted: Sun Jul 09, 2006 2:35 pm     Reply with quote

First comment. Use the 'code' button to post code. Otherwise it is almost unreadable.
The code is too long to look through as a casual search, but one big comment leaps out. Get rid of most of your restart_wdt statements...
You want to make the act of restarting the watchdog, _depend_ on the code running correctly. As it stands, the code can get stuck almost anywhere, and will still keep resetting the watchdog, and will then never recover, making having the watchdog 'pointless'.
Then assuming you are running on 5v, enable the brownout restart as well.

Best Wishes
deneme
Guest







still have problem
PostPosted: Tue Jul 25, 2006 11:21 am     Reply with quote

I applied the suggestions Ttelmah but it still freezing but I want to remind that I have some of this design and same program running about a year
I send the code again
Code:
#if defined(__PCM__)
#include <16F877>
#fuses HS,WDT,NOPROTECT,NOLVP,BROWNOUT
#use delay(clock=4096000 , restart_wdt)
#endif

#include<lcdnewe>

#define parametersAd 8
#define multiplier 16

//pin definition
#define MOTOR PIN_C0
#define FAN PIN_C2
#define CIRCULATION PIN_C3
#define DIRECTION PIN_C4
//pin definition

//time variable
int workTime;
int32 seconds;
int times;
short mode; // surme yada bekleme olması 0 bekleme 1 surme
int timeVariableAdd[2] = {1,2}; // [0] bekleme [1] surme
//time variable

//menu variable
char menuItem[25];
int selection = 0;
int tempVariableAdd[3] = {5,6,7};//0 sirkulasyon,1 durma,2 calışma
char menuIndex[3];
//menu variable

//temp variable
int temp = 0;
int value = 0;
int16 tempSum = 0;
short situation; //0 ust deger altı 1 ust deger ustu
//temp variable

short begining;
short reverse;
int parameters;//situation changed 0,




void readTemp()
{


      value = read_adc();
      if (tempSum == 0)
         tempSum = value;
      else
      {
         if (!(value <tempSum> (tempSum / times + 5)))
            tempSum += value;
         else
            tempSum += (int)(tempSum/(times-1));
      }




      return;
}

void menu(int slc)
{


   switch(slc)
   {
      case 0:
         strcpy(menuItem ,"KAZAN SICAKLIK");
         strcpy(menuIndex ,"C");
         break;
      case 1:
         strcpy(menuItem ,"BEKLEME SURESI");
         strcpy(menuIndex ,"dk");
         break;
      case 2:
         strcpy(menuItem ,"CALISMA SURESI");
         strcpy(menuIndex ,"sn");
         break;
    /*  case 3:
         strcpy(menuItem ,"BEKLEME SURESI 2");
         strcpy(menuIndex ,"dk");
         break;
      case 4:
         strcpy(menuItem ,"CALISMA SURESI 2");
         strcpy(menuIndex ,"sn");
         break;*/
      case 3:
         strcpy(menuItem ,"SIRKULASYON POMPA");
         strcpy(menuIndex ,"C");
         break;
      case 4:
         strcpy(menuItem ,"DURMA SICAKLIGI");
         strcpy(menuIndex ,"C");
         break;
      case 5:
         strcpy(menuItem ,"CALISMA SICAKLIGI");
         strcpy(menuIndex ,"C");
         break;
      case 6:
         strcpy(menuItem ,"GERI CEVIRME");
         strcpy(menuIndex ," ");
         break;
   }


}

void controlSituation(int temperature)
{

   parameters = read_eeprom(parametersAd);



   if( (situation || begining) && read_eeprom(tempVariableAdd[2]) >= temperature)
   {
      if(!mode)
      {
         situation = 0;
         output_high(FAN);
         bit_set(parameters,0);

         write_eeprom(parametersAd,parameters);

         mode = 0;
         begining = 0;
         seconds = 0;
      }
   }

   if(!situation && (read_eeprom(tempVariableAdd[1]) <temperature>= read_eeprom(tempVariableAdd[0]) && !input(CIRCULATION))
      output_high(CIRCULATION);
   if (temperature <read_eeprom>= 15)
            {
               bit_clear(parameters,0);



               write_eeprom(parametersAd,parameters);




               if(read_eeprom(timeVariableAdd[1]))
               {

                  seconds = 0;

                  driveMotor(read_eeprom(timeVariableAdd[1]));

                  return;
               }
            }
         }
         else
         {
            if((read_eeprom(timeVariableAdd[mode]) || read_eeprom(timeVariableAdd[!mode])) && !situation)
            {


                //

                if(mode)
                {



                  if (seconds >= workTime)
                  {

                     output_low(MOTOR);
                     seconds = 0;
                     mode=!mode;



                   }
                }
                else
                {
                   if (seconds >= (int32)(60*(int32)(read_eeprom(timeVariableAdd[mode]))))
                   {


                      driveMotor(read_eeprom(timeVariableAdd[!mode]));

                   }
                 }
            }
         }
      }
   }

   return;
}



#INT_RB
void menuItems()
{

   int gecici;
   int gecici2;
   int tempselection;
   int valueb;
   restart_wdt();
   valueb = input_b();
   delay_ms(40);
   if (valueb == input_b())
   {
      valueb = valueb - (valueb%16);




      switch (valueb)
      {
         case 0xE0:
            if (selection < 3 && selection)
            {
               tempselection = selection - 1;
               gecici = read_eeprom(timeVariableAdd[tempselection]);

               if (gecici <255>= 3)
            {

               if (selection == 6)
               {
                  reverse = 1;
                  output_low(MOTOR);

                  output_high(DIRECTION);

                  delay_ms(1000);

                  output_high(MOTOR);

               }
               else
               {
                  tempselection = selection - 3;
                  gecici = read_eeprom(tempVariableAdd[tempselection]);


                  if (selection == 5)
                  {
                     gecici2 = read_eeprom(tempVariableAdd[tempselection - 1]);
                     if (gecici2 > gecici+1)
                     {
                        ++gecici;
                        write_eeprom(tempVariableAdd[tempselection],gecici);


                     }
                  }
                  else
                  {
                     if (gecici < 255)
                     {
                        ++gecici;
                        write_eeprom(tempVariableAdd[tempselection],gecici);


                     }
                  }

                  lcd_gotoxy(3,2);
                  printf(lcd_putc," %u ",gecici);
               }
            }
            lcd_gotoxy(9,2);
            printf(lcd_putc,menuIndex);
            break;


         case 0xB0:

            if (selection <3> 0)
               {
                  --gecici;
                  write_eeprom(timeVariableAdd[tempselection],gecici);


               }

               lcd_gotoxy(3,2);
               printf(lcd_putc," %u ",gecici);
            }
            if (selection >= 3)
            {
                  if (selection == 6)
               {
                  reverse = 1;

                  output_low(MOTOR);

                  output_high(DIRECTION);

                  delay_ms(1000);

                  output_high(MOTOR);

               }
               else
               {
                  tempselection = selection - 3;
                  gecici = read_eeprom(tempVariableAdd[tempselection]);
                  if (selection == 4)
                  {
                     gecici2 = read_eeprom(tempVariableAdd[tempselection + 1]);
                     if (gecici2 <gecici> 0)
                     {
                        --gecici;

                        write_eeprom(tempVariableAdd[tempselection],gecici);

                     }
                  }
                  else
                  {
                     if (gecici > 0)
                     {
                        --gecici;

                        write_eeprom(tempVariableAdd[tempselection],gecici);

                     }
                  }

                  lcd_gotoxy(3,2);
                  printf(lcd_putc," %u ",gecici);
               }
            }
            lcd_gotoxy(9,2);
            printf(lcd_putc,menuIndex);
            break;


         case 0xD0:

            if (selection == 6)
               selection = 0;
            else
               ++selection;

               menu(selection);
               lcd_putc("\f");
               lcd_gotoxy(1,1);
               printf(lcd_putc,menuItem);



            if (!selection)
            {
               lcd_gotoxy(3,2);
               printf(lcd_putc," %u  ",temp);
            }
            if (selection <3>= 3)
            {
               tempselection = selection - 3;

               gecici = read_eeprom(tempVariableAdd[tempselection]);

               lcd_gotoxy(3,2);
               printf(lcd_putc," %u  ",gecici);
            }

            lcd_gotoxy(9,2);
            printf(lcd_putc,menuIndex);
            if(selection == 6)
            {
               lcd_gotoxy(1,2);
               lcd_putc("                        ");
            }
            break;


         case 0x00:

             if (selection == 0)
               selection = 6;
            else
               --selection;

            menu(selection);
            lcd_putc("\f");
            lcd_gotoxy(1,1);
            printf(lcd_putc,menuItem);



            if (!selection)
            {
               lcd_gotoxy(3,2);
               printf(lcd_putc," %u  ",temp);
            }



            if (selection <3>= 3)
            {
               tempselection = selection - 3;
               gecici = read_eeprom(tempVariableAdd[tempselection]);
               lcd_gotoxy(3,2);
               printf(lcd_putc," %u  ",gecici);
            }



            lcd_gotoxy(9,2);
            printf(lcd_putc,menuIndex);

            if(selection == 6)
            {
               lcd_gotoxy(1,2);
               lcd_putc("                        ");
            }

            break;
      }
   }

   restart_wdt();
   return;

}


void main()
{
   set_tris_b(0xFF);



   lcd_init();
   set_timer0(0);



   setup_timer_0 (RTCC_DIV_256 );

   restart_wdt();


   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);



   setup_adc_ports( AN0_AN1_VREF_VREF);
   setup_adc( ADC_CLOCK_INTERNAL );
   set_adc_channel( 0 );



   mode = 0;
   times = 0;
   seconds = 0;
   begining = 1;
   reverse = 0;



   menu(selection);
   lcd_putc("\f");
   lcd_gotoxy(1,1);
   printf(lcd_putc,menuItem);



   delay_ms(50);
   readTemp();
   lcd_gotoxy(3,2);
   printf(lcd_putc," %u  ",value);
   lcd_gotoxy(9,2);

   restart_wdt();

   printf(lcd_putc,menuIndex);

   delay_ms(2000);

   controlSituation(value);
   restart_wdt();
   while(TRUE)
   {
      restart_wdt();
   }
}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 1:52 pm     Reply with quote

I'm not sure if this would cause your lock-ups but this code doesn't look quite right to me, not that I'm the resident expert on proper coding.

Quote:
if(!situation && (read_eeprom(tempVariableAdd[1]) <temperature>=


and

Quote:
if (temperature <read_eeprom>= 15)


Your evaluations don't look like I would think they should. Plus, the second quote would indicate that you have a variable named 'read_eeprom' which is also an internal command, that you are also using, to read the eeprom. But then I stink at reading other peoples messes, let alone my own.

Ronald
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 2:37 pm     Reply with quote

It's because the post was done with HTML enabled. It used to be
disabled by default and recently all posts have it enabled by default,
which causes many posts to have scrambled code. Before you post,
look below the text box in the posting window. You'll see this:
Code:
Disable HTML in this post

Make sure it is selected.

Darren has said he will try to look into this problem later this week.
CCS is currently consumed with the version 4.0 beta rollout.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Jul 27, 2006 7:02 pm     Reply with quote

Quote:
I have freezing problem

Code:
while (1) {
  if (temperature < 0) {
    output_high(HEATER_CONTROL_PORT) ;
  } else {
    output_low(HEATER_CONTROL_PORT);
  }
}

This'll help you, no freezing any more... Guaranteed. (...you might want to add some hysteresis) (sorry :-)
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