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

Timer4 interrupt makes the 18F6621 reset

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



Joined: 01 Mar 2004
Posts: 22
Location: Nice, France

View user's profile Send private message

Timer4 interrupt makes the 18F6621 reset
PostPosted: Tue May 04, 2004 9:04 am     Reply with quote

I want to use the timer4 for the first time on a 18F6621 and surprisingly, the µc resets when I enable it ! Here is the interrupt routine :

#int_TIMER4
void Timer4_interrupt_processing()
{

if (temps_inter_salve==0)
{
if (premiere_interruption)
{
disable_interrupts(INT_TIMER0); /* on desactive timer0 pour ne pas perturber la vitesse de la LF */
if (configuration.mode_f!=lf) disable_interrupts(INT_EXT1); /* debut emission lf on desactive l'interupt ext */
if (bit_test (trame_lf[indice_tableau],(15-indice_bit))) commande_lf=0;
else commande_lf=1;

cpt_salve_lf++;

if (cpt_salve_lf<50)
{
indice_tableau=(int)(cpt_salve_lf/16);
indice_bit=cpt_salve_lf%16;
}
else
{
indice_tableau=(int)((cpt_salve_lf+14)/16);
indice_bit=(cpt_salve_lf+14)%16;
}
premiere_interruption=FALSE;
}
else
{
FLF=commande_lf;
if (bit_test (trame_lf[indice_tableau],(15-indice_bit))) commande_lf=0;
else commande_lf=1;

cpt_salve_lf++;

if (cpt_salve_lf<50)
{
indice_tableau=(int)(cpt_salve_lf/16);
indice_bit=cpt_salve_lf%16;
}
else
{
indice_tableau=(int)((cpt_salve_lf+14)/16);
indice_bit=(cpt_salve_lf+14)%16;
}



if (cpt_salve_lf>=148)
{
FLF=0; /* fin trame */
if (configuration.mode_f!=lf) enable_interrupts(INT_EXT1); /* fin de trame lf on reactive l'interrupt externe */
numero_salve_lf++;
if (numero_salve_lf>=NOMBRE_SALVES_LF)
{
disable_interrupts(INT_TIMER4);
clear_interrupt(INT_TIMER0);
enable_interrupts(INT_TIMER0);
}
temps_inter_salve=DUREE_INTER_SALVE; /* (16*2)+(18)+(8*2*4)= 114 */
premiere_interruption=TRUE;
}
}
}
else
{
temps_inter_salve--; /* periode intersalve */
cpt_salve_lf=0;
indice_bit=0;
}
}


Any idea ?

CCS 3.189
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue May 04, 2004 9:21 am     Reply with quote

When posting code use the code format button. Other wise the leading spaces are removed. This makes it more dificult to read.
Code display: [ code]code[/code ] (alt+c)
Schmobol



Joined: 01 Mar 2004
Posts: 22
Location: Nice, France

View user's profile Send private message

timer4 interrupt
PostPosted: Tue May 04, 2004 9:36 am     Reply with quote

You're right, sorry !

Code:

#int_TIMER4
void Timer4_interrupt_processing()

   //SET_TIMER3(64302);   // 128.2µs c.a.d un demi Tbit à 3900 bauds
   if (temps_inter_salve==0)
      {
         if (premiere_interruption)
            {
               disable_interrupts(INT_TIMER0);  // on desactive timer0 pour ne pas perturber la vitesse de la LF
               if (configuration.mode_f!=lf) disable_interrupts(INT_EXT1); // debut emission lf on desactive l'interupt ext
               if (bit_test (trame_lf[indice_tableau],(15-indice_bit))) commande_lf=0;
               else commande_lf=1;

               cpt_salve_lf++;

               if (cpt_salve_lf<50)
                  {
                     indice_tableau=(int)(cpt_salve_lf/16);
                     indice_bit=cpt_salve_lf%16;
                  }
               else
                  {
                     indice_tableau=(int)((cpt_salve_lf+14)/16);
                     indice_bit=(cpt_salve_lf+14)%16;
                  }
               premiere_interruption=FALSE;
            }
         else
            {
               FLF=commande_lf;
               if (bit_test (trame_lf[indice_tableau],(15-indice_bit))) commande_lf=0;
               else commande_lf=1;

               cpt_salve_lf++;

               if (cpt_salve_lf<50)
                  {
                     indice_tableau=(int)(cpt_salve_lf/16);
                     indice_bit=cpt_salve_lf%16;
                  }
               else
                  {
                     indice_tableau=(int)((cpt_salve_lf+14)/16);
                     indice_bit=(cpt_salve_lf+14)%16;
                  }



               if (cpt_salve_lf>=148)
                  {
                     FLF=0;  // fin trame 
                     if (configuration.mode_f!=lf) enable_interrupts(INT_EXT1);  // fin de trame lf on reactive l'interrupt externe
                     numero_salve_lf++;
                     if (numero_salve_lf>=NOMBRE_SALVES_LF)
                        {
                           disable_interrupts(INT_TIMER4);
                           clear_interrupt(INT_TIMER0);
                           enable_interrupts(INT_TIMER0);
                        }
                     temps_inter_salve=DUREE_INTER_SALVE;  // (16*2)+(18)+(8*2*4)= 114
                     premiere_interruption=TRUE;
                  }
            }
      }
   else
      {
         temps_inter_salve--;
         cpt_salve_lf=0;
         indice_bit=0;
      }

}
Schmobol



Joined: 01 Mar 2004
Posts: 22
Location: Nice, France

View user's profile Send private message

Timer4 interrupt makes the 18F6621 reset
PostPosted: Wed May 05, 2004 8:55 am     Reply with quote

After a couple of tests the problem isn't linked with the interrupt routine. The reset occurs whenever I activate the timer4 interruption even if there's no code in the inerrupt routine. Weird ? It might not be related to the compiler !

Any idea are welcomed !

PIC18F6621

CCS 3.189
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed May 05, 2004 9:06 am     Reply with quote

Since the problem is not the ISR, post the rest of your code.
prwatCCS



Joined: 10 Dec 2003
Posts: 70
Location: West Sussex, UK

View user's profile Send private message

PostPosted: Wed May 05, 2004 9:46 am     Reply with quote

I would check the .lst file to be sure that the isr is correctly resetting the irq flag. Otherwise you may be continually stuck in an isr and be suffering from a watchdog timeout.

Dont forget it always helps to post your setup code and config data. You may need to comment out the line #nolist in the file 18F6621.h to see the irq code generated by the compiler.

regards
_________________
Peter Willis
Development Director
Howard Eaton Lighting Ltd UK
Schmobol



Joined: 01 Mar 2004
Posts: 22
Location: Nice, France

View user's profile Send private message

Timer4 interrupt makes the 18F6621 reset
PostPosted: Thu May 06, 2004 8:52 am     Reply with quote

It does clear the timer4 interrupt flag before exiting interrupt routine. It does a (MOVLB 0, how could it hurt ?) and returns to the dispatcher for restoring the context.

BCF PIR3.3
MOVLB 0
GOTO 007C

Otherwise, Haplo, regarding the rest of the code, I have more than 4500 lines in this program. What should I post ?
Code:

 setup_psp(PSP_DISABLED);
   setup_spi(FALSE);

   setup_timer_0(RTCC_DIV_4);      /*  timer 0 16-bit PS de 4 uc = 0.8 µs */
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);     /*  timer 1 16-bit PS de 1 uc = 0.1 µs */
   setup_timer_2(T2_DIV_BY_16,79,1);           /*  timer 2 activé interruption ttes les 123.2µs */
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);     /*  timer 3 16-bit PS de 1 uc = 0.2 µs */
   setup_timer_4(T4_DIV_BY_4,250,5);

   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   setup_wdt(WDT_ON);

   //setup_comparator(NC_NC_NC_NC);
   SETUP_ADC(ADC_CLOCK_INTERNAL);
   /* init_display() */

/* initialisation des interruption  */

   enable_interrupts(INT_TIMER0);
   disable_interrupts(INT_EXT1);
   disable_interrupts(INT_TIMER1);
   disable_interrupts(INT_TIMER2);
   disable_interrupts(INT_TIMER3);
   enable_interrupts(INT_TIMER4);
   enable_interrupts(GLOBAL);
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu May 06, 2004 9:12 am     Reply with quote

Well this is a difficult one. It can be a timing issue. How often does your Timer4 interrupt?

As you might know interrupts have a very high latency in PIC18s (both the PIC and the CCS code). If the Timer4 interrupt is happening too often it might be corrupting some data somewhere else, especially if you have any software UART/I2C/....(for example if your timer interrupts every 100us, all the software UART data with baud rates faster than 4800bps would get corrupted). It might cause a corrupt byte to be sent/received, and put your code in a state that you never expected it to enter in normal situations, resulting in a watchdog reset.
prwatCCS



Joined: 10 Dec 2003
Posts: 70
Location: West Sussex, UK

View user's profile Send private message

PostPosted: Thu May 06, 2004 9:24 am     Reply with quote

A few questions :

What happens if you disable the WDT ?

What happens if you service the WDT from within your dummy tmr4 iq handler ?

What happens in the tmr0 irq handler - are you simply spending too much time in the two irq handlers ?

What priority have you given to the irqs ?

A line like
#priority timer2,rda2,timer1,timer0,tbe

sets the order in which they get despatched ...

regards
_________________
Peter Willis
Development Director
Howard Eaton Lighting Ltd UK
Schmobol



Joined: 01 Mar 2004
Posts: 22
Location: Nice, France

View user's profile Send private message

Timer4 interrupt makes the 18F6621 reset
PostPosted: Thu May 06, 2004 9:33 am     Reply with quote

YEs I'm aware of the huge latency when FAST interrupt isn't used. In this very same program I use fast interrupt on INT_EXT1 to decode a bunch of different telegrams carried by RF 433 MHz with a automatic recognition of 7 different possible emission source. Some of these telegrams are coded in manchester 9600 baud witch means that I have to catch (with lower tolerance) times no greater than 36 µs while doing a lot of things in the background. In other words I 'm very tight with the throughput.

But the thing is that this interrupt isn't even activated when I need the timer4 interrupt. At this point of time, only TIMER 0 is activated !

Moreover, I haven't found anything in the 18F6621 errata sheet.

I managed to tweak my program to spare a timer and avoid using timer 4, but still, this remains a mystery...

Any other idea are welcomed
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