Author Topic: PIC18F57K42 - Interrupt - Pickit3 Program flashing Problem  (Read 1042 times)

0 Members and 1 Guest are viewing this topic.

Offline arulTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: in
PIC18F57K42 - Interrupt - Pickit3 Program flashing Problem
« on: February 20, 2019, 06:42:52 pm »
Hai,

Now i writing one program for data acquisition using PIC18F57K42 uc and the hardware tool as Pickit3. The inputs are analog input and pulse. So I am using ADC module for analog meaurement and CCP-capture module for pulse width measurement. The conversion are taken out from UART. I am using three interrupt i.e timer3(regular time interval) and timer1&CCP1(pulse measurement).

The analog inputs are read at regular intervals using one of the timer interrupt for regular interval measurement and otherwise the pulse width is measured. I did the measurement separately, it is okay.

When i integrate both, i got some bugs. The bugs are (1) When i flash the program to the controller, at the same time, the pulse is fed at controller CCP capture input pin mean i got conversion at the UART otherwise sometimes i didn't get the ouput. (2) In this manner, suppose i switch OFF the pulse input, after i didn't get UART output. (3) Then I switch OFF the system, after switch ON system i didn't get anything from UART.

The code as
Code: [Select]
   
    PIR4bits.CCP1IF = 0;
    PIE4bits.CCP1IE = 1;
   
    PIR4bits.TMR1IF = 0;
    PIE4bits.TMR1IE = 1;
   
    PIR6bits.TMR3IF = 0;
    PIE6bits.TMR3IE = 1;
   
    INTCON0bits.GIEH = 1;
    INTCON0bits.GIEL = 1;
    INTCON0bits.IPEN = 1;

   
   

   
   
    while (1)
    {

        if(flag == true)
        {
        ADCC_GetSingleConversion(channel_AND4);
        ADCC_GetConversionResult();
        converted_value = ADCC_GetConversionResult();
        actual_res = (float) converted_value *((float) VRef/(float) ADC_Resolution)  ;
        FPM = actual_res;
       
        UART1_string("Forward Power Monitor (FPM) Value is : "); UART1_Write('\n');
        UART_RES(FPM); UART1_Write('\n');
       

   
       
        ADCC_GetSingleConversion(channel_AND5);
        ADCC_GetConversionResult();
        converted_value = ADCC_GetConversionResult();
        actual_res = (float) converted_value *((float) VRef/(float) ADC_Resolution)  ;
        RPM = actual_res;
       
        UART1_string("Reverse Power Monitor (RPM) Value is : "); UART1_Write('\n');
        UART_RES(RPM); UART1_Write('\n');
       
        flag = false;
        }
     


        if(cap == true)
        {
                ED = edge2 - edge1;
                signal_period = (float) Timer_Freq/ (float) ED;
                time = signal_period;

                UART1_string("Frequency is : ");
                UART1_Write('\n');
                UART_RES(signal_period);
                UART1_Write('\n');

                cap = false;
        }
    }
}





void __interrupt() INTERRUPT_InterruptManager (void)
{

    if(PIE6bits.TMR3IE == 1 && PIR6bits.TMR3IF == 1)
    {
        TMR3L = 0x06;
        TMR3H = 0xFF;

       
        count++;
            if(count == 10000)
            {
                flag  = true;
                count = 0;
                Pulse = ~Pulse ;
            }   
        PIR6bits.TMR3IF = 0;
    }
   
   
    if(PIE4bits.CCP1IE == 1 && PIR4bits.CCP1IF == 1)
    {
            PIR4bits.CCP1IF = 0;
            edge1 = (CCPR1H<<8) | (CCPR1L & 0xFF);

            while(!(PIR4bits.CCP1IF));

            edge2 = (CCPR1H<<8) | (CCPR1L & 0xFF); 


            TMR1H = 0x00;
            TMR1L = 0x00;

                if(edge1<edge2)
                {
                    cap = true;
                }
            PIR4bits.CCP1IF = 0;
    }

}

Please let me know which possibility make a wrong...!

Advance in thanks
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: PIC18F57K42 - Interrupt - Pickit3 Program flashing Problem
« Reply #1 on: February 20, 2019, 07:39:43 pm »
How long is the pulse? If your pulse is not long enough, the whole pulse may be already over by the time you reset CCP1IF in your interrupt. Then you're waiting for the falling edge which never comes.

Also, while you're waiting for the falling edge, the interrupts are effectively disabled, so you TMR3 processing gets blocked.

Your chip has two-level vectored interrupts. You can use them.
 
The following users thanked this post: arul

Offline arulTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: in
Re: PIC18F57K42 - Interrupt - Pickit3 Program flashing Problem
« Reply #2 on: February 20, 2019, 07:50:33 pm »
If I did not give the pulse input mean that the analog conversion should be done at regular intervals. But  i can't get the analog conversion at UART. And also if i switch OFF the system, after switch ON, i can't get anything at UART. So which one make the bug???
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: PIC18F57K42 - Interrupt - Pickit3 Program flashing Problem
« Reply #3 on: February 20, 2019, 08:39:16 pm »
If I did not give the pulse input mean that the analog conversion should be done at regular intervals.

If your program is stuck within the interrupt waiting for CCP1IF, nothing will be done.

Remove the CCP processing from the interrupt and it all should start working.
 
The following users thanked this post: arul


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf