Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Capture PWM on a PIC32 Intx pin

Status
Not open for further replies.

sdecorme

Newbie level 5
Joined
Jun 20, 2013
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
FRANCE
Activity points
1,352
Hi,
I try to capture aPWM coming on my Int1 pin of my PIC32MX695F512H
when I use this code the interrupt make toggling the led at the right frequency,
but after the first interrupt my main loop crash and never loop again .
Any ideas ?
void Initialize(void)
{
mInit();
OpenTimer23(T2_ON | T2_32BIT_MODE_ON | T2_PS_1_1, 4000000000);
ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_6 |IC_INT_SUB_PRIOR_3);
OpenCapture1(IC_INT_1CAPTURE | IC_CAP_32BIT | IC_TIMER2_SRC | IC_EVERY_EDGE |IC_ON );
INTEnableSystemMultiVectoredInt();
mIC1ClearIntFlag();
Vitesse=0;
}


// Input capture interrupt handler
void __ISR(_INPUT_CAPTURE_1_VECTOR, IPL6SRS) InputCapture_Handler(void)
{
mLED_5_Toggle();
mPORTDClearBits(BIT_2);
mIC1ClearIntFlag();
while(!mIC1CaptureReady());
Vitesse = mIC1ReadCapture();
}

Thanks
 

void Initialize(void)
{
mInit();
OpenTimer23(T2_ON | T2_32BIT_MODE_ON | T2_PS_1_1, 4000000000);
ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_6 |IC_INT_SUB_PRIOR_3);
OpenCapture1(IC_INT_1CAPTURE | IC_CAP_32BIT | IC_TIMER2_SRC | IC_EVERY_EDGE |IC_ON );
INTEnableSystemMultiVectoredInt();
mIC1ClearIntFlag();
Vitesse=0;
while(1);
}


// Input capture interrupt handler
void __ISR(_INPUT_CAPTURE_1_VECTOR, IPL6SRS) InputCapture_Handler(void)
{
mLED_5_Toggle();
mPORTDClearBits(BIT_2);
mIC1ClearIntFlag();
while(!mIC1CaptureReady());
Vitesse = mIC1ReadCapture();
}
 

Hi Jinzpaul4u,
Thanks you but my main loop look like this already

main
{
Initialize()
while(1)
{
Toggle_LED_2();
}
}

So your code looks mine and done works.
my led2 stop to toggle at the first interrupt;

Thanks you
 

Hi There,

// Input capture interrupt handler
void __ISR(_INPUT_CAPTURE_1_VECTOR, IPL6SRS) InputCapture_Handler(void)
{
mLED_5_Toggle();
mPORTDClearBits(BIT_2);
mIC1ClearIntFlag();
while(!mIC1CaptureReady());
Vitesse = mIC1ReadCapture();
}


Please be ensure its coming out from while(!mIC1CaptureReady()); loop or else give small delay in toggle section.



my led2 stop to toggle at the first interrupt;

make sure your code is resetting the interrupt flag bit.

Regards,
 

Hi,
Now my main prog run and the Capture interrupt too , here is my code
For the init:
//Clear interrupt flag
mIC1ClearIntFlag();
// Setup Timer 3
OpenTimer3(T3_ON | T1_PS_1_1, 0x0);

// Enable Input Capture Module 1
// - Capture Every edge
// - Enable capture interrupts
// - Use Timer 3 source
// - Capture rising edge first
OpenCapture1( IC_EVERY_EDGE | IC_CAP_16BIT | IC_INT_1CAPTURE | IC_TIMER3_SRC | IC_ON );
ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_7 |IC_INT_SUB_PRIOR_3);
mIC1IntEnable(1);
INTEnableSystemMultiVectoredInt();
mIC1ClearIntFlag();

// Input capture interrupt handler
void __ISR(_INPUT_CAPTURE_1_VECTOR, IPL7SRS) InputCapture_Handler(void)
{
Vitesse = mIC1ReadCapture();
mIC1IntEnable(0);
mLED_5_Toggle();
mIC1IntEnable(1);
mIC1ClearIntFlag();
}

But now the problem is that mIC1ReadCapture() is always 0 ?



Edit:

If I change 0x0 to 0xFFFF in the timer config the captured value looks like this for a 50khz PWM
19599
37809
56019
8693
26903
45113
63323
15997
34207
52417
5091
23301
41511
59721
 
Last edited:

Finally I've made it like this

OpenTimer45(T45_ON | T45_PS_1_1 | T45_SOURCE_INT,1600000000);
ConfigINT1(EXT_INT_ENABLE | RISING_EDGE_INT | EXT_INT_PRI_7);
SetSubPriorityINT1(EXT_INT_SUB_PRI_3);
EnableINT1;
mINT1ClearIntFlag();
INTEnableSystemMultiVectoredInt();


void __ISR(_EXTERNAL_1_VECTOR, IPL7SRS) InputEncoder_Handler(void)
{
NbBetweenEdge = ReadTimer45();
WriteTimer45(0x00000000);

DisableINT1;
if(InterruptMode == RisingEdge)
{
mINT1SetEdgeMode(FallingEdge);
InterruptMode = FallingEdge;
}
else
{
mINT1SetEdgeMode(RisingEdge);
InterruptMode = RisingEdge;
}
EnableINT1;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top