Hi. Does anyone know a clean way to have an OC module self-sync but also reset the associated TMR at the same time? I want to do this so that I can use the TMR3 rollover event to trigger an ADC capture at the start of the OC's PWM period. It doesn't appear to be possible to trigger an ADC capture directly from the OC module.
Here's my config:
I determined that TMR3 wasn't being reset by checking its value upon the OC1 interrupt. It's random
Here's my config:
Code:
//****************************************
// TIMER3: L pump ON/OFF: 16MHz increment
//****************************************
T3CONbits.TCS = 0; // internal clk
T3CONbits.TCKPS = 0; // no prescaler
T3CONbits.TON = 0; // ensure OFF to start with
// set up output compare on OC1
OC1CON1 = 0;
OC1CON1bits.OCM = 0b110; // edge-aligned PWM
OC1CON1bits.OCTSEL = 1; // TMR3 drives clock
OC1CON2bits.SYNCSEL = 0x1F; // self-sync
IFS0bits.OC1IF = 0;
IEC0bits.OC1IE = 1; // interrupt on every OC1 event
OC1R = 8;
OC1RS = 100;
Code:
void __attribute__((interrupt,auto_psv)) _OC1Interrupt(void)
{ // start of L PWM pulse
da = TMR3;
IFS0bits.OC1IF = 0;
}