Hello everybody
I'm having problems with the Input Capture Interrupt and the problem is that is not generating. I have other interrupts in the system and these are working ok. Here are the files I'm using and their contents.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
incap2isrwrapper.S
include
include "ISR_Support.h"
.set nomips16
.set noreorder
.extern vInputCapture2InterruptHandler
.extern xISRStackTop
.global vInputCapture2InterruptWrapper
.set noreorder
.set noat
.ent vInputCapture2InterruptWrapper
vInputCapture2InterruptWrapper:
portSAVE_CONTEXT
jal vInputCapture2InterruptHandler
nop
portRESTORE_CONTEXT
.end vInputCapture2InterruptWrapper
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
isr.c
void _ISR(INPUTCAPTURE2_VECTOR, ipl6) vInputCapture2InterruptWrapper(void);
void vInputCapture2InterruptHandler(void)
{
static portBASETYPE xHigherPriorityTaskWoken;
uint16t input_capture = 0; /* Varable where the input capture value is read */
xHigherPriorityTaskWoken = pdFALSE;
// Clear the interrupt flag
INTClearFlag(INTSOURCEINPUTCAP(INTIC2));
/*--------------------------- Add Application Code Here ------------------------------- */
if (mIC2CaptureReady())
{
/* Read captures while there still data in the capture buffer */
do
{
input_capture = mIC2ReadCapture();
}while(mIC2CaptureReady());
}
xQueueSendFromISR(InputCapDrvEventQueue, &input_capture, xHigherPriorityTaskWoken);
/* ------------------------------------------------------------------------------------ */
/* If DMA interrupt necessitates a context switch, then switch now. */
portENDSWITCHINGISR(xHigherPriorityTaskWoken);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input_compare.c
static void InputCapDriverSetup(void)
{
/* Set INT controller priority */
INTSetVectorPriority(INTVECTORINPUTCAP(INTINPUTCAPTURE2VECTOR), (configKERNELINTERRUPTPRIORITY + 2));
INTSetVectorSubPriority(INTVECTORINPUTCAP(INTINPUTCAPTURE2VECTOR), (configMAXSYSCALLINTERRUPTPRIORITY));
OpenTimer2(T2ON | T2SOURCEINT | T2PS1256 | T2IDLECON, PERIOD);
OpenCapture2(ICEVERYRISEEDGE | ICINT1CAPTURE | ICTIMER2SRC | ICCAP16BIT | ICIDLECON | ICON);
INTEnable(INTIC2, INTENABLED);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think everything is alright but if I put a breakpoint in the handler the execution doesn't stop. If I hit "pause" in the debug session then the IFS0 register show that the IC2IF is set and also the IC2CON shows that there is a capture present (ICBNE = 1). Also I've verified that IC2IE at IEC0 is set so I don't know what happens.
Has anybody used the PIC32 Input Capture module with FreeRTOS and have a working example?
By the way, I have a 25Hz 50% duty cycle pwm signal at the IC2 input pin so I think that's not the problem.
Regards
Does the interrupt work if you are not using FreeRTOS? It might not be a FreeRTOS question.
Regards.
Thanks for answering
You are right, I haven't checked if the interrupt works without FreeRTOS, I jumped directly in to FreeRTOS. I'll check that.
Regards.
Hi there
I implemented the isolated code to use the Input Capture for the PIC32 usig this code.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include
include
pragma config UPLLEN = ON // USB PLL Enabled
pragma config FPLLMUL = MUL_20
pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider
pragma config FPLLIDIV = DIV_2
pragma config FPLLODIV = DIV_1
pragma config FPBDIV = DIV_2
pragma config FWDTEN = OFF
pragma config POSCMOD = HS
pragma config FNOSC = PRIPLL
pragma config CP = OFF
pragma config BWP = OFF
pragma config PWP = OFF
pragma config FSRSSEL = PRIORITY_7
define SYS_FREQ (80000000L)
define PERIOD 0xFFFF
define SIZE 1000
uint16t CaptureTime[SIZE]; // Used to store the captured timer value
volatile uint32t array_index = 0;
int main(void)
{
SYSTEMConfig(SYSFREQ, SYSCFGWAITSTATES | SYSCFGPCACHE);
OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_256, PERIOD);
OpenCapture2(IC_EVERY_RISE_EDGE | IC_INT_1CAPTURE | IC_TIMER2_SRC | IC_CAP_16BIT | IC_IDLE_CON | IC_ON);
// Set up the input capture 1 interrupt with a priority of 2, subpriority of 0
INTEnable(INT_IC2, INT_ENABLED);
INTSetVectorPriority(INT_INPUT_CAPTURE_2_VECTOR, INT_PRIORITY_LEVEL_2);
INTSetVectorSubPriority(INT_INPUT_CAPTURE_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
// Enable multi-vector interrupts
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
INTEnableInterrupts();
while(1)
{
// Waiting for input capture event (stuck in this loop)
}
// Not executed
CloseCapture2();
CloseTimer2();
return 0;
}
// Configure the input capture interrupt handler
void _ISR(INPUTCAPTURE2VECTOR, ipl2) InputCaptureHandler(void)
{
// Clear the interrupt flag
INTClearFlag(INT_IC2);
if(mIC2CaptureReady())
{
do
{
// Store the timer value of the capture event into CaptureTime variable
CaptureTime[array_index++] = mIC2ReadCapture();
if(SIZE == array_index)
{
array_index = 0;
Nop();
}
}while(mIC2CaptureReady());
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
And it works perfectly. If I put a breakpoint in the Nop(); then I can see my CaptureTime array filled with 1000 captures that reflect the exact frequency of my input.
So, the input compare feature is working isolated and without FreeRTOS.
Have anyone implemented Input Capture for the PIC32 with FreeRTOS that can help me please?
Regards.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.