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

Unspected reset

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








Unspected reset
PostPosted: Mon Oct 27, 2003 1:07 pm     Reply with quote

Hi,
I've been programming PICs using assembler for a few years now, and I decided to move to C, as assembler is not a fast development tool.

I'm migrating a program which allows the user to configure a PBX using a phone.

I don't include the code here because its written in spanish, and most of you won't understand it (tell me if I'm wrong, and I'll post it).

Basically, my code is comprised by a lot of infinite loops, every one representing a "state".

The main selects the state according to the events. Below are some excerpts of the code that I translated to english:

Code:

void main() {

   #bit tris_RELE = 0x85.0       // relay tris (PORTA<0>)
   #bit tris_HOOK = 0x86.5       // hook tris (PORTB<5>)
   #bit tris_RING = 0x86.6       // ring tris (PORTB<6>)

   #byte adcon1 = 0x9F           // A/D control

   int state = IDLE;

   // initializations
   enable_interrupts(GLOBAL);    // in order for the timer to work
   initialize_I2C();
   initialize_PWM();
   initialize_timer();
   initialize_DTMF();
   initialize_clock();
   tris_RELE = 0;                // relay pin as an output
   tris_HOOK = 1;                // hook pin as an input
   tris_RING = 1;                // ring pin as an input
   adcon1 = 0x18;                // port A pins as digital I/O

   #IFDEF DEBUG_MAIN
   printf("\n\rQOK");
   #ENDIF
   while(1) {
      if(state == IDLE) state = eIDLE(); //idle state
      if(state == INTT) state = eINTT(); //internal tone
      if(state == BUST) state = eBUST(); //bussy tone
      if(state == LOGN) state = eLOGN();  //login
      if(state == COMU) state = eCOMR();  //commands reception
   }
}


int eIDLE()   {   // IDLE state

   #ifdef DEBUG_STATE
      printf("\n\rIDLE");
   #endif

   //state initializations
   //
   //
   relay_coil = 0;   // disconnect the user from the config line
   stop_PWM();     // mute the internal tone

   while(1) {

      // if the phone goes off-hook, jump to INTT (internal tone)
      if(!on_hook) return INTT;

      // if the phone is ringing, jump to RING (ringing routine)
      if(!no_ring) return RING;
   }
}


int eINTT()   {   // INTT state (Internal Tone)

   #ifdef DEBUG_STATE
      printf("\n\rINTT");
   #endif

   //state initializations
   //
   //
   start_timer(1500);   //set the timer to 15 seconds
   start_PWM(190);  //start the internal tone

   while(1) {

      //if the user hungs up, jump back to idle
      if(off_hook) return IDLE;

      //if the user presses a key, save it as user number
      if(DTMFhit()) {
         user = read_DTMF();         //user is a global variable
         return LOGN;
      }

      // if the timer expires, jump to bust
      if(timer_out()) return BUST;
   }
}


int eLOGN() {   // LOGN state (LOGiN)

   int key[4], numkeys = 0;
   int PIN[4];

   #ifdef DEBUG_STATE
      printf("\n\rLOGN");
   #endif

   //inicializaciones de este estado
   //
   //
   start_timer(1000);
   stop_PWM();

   while(1) {

      //on_hook ? go back to idle
      if(off_hook) return IDLE;

      //timeout ? bussy tone
      if(timer_out()) return BUST;

      //receive the PIN
      if(DTMFhit()) {
         key[numkeys] = read_DTMF();
         numkeys ++;
         if(numkeys == 4) {
         read_EEPROM((user<<4) + 12, PIN, 4);
         if(key[0] == PIN[0] && key[1] == PIN[1] && key[2] == PIN[2] && key[3] == PIN[3]) {
            start_PWM(100); // a little beep
            delay_ms(200);
            stop_PWM();
            return ECOR;
         } else return BUST;
      }
   }
}
}



Well, that should give an idea of what I'm doing (and it only tookme half an hour to translate...)

The thing is ti hungs (and resets) randomly during the login state. Some times I'm able to login without a problem, and some other times it hungs and resets.

I'm using only the rtcc interrupt, and its enabled only between the start_timer() function and the timeout.

Can anyone giveme a hint on this ? This is my first ccs program, and I don't have a clue on what's wrong.

BTW, the watchdog is disabled.

Thanks in advance
kamyip



Joined: 14 Oct 2003
Posts: 10

View user's profile Send private message

PostPosted: Mon Oct 27, 2003 1:57 pm     Reply with quote

I think you should enable global interrupt only after you initialise all the hardware peripherals. This should be before you go into main().
kamyip



Joined: 14 Oct 2003
Posts: 10

View user's profile Send private message

PostPosted: Mon Oct 27, 2003 2:11 pm     Reply with quote

kamyip wrote:
I think you should enable global interrupt only after you initialise all the hardware peripherals. This should be before you go into main().


Thousands apologies, "main()" should have been "while(1) {}" superloop. Embarassed
Guest








PostPosted: Tue Oct 28, 2003 7:06 am     Reply with quote

Is there any bug list for the compiler I can check ?
Guest








unexpected reset
PostPosted: Tue Oct 28, 2003 7:00 pm     Reply with quote

One possibility: there are hardware condition(s) to cause unexpected resets. If you happen to have very long wires (>10ft) from switch inputs to processor I/O pins, this can cause a reset. If this is applicable, I can offer more info.
sbayeta



Joined: 27 Oct 2003
Posts: 6

View user's profile Send private message

Re: unexpected reset
PostPosted: Wed Oct 29, 2003 4:48 am     Reply with quote

Anonymous wrote:
One possibility: there are hardware condition(s) to cause unexpected resets. If you happen to have very long wires (>10ft) from switch inputs to processor I/O pins, this can cause a reset. If this is applicable, I can offer more info.


Hi,
Thanks for that answer, but it can be that. The thing is i have a version of the program written in assembler and it runs fine. It's not a hardware problem, nor a configuration problem.
The C porgram is really simple, so I don't think the problem is there. That's why I think it must be the compiler.

BTW, I'm the original poster (I registered now)

Thanks
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