m4l490n wrote on Monday, September 01, 2014:
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.
incap2_isr_wrapper.S
#include <p32xxxx.h>
#include <sys/asm.h>
#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(_INPUT_CAPTURE_2_VECTOR, ipl6) vInputCapture2InterruptWrapper(void);
void vInputCapture2InterruptHandler(void)
{
static portBASE_TYPE xHigherPriorityTaskWoken;
uint16_t input_capture = 0; /* Varable where the input capture value is read */
xHigherPriorityTaskWoken = pdFALSE;
// Clear the interrupt flag
INTClearFlag(INT_SOURCE_INPUT_CAP(INT_IC2));
/*--------------------------- 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. */
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
input_compare.c
static void Input_Cap_Driver_Setup(void)
{
/* Set INT controller priority */
INTSetVectorPriority(INT_VECTOR_INPUT_CAP(INT_INPUT_CAPTURE_2_VECTOR), (configKERNEL_INTERRUPT_PRIORITY + 2));
INTSetVectorSubPriority(INT_VECTOR_INPUT_CAP(INT_INPUT_CAPTURE_2_VECTOR), (configMAX_SYSCALL_INTERRUPT_PRIORITY));
OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_256 | T2_IDLE_CON, PERIOD);
OpenCapture2(IC_EVERY_RISE_EDGE | IC_INT_1CAPTURE | IC_TIMER2_SRC | IC_CAP_16BIT | IC_IDLE_CON | IC_ON);
INTEnable(INT_IC2, INT_ENABLED);
}
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