The interrupt has a postscaler, the SEVOPS bits in the PWMCON2 control register.
Could this be your problem?
Thanks for your reply
Unfortunately, I have it selected as 0 (0000 = 1:1 Postscale). It's right, isn't it?!
The Adc trigered with the pwm signals should call the ADC interruption in the middle of the period of the pwm signal, right? I can't find information about it...
---------- Post added 31-01-12 at 00:03 ---------- Previous post was 30-01-12 at 23:58 ----------
My PWM init code:
void PWM_init(void) {
// Initialize the PWM Module
PTPER = ((FCY/FPWM) - 1 ) >> 1; // Compute Period for desired frequency
OVDCON = 0x0000; // Disable all PWM outputs
DTCON1 = 0x0000; // Dead Time = 0
DTCON1 = 0.000002 * FCY;
PWMCON1 = 0x00EE; //Enable PWM Pins and enable complementary mode
PWMCON2 = 0x0011;
PDC2 = PTPER; // initial value = 0 Volts
PDC3 = PTPER; // initial value = 0 Volts
PDC4 = PTPER; // initial value = 0 Volts
IFS2bits.PWMIF = 0; // Clear PWM interrupt flag
IEC2bits.PWMIE = 1; // Enable PWM interrupt
OVDCON = 0xFC00; // PWM outputs are controller by PWM module
PTCONbits.PTMOD= 2 ; // Center aligned PWM operation
PTCONbits.PTEN = 1; // Start PWM
}
And my ADC init code:
void ADC_init(void)
{
ADCON1 = 0;
// Signed fractional (DOUT = sddd dddd dd00 0000)
ADCON1bits.FORM = 3;
// Motor Control PWM interval ends sampling and starts conversion
ADCON1bits.SSRC = 3;
// Simultaneous Sample Select bit (only applicable when CHPS = 01 or 1x)
// Samples CH0, CH1, CH2, CH3 simultaneously (when CHPS = 1x)
// Samples CH0 and CH1 simultaneously (when CHPS = 01)
ADCON1bits.SIMSAM = 1;
// Sampling begins immediately after last conversion completes.
// SAMP bit is auto set.
ADCON1bits.ASAM = 1;
ADCON2 = 0;
// Samples CH0, CH1, CH2, CH3 simultaneously (when CHPS = 1x)
ADCON2bits.CHPS = 2;
ADCON3 = 0;
// A/D Conversion Clock Select bits = 8 * Tcy
ADCON3bits.ADCS = 15;
/* ADCHS: ADC Input Channel Select Register */
ADCHS = 0;
// CH0 is AN7 - MUDEI PARA O 10
ADCHSbits.CH0SA = 10;
// CH1 positive input is AN0, CH2 positive input is AN1, CH3 positive input is AN2
ADCHSbits.CH123SA = 0;
/* ADPCFG: ADC Port Configuration Register */
// Set all ports digital
ADPCFG = 0xFFFF;
ADPCFGbits.PCFG0 = 0; // AN0 analog
ADPCFGbits.PCFG1 = 0; // AN1 analog
ADPCFGbits.PCFG2 = 0; // AN2 analog
ADPCFGbits.PCFG10 = 0; // AN7 analog - MUDEI PARA O 10
/* ADCSSL: ADC Input Scan Select Register */
ADCSSL = 0;
// Turn on A/D module
ADCON1bits.ADON = 1;
return;
}