pic18f8520 CCP problem

Discussion in 'Embedded Systems and Microcontrollers' started by iceman529, Jun 28, 2013.

  1. iceman529

    Thread Starter New Member

    Jun 17, 2013
    16
    0
    [​IMG]Hello i am trying to capture the first bit of an uart message with the CCP in capture mode, the problem is that once in a wile the interupt fires without any signal on the line, exactly when the interrupt is enabled(happens one every minute or so), i found this using an oscilloscope on the DEV2_LED, the delay between each uart frame is 20 ms, and the length of the frame is 2-3ms, i switch the interrupt off each time i receive the falling edge of the first bit of the frame and i putt it on back ~12ms after that, or at least that is what i want to do.
    the ccp interrupt are enabled in high priority isr and thy are checked in low priority
    a picture with the osciloscope can be see here , blue line DEV1_LED, yellow line UART,
    Code ( (Unknown Language)):
    1.  
    2. void ActivateCcpInterrupt(u8 channel)
    3. {
    4.     switch(channel)
    5.     {
    6.         case 5:
    7.             CCP5IF = FALSE;
    8.             CCP5IE = TRUE;
    9.             break;
    10.         case 4:
    11.             CCP4IF = FALSE;
    12.             CCP4IE = TRUE;
    13.             break;
    14.         case 3:
    15.             CCP3IF = FALSE;
    16.             CCP3IE = TRUE;
    17.             break;
    18.     }
    19. }
    20.  
    21.                 //this part is inside a timer interrupt that fires every ms
    22.                 // the problem appears here afer the interrupt is se to enable the isr for the interrupt is executed without any signal on the uart, both of the lines are observed on the oscilloscope
    23.                 //enabling the ccp interrupt after a 12ms delay
    24.                 if(ccp3IsDisabled)
    25.                 {
    26.                     if(ccp3Timer-- == 0)
    27.                     {
    28.                         ccp3Timer = 12;
    29.                         ccp3IsDisabled = FALSE;
    30.                         ActivateCcpInterrupt(3);
    31.                     }
    32.                 }
    33.                 if(ccp4IsDisabled)
    34.                 {
    35.                     if(ccp4Timer-- == 0)
    36.                     {
    37.                         ccp4Timer = 12;
    38.                         ccp4IsDisabled = FALSE;
    39.                         ActivateCcpInterrupt(4);
    40.                     }
    41.                 }
    42.                 if(ccp5IsDisabled)
    43.                 {
    44.                     if(ccp5Timer-- == 0)
    45.                     {
    46.                         ccp5Timer = 12;
    47.                         ccp5IsDisabled = FALSE;
    48.                         ActivateCcpInterrupt(5);
    49.                     }
    50.                 }
    51.  
    52. // this part is inside the low priority isr
    53.  if(CCP3IF && CCP3IE)
    54.     { //!< A capture interrupt is set for CCP3
    55.         temp=CCPR3;
    56.         CCP3IF=FALSE; //!< Set capture interrupt flag false
    57.         CCP3IE=FALSE;  //!< Disable Capture interrupt
    58.         DEV3_LED = !DEV3_LED;
    59.         ccp3IsDisabled = TRUE;
    60.         CCP_time_log(2,temp);    //!< Logging tmr value, for ccp3
    61.     }
    62.  
    63.     if(CCP4IF && CCP4IE)
    64.     { //!< A capture interrupt is set for CCP4
    65.         temp=CCPR4;
    66.         CCP4IF=FALSE; //!< Set capture interrupt flag false
    67.         CCP4IE=FALSE;  //!< Disable Capture interrupt
    68. //        DEV2_LED = !DEV2_LED;
    69.         ccp4IsDisabled = TRUE;
    70.           CCP_time_log(1,temp);    //!< Logging tmr value, for ccp4
    71.     }
    72.  
    73.     if(CCP5IF && CCP5IE)
    74.     { //!< A capture interrupt is set for CCP5
    75.         temp=CCPR5;
    76. //        COMPENSATE_TMR3(temp);
    77.         CCP5IF=FALSE; //!< Set capture interrupt flag false
    78.         CCP5IE=FALSE;  //!< Disable Capture interrupt
    79.         DEV1_LED = !DEV1_LED;
    80.         ccp5IsDisabled = TRUE;
    81.          CCP_time_log(2,temp);    //!< Logging tmr value, for ccp5
    82.     }
    83.  
     
    Last edited: Jun 28, 2013
  2. iceman529

    Thread Starter New Member

    Jun 17, 2013
    16
    0
    later edit: after a little bit of digging up the the isr doesn't execut exactly after the delay, it waits 5-7ms and after that the interrupt is triggered, what could cause this scenario?
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    I wonder what the manual says...

    Otherwise I can't make any sense out of the code fragments you posted. It's always best to cut the code down to the simplest piece that demonstrates the problem. And all the module set-up code should be provided.
     
Loading...