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 support@ccsinfo.com

CCP1 and CCP2 capture mode and timer

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



Joined: 25 Oct 2012
Posts: 51

View user's profile Send private message

CCP1 and CCP2 capture mode and timer
PostPosted: Tue Feb 03, 2015 1:11 pm     Reply with quote

Hi all

I use ccp1 and ccp2 in capture mode for getting the frequency of 2 signal and then to check the delay between this 2 signal. I use the timer 1.
It work fine.

I need more timer interrupt for parts of my software but as soon as I use "enable_interrupt" with another timer my software became completely buggy.

Code:
//Setup OSC
   setup_oscillator(OSC_4MHZ|OSC_INTRC);
//Setup ADC
      setup_adc_ports(CONFIG_ADC);
    setup_adc(ADC_CLOCK_DIV_8);
   
//Setup Timer 0
   setup_timer_0(RTCC_INTERNAL | RTCC_8_BIT| RTCC_DIV_128);
   enable_interrupts(INT_TIMER0);

//Setup Timer 1 prescaler x1
      set_timer1(0);           
      setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); 

//Setup Timer 3 prescaler x1
      set_timer3(65286);           
      setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); 
   //enable_interrupts(INT_TIMER3);

//Setup CCP
      setup_ccp1(CCP_CAPTURE_RE); // Capture rise edge
      setup_ccp2(CCP_CAPTURE_RE);   // Capture rise edge


As soon as I
Code:
enable_interrupts(INT_TIMER3);
for having interrupts at 250us everything stop working fine.

thanks in advance for your help
Ttelmah



Joined: 11 Mar 2010
Posts: 19380

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 1:27 pm     Reply with quote

You don't show your interrupt handlers?.
If you enable any interrupt without a handler present, it'll crash the code.

Other thing is that you are showing presetting the timer3 to 65286. If you are doing a similar setting in the handler, then this interrupt would be happening every 100 instructions. Given that the interrupt handler alone will use about 60 instructions, it doesn't take much code in the interrupt routine to make the machine grind to a halt.
in_nursery



Joined: 25 Oct 2012
Posts: 51

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 1:35 pm     Reply with quote

Hi Ttelmah

here is my int3 Handler (work fine in other place)

Code:
#INT_TIMER3
void isr_timer3()
{
   set_timer3(65286);
      if (compteurTimer3 == 1)
         compteurTimer3 = 0;
      else {
         compteurTimer3 = 1;

         //if(compteurPeak > 0)
         //   compteurPeak--;
   
         // vérifier si un mot est terminé en déterminant si on a lu le dernier bit
         if(timerMotIR > 0) {
            timerMotIR--;

            // traiter l'interruption seulement si un mot IR est actuellement envoyé
            if (compteurBitIR > 1) { // ">1" car le dernier bit lu n'est pas un vrai bit
     
               // attendre 500us pour vérifier si bit est 1 ou 0
               if(timerBitIR > 0) {
                     timerBitIR--;
               }
                 else { // délais de 500us terminé
               
                     // Déterminer si 1 ou 0
                     // Doit être fait une seule fois par bit
                     if (nouveauBitIR) {
                        motActuelIR <<= 1;
               
                        motActuelIR += input(PIN_IR);
                     
                        nouveauBitIR = FALSE;   // éviter de traiter deux fois le même bit
                 
                        compteurBitIR--;
                     }
               }
            }
         }
         else {
            if (debounceIR == 0) {
            // Si on termine un mot
               if ((compteurBitIR < 13) && (vraiMotIR == 0)){
         
                     // Vérifier si le mot qui vient d'être lu est identique au précédent     
                     if(motActuelIR == motAncienIR) { // oui
                        compteurBonMotIR++;
                     }
                     else {                           // non
                        //vraiMotIR = motActuelIR;
                        compteurBonMotIR = 0;
                     }
               
                     // S'assurer d'avoir lu le même mot 3 fois avant de conclure que c'est
                     // le bon mot.
                     if(compteurBonMotIR > 2) {
                        vraiMotIR = motAncienIR;
                        debounceIR = TEMPS_DEBOUNCE_IR;
                        //   compteurVeille = TEMPS_VEILLE;   // Nouveau IR CMS
     
                        compteurBonMotIR = 0;
                        motAncienIR = 0;
                        motActuelIR = 0;
                     }
               
                     motAncienIR = motActuelIR;
               
                     // Initialiser le compteur de bits.
                     // On utilise 13 car une interruption est générée après le 12e bit.
                     compteurBitIR = 13;   
                     motActuelIR = 0;     //initialiser le mot
               }
            }
     
            else {
               motAncienIR = 0;
               motActuelIR = 0;
            }
         }
   }
}


and the setup

Code:
//Setup Timer 3 prescaler x1
       
       setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); 
       enable_interrupts(INT_TIMER3);
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