Created Sat, 29 Nov 2014 18:50:37 +0000 by PICedh
Sat, 29 Nov 2014 18:50:37 +0000
Hello
As soon as OC1 is enable, the following source loops in the Interrupt fonction and never come back to the main. Could you please indicate what is wrong ?
Here is the log:
vw-setup chipkit prescaler: 1 nticks: 5000 __ISR chipkit end __ISR chipkit __ISR chipkit end __ISR chipkit __ISR chipkit end __ISR chipkit .....
[code]#include <sys/attribs.h> //used for __ISR
extern "C"
{
void __ISR(_OUTPUT_COMPARE_1_VECTOR,ipl7) OC1_IntHandler2(void) { //priority 7
Serial.println("__ISR chipkit");
IFS0CLR = 0x0040;// Clear the OC1 interrupt flag}
Serial.println("end __ISR chipkit");
}
void vw_setup()
{
uint16_t nticks; // number of prescaled ticks needed
uint8_t prescaler; // Bit values for CS0[2:0]
nticks =5000;
prescaler = 1;
Serial.println("vw-setup chipkit");
Serial.print("prescaler: "); Serial.println((int)prescaler);
Serial.print("nticks: "); Serial.println(nticks);
// Initialization TIMER2
T2CON = 0x0000 ; // 0x0000=0000000000000000
// ON=0 (Timer is disable for now)
// FRZ=0 (Continue operation even when CPU is in Debug Exception mode)
// SIDL=0 (Continue operation even in Idle mode)
// TGATE=0 (Gated time accumulation is disabled)
// TCKPS=000 (prescale value updated below)
// T32=0 (TMRx and TMRy form separate 16-bit timer)
// TCS=0 (Internal peripheral clock)
T2CONbits.TCKPS = 1 << (prescaler-1); //TCKPS= prescale value CPU clock = 80 MHz => Period : prescale value/80Mhz = prescale value/80 000 000
//111 = 1:256 prescale value
//110 = 1:64 prescale value
//101 = 1:32 prescale value
//100 = 1:16 prescale value
//011 = 1:8 prescale value
//010 = 1:4 prescale value
//001 = 1:2 prescale value
//000 = 1:1 prescale value
PR2 = nticks; // TIMER2 Period = (nticks+1)* prescale value/80 000 000 seconds
// Configure the control register OC1CON for the output compare channel 1
OC1CON = 0x0000; // clear OC1
OC1CONbits.OCTSEL = 0; // Select Timer 2 as output compare time base
OC1CONbits.OCM = 0b011; // OCM=011: Compare event toggles OCx pin
// Configure the compare register OC1R and compare register secondary OC1RS for the output compare channel 1
OC1R = 5000; // set initial cycle in counts
// Configure int
IFS0CLR = 0x0040; // Clear the OC1 interrupt flag
IEC0SET = 0x040; // Enable OC1 interrupt
IPC1SET = 0x001C0000; // Set OC1 interrupt priority to 7
IPC1SET = 0x00030000; // Set Subpriority to 3, maximum
// Enable Timer 2 and OC1
T2CONSET = 0x8000; // Enable Timer2
OC1CONSET = 0x8000; // Enable OC1
Serial.println("end vw-setup chipkit");
}
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
vw_setup();
}
void loop()
{
Serial.println("hello");
}
[/code]
}
Tue, 02 Dec 2014 21:30:15 +0000
Hi,
Please note that I have removed the 'Serial.println' in the ISR handler and now everything is fine. I don't know the rott casue of the issue but I will take care of the manner to debug ISR