PIC32 input capture not working in MPLAB-SIM

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

PIC32 input capture not working in MPLAB-SIM

Isaac Marino Bavaresco
I'm simulating a C32 application with MPLAB-SIM that uses input capture.
The timer increments and the input capture interrupt is being fired, but
the register IC1BUF doesn't get updated, stays at zero all the time.

The MPLAB IDE help says that input capture is implemented and works OK
in the simulator.

I am using 32-bit capture mode (TMR3:TMR2).

Did anybody stomp with this already? Im I doing some mistake?


Some code:

//==============================================================================

void InitPPM( void )
    {
   
//--------------------------------------------------------------------------
    // Initialize the pins

    // IC1 is mapped to pin RD8
    TRISDbits.TRISD8    = 1;    // Pin is an input

    // Enable the IC module in 32-bit mode, capturing every edge.
    IC1CON                = 0x00008306;
   
   
//--------------------------------------------------------------------------
    // Initialize the timer

    PR3                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
16 );
    PR2                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
0 );

    TMR3                = 0;
    TMR2                = 0;

    // Start timers 3 and 2 as a single 32 bit timer
    T2CON                = 0x00008008;
   
   
//--------------------------------------------------------------------------
    // Enable the interrupts

    INTSetVectorPriority( INT_INPUT_CAPTURE_1_VECTOR,
INT_PRIORITY_LEVEL_2 );
    INTSetVectorSubPriority( INT_INPUT_CAPTURE_1_VECTOR,
INT_SUB_PRIORITY_LEVEL_0 );
    INTClearFlag( INT_IC1 );
    INTEnable( INT_IC1, INT_ENABLED );
    }

//==============================================================================

unsigned long    PPM1TRise        = 0;
unsigned long    PPM1TFall        = 0;
unsigned int    PPM1Overflows    = 0;
unsigned long    PPM1PulseWidth    = 0;
unsigned int    PPM1State        = 0;

void __ISR( _INPUT_CAPTURE_1_VECTOR, ipl2 ) IntIC1Handler( void )
    {
    unsigned long    Temp;

    Temp            = IC1BUF;

    INTClearFlag( INT_IC1 );

    if( PORTDbits.RD8 )
        {
        // Signal rise
        PPM1TRise        = Temp;
        PPM1Overflows    = 0;
        PPM1State        = 1;
        }
    else
        {
        // Signal fall
        if( PPM1State == 1 )
            {
            PPM1State    = 0;
            if( PPM1Overflows < 2 )
                {
                PPM1TFall        = Temp;
                PPM1PulseWidth    = PPM1TFall - PPM1TRise;
                }
            else
                {
                // TODO: Lost the PPM signal
                }
            }
        }
    }

//==============================================================================

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: PIC32 input capture not working in MPLAB-SIM

electron-3
At 04.14 2011.11.04, you wrote:
>I'm simulating a C32 application with MPLAB-SIM that uses input capture.
>The timer increments and the input capture interrupt is being fired, but
>the register IC1BUF doesn't get updated, stays at zero all the time.
>
>The MPLAB IDE help says that input capture is implemented and works OK
>in the simulator.
>
>I am using 32-bit capture mode (TMR3:TMR2).

Are you sure that input capture works in 32bit mode? I would have wanted
to use it but by reading the data sheet I had the impression it wouldn't
work.

I would suggest you to try if it works in 16bit mode, maybe the problem
is this.

I am interested in your findings, I will experiment in this regard too
in some days.

Cheers,
Mario


>Did anybody stomp with this already? Im I doing some mistake?
>
>
>Some code:
>
>//====================================================================
>==========
>
>void InitPPM( void )
>    {
>  
>//--------------------------------------------------------------------------
>    // Initialize the pins
>
>    // IC1 is mapped to pin RD8
>    TRISDbits.TRISD8    = 1;    // Pin is an input
>
>    // Enable the IC module in 32-bit mode, capturing every edge.
>    IC1CON                = 0x00008306;
>  
>  
>//--------------------------------------------------------------------------
>    // Initialize the timer
>
>    PR3                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
>16 );
>    PR2                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
>0 );
>
>    TMR3                = 0;
>    TMR2                = 0;
>
>    // Start timers 3 and 2 as a single 32 bit timer
>    T2CON                = 0x00008008;
>  
>  
>//--------------------------------------------------------------------------
>    // Enable the interrupts
>
>    INTSetVectorPriority( INT_INPUT_CAPTURE_1_VECTOR,
>INT_PRIORITY_LEVEL_2 );
>    INTSetVectorSubPriority( INT_INPUT_CAPTURE_1_VECTOR,
>INT_SUB_PRIORITY_LEVEL_0 );
>    INTClearFlag( INT_IC1 );
>    INTEnable( INT_IC1, INT_ENABLED );
>    }
>
>//====================================================================
>==========
>
>unsigned long    PPM1TRise        = 0;
>unsigned long    PPM1TFall        = 0;
>unsigned int    PPM1Overflows    = 0;
>unsigned long    PPM1PulseWidth    = 0;
>unsigned int    PPM1State        = 0;
>
>void __ISR( _INPUT_CAPTURE_1_VECTOR, ipl2 ) IntIC1Handler( void )
>    {
>    unsigned long    Temp;
>
>    Temp            = IC1BUF;
>
>    INTClearFlag( INT_IC1 );
>
>    if( PORTDbits.RD8 )
>        {
>        // Signal rise
>        PPM1TRise        = Temp;
>        PPM1Overflows    = 0;
>        PPM1State        = 1;
>        }
>    else
>        {
>        // Signal fall
>        if( PPM1State == 1 )
>            {
>            PPM1State    = 0;
>            if( PPM1Overflows < 2 )
>                {
>                PPM1TFall        = Temp;
>                PPM1PulseWidth    = PPM1TFall - PPM1TRise;
>                }
>            else
>                {
>                // TODO: Lost the PPM signal
>                }
>            }
>        }
>    }
>
>//====================================================================
>==========
>
>--
>http://www.piclist.com PIC/SX FAQ & list archive
>View/change your membership options at
>http://mailman.mit.edu/mailman/listinfo/piclist

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: PIC32 input capture not working in MPLAB-SIM

Isaac Marino Bavaresco
>From Microchips "PIC32 Family Reference Manual, Sect. 15 Input Capture.pdf":


"Each PIC32MX device may have one or more Input Capture modules. Each
module can select
between one of two 16-bit timers for the time base or one 32-bit timer,
which is formed by
combining two 16-bit timers. Refer to the specific device data sheet for
the timers that can be
selected.
For 16-bit Capture mode, setting ICTMR (ICxCON<7>) to ‘0’ selects Timer3
for capture. Setting
ICTMR (ICxCON<7>) to ‘1’ selects Timer2 for capture.
An Input Capture module configured to support 32-bit capture may use a
32-bit timer resource
for capture. By setting ICC32 (ICxCON<8>) to ‘1’, a 32-bit timer
resource is captured. The 32-bit
timer resource is routed into the module using the existing 16-bit timer
inputs. Timer2 provides
the lower 16 bits and Timer3 provides the upper 16 bits, as shown in
Figure 15-2."


By the way, I'm using the PIC32MX795F512L.


Isaac


Em 4/11/2011 06:24, Electron escreveu:

> At 04.14 2011.11.04, you wrote:
>> I'm simulating a C32 application with MPLAB-SIM that uses input capture.
>> The timer increments and the input capture interrupt is being fired, but
>> the register IC1BUF doesn't get updated, stays at zero all the time.
>>
>> The MPLAB IDE help says that input capture is implemented and works OK
>> in the simulator.
>>
>> I am using 32-bit capture mode (TMR3:TMR2).
> Are you sure that input capture works in 32bit mode? I would have wanted
> to use it but by reading the data sheet I had the impression it wouldn't
> work.
>
> I would suggest you to try if it works in 16bit mode, maybe the problem
> is this.
>
> I am interested in your findings, I will experiment in this regard too
> in some days.
>
> Cheers,
> Mario
>
>
>> Did anybody stomp with this already? Im I doing some mistake?
>>
>>
>> Some code:
>>
>> //====================================================================
>> ==========
>>
>> void InitPPM( void )
>>    {
>>  
>> //--------------------------------------------------------------------------
>>    // Initialize the pins
>>
>>    // IC1 is mapped to pin RD8
>>    TRISDbits.TRISD8    = 1;    // Pin is an input
>>
>>    // Enable the IC module in 32-bit mode, capturing every edge.
>>    IC1CON                = 0x00008306;
>>  
>>  
>> //--------------------------------------------------------------------------
>>    // Initialize the timer
>>
>>    PR3                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
>> 16 );
>>    PR2                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
>> 0 );
>>
>>    TMR3                = 0;
>>    TMR2                = 0;
>>
>>    // Start timers 3 and 2 as a single 32 bit timer
>>    T2CON                = 0x00008008;
>>  
>>  
>> //--------------------------------------------------------------------------
>>    // Enable the interrupts
>>
>>    INTSetVectorPriority( INT_INPUT_CAPTURE_1_VECTOR,
>> INT_PRIORITY_LEVEL_2 );
>>    INTSetVectorSubPriority( INT_INPUT_CAPTURE_1_VECTOR,
>> INT_SUB_PRIORITY_LEVEL_0 );
>>    INTClearFlag( INT_IC1 );
>>    INTEnable( INT_IC1, INT_ENABLED );
>>    }
>>
>> //====================================================================
>> ==========
>>
>> unsigned long    PPM1TRise        = 0;
>> unsigned long    PPM1TFall        = 0;
>> unsigned int    PPM1Overflows    = 0;
>> unsigned long    PPM1PulseWidth    = 0;
>> unsigned int    PPM1State        = 0;
>>
>> void __ISR( _INPUT_CAPTURE_1_VECTOR, ipl2 ) IntIC1Handler( void )
>>    {
>>    unsigned long    Temp;
>>
>>    Temp            = IC1BUF;
>>
>>    INTClearFlag( INT_IC1 );
>>
>>    if( PORTDbits.RD8 )
>>        {
>>        // Signal rise
>>        PPM1TRise        = Temp;
>>        PPM1Overflows    = 0;
>>        PPM1State        = 1;
>>        }
>>    else
>>        {
>>        // Signal fall
>>        if( PPM1State == 1 )
>>            {
>>            PPM1State    = 0;
>>            if( PPM1Overflows < 2 )
>>                {
>>                PPM1TFall        = Temp;
>>                PPM1PulseWidth    = PPM1TFall - PPM1TRise;
>>                }
>>            else
>>                {
>>                // TODO: Lost the PPM signal
>>                }
>>            }
>>        }
>>    }
>>
>> //====================================================================
>> ==========
>>
>> --
>> http://www.piclist.com PIC/SX FAQ & list archive
>> View/change your membership options at
>> http://mailman.mit.edu/mailman/listinfo/piclist

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: PIC32 input capture not working in MPLAB-SIM

electron-3

Great, sorry for my mistake, I got confused with the dsPIC input capture module.

In some days I will definitely experiment (both SIM and ICD3) with IC on a
PIC32MX460F512L (should act just like your 795) and report.

Perhaps it's just the simulator, it's far from being perfect, this regardless
of what the help says.

Greets,
MarI/O


At 12.42 2011.11.04, you wrote:

>>From Microchips "PIC32 Family Reference Manual, Sect. 15 Input Capture.pdf":
>
>
>"Each PIC32MX device may have one or more Input Capture modules. Each
>module can select
>between one of two 16-bit timers for the time base or one 32-bit timer,
>which is formed by
>combining two 16-bit timers. Refer to the specific device data sheet for
>the timers that can be
>selected.
>For 16-bit Capture mode, setting ICTMR (ICxCON<7>) to ‘0’ selects Timer3
>for capture. Setting
>ICTMR (ICxCON<7>) to ‘1’ selects Timer2 for capture.
>An Input Capture module configured to support 32-bit capture may use a
>32-bit timer resource
>for capture. By setting ICC32 (ICxCON<8>) to ‘1’, a 32-bit timer
>resource is captured. The 32-bit
>timer resource is routed into the module using the existing 16-bit timer
>inputs. Timer2 provides
>the lower 16 bits and Timer3 provides the upper 16 bits, as shown in
>Figure 15-2."
>
>
>By the way, I'm using the PIC32MX795F512L.
>
>
>Isaac
>
>
>Em 4/11/2011 06:24, Electron escreveu:
>> At 04.14 2011.11.04, you wrote:
>>> I'm simulating a C32 application with MPLAB-SIM that uses input capture.
>>> The timer increments and the input capture interrupt is being fired, but
>>> the register IC1BUF doesn't get updated, stays at zero all the time.
>>>
>>> The MPLAB IDE help says that input capture is implemented and works OK
>>> in the simulator.
>>>
>>> I am using 32-bit capture mode (TMR3:TMR2).
>> Are you sure that input capture works in 32bit mode? I would have wanted
>> to use it but by reading the data sheet I had the impression it wouldn't
>> work.
>>
>> I would suggest you to try if it works in 16bit mode, maybe the problem
>> is this.
>>
>> I am interested in your findings, I will experiment in this regard too
>> in some days.
>>
>> Cheers,
>> Mario
>>
>>
>>> Did anybody stomp with this already? Im I doing some mistake?
>>>
>>>
>>> Some code:
>>>
>>> //====================================================================
>>> ==========
>>>
>>> void InitPPM( void )
>>>    {
>>>  
>>> //--------------------------------------------------------------------------
>>>    // Initialize the pins
>>>
>>>    // IC1 is mapped to pin RD8
>>>    TRISDbits.TRISD8    = 1;    // Pin is an input
>>>
>>>    // Enable the IC module in 32-bit mode, capturing every edge.
>>>    IC1CON                = 0x00008306;
>>>  
>>>  
>>> //--------------------------------------------------------------------------
>>>    // Initialize the timer
>>>
>>>    PR3                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
>>> 16 );
>>>    PR2                    = (unsigned short)( TMR32_PERIOD_REGISTER >>
>>> 0 );
>>>
>>>    TMR3                = 0;
>>>    TMR2                = 0;
>>>
>>>    // Start timers 3 and 2 as a single 32 bit timer
>>>    T2CON                = 0x00008008;
>>>  
>>>  
>>> //--------------------------------------------------------------------------
>>>    // Enable the interrupts
>>>
>>>    INTSetVectorPriority( INT_INPUT_CAPTURE_1_VECTOR,
>>> INT_PRIORITY_LEVEL_2 );
>>>    INTSetVectorSubPriority( INT_INPUT_CAPTURE_1_VECTOR,
>>> INT_SUB_PRIORITY_LEVEL_0 );
>>>    INTClearFlag( INT_IC1 );
>>>    INTEnable( INT_IC1, INT_ENABLED );
>>>    }
>>>
>>> //====================================================================
>>> ==========
>>>
>>> unsigned long    PPM1TRise        = 0;
>>> unsigned long    PPM1TFall        = 0;
>>> unsigned int    PPM1Overflows    = 0;
>>> unsigned long    PPM1PulseWidth    = 0;
>>> unsigned int    PPM1State        = 0;
>>>
>>> void __ISR( _INPUT_CAPTURE_1_VECTOR, ipl2 ) IntIC1Handler( void )
>>>    {
>>>    unsigned long    Temp;
>>>
>>>    Temp            = IC1BUF;
>>>
>>>    INTClearFlag( INT_IC1 );
>>>
>>>    if( PORTDbits.RD8 )
>>>        {
>>>        // Signal rise
>>>        PPM1TRise        = Temp;
>>>        PPM1Overflows    = 0;
>>>        PPM1State        = 1;
>>>        }
>>>    else
>>>        {
>>>        // Signal fall
>>>        if( PPM1State == 1 )
>>>            {
>>>            PPM1State    = 0;
>>>            if( PPM1Overflows < 2 )
>>>                {
>>>                PPM1TFall        = Temp;
>>>                PPM1PulseWidth    = PPM1TFall - PPM1TRise;
>>>                }
>>>            else
>>>                {
>>>                // TODO: Lost the PPM signal
>>>                }
>>>            }
>>>        }
>>>    }
>>>
>>> //====================================================================
>>> ==========
>>>
>>> --
>>> http://www.piclist.com PIC/SX FAQ & list archive
>>> View/change your membership options at
>>> http://mailman.mit.edu/mailman/listinfo/piclist
>
>--
>http://www.piclist.com PIC/SX FAQ & list archive
>View/change your membership options at
>http://mailman.mit.edu/mailman/listinfo/piclist

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: PIC32 input capture not working in MPLAB-SIM

sza7890
This post has NOT been accepted by the mailing list yet.
I understand its been a while that this thread was posted but I am currently working with PIC24FV and trying to simulate Input Capture module(capturing rising edges) with MPLAB SIM. I am generating Pulses on RB9 pin in the 'Pin/Register Actions' tab but no success. No interrupt from input capture. Can anyone please clarify what should be the settings for MPLAB SIM to simulate input capture?