sec
Advanced Member level 4
Hi everyone,
I am working with the DSPIC33FJ16GS502 for a little while. I would like my PWM to trigger an ADC conversion but without success. Anyone know how to do ?? I've been looking around the Special event trigger and the dedicated trigger but without succes. I know my ADC interrupt function is ok because it is triggered at the start of the program and if I do not reset the flag it loops out and in the ADC interrupt
The interrupt function is not include, ask for it if you think it is the problem
Please Help,
I'll give all my points to the one who found the error!
I am working with the DSPIC33FJ16GS502 for a little while. I would like my PWM to trigger an ADC conversion but without success. Anyone know how to do ?? I've been looking around the Special event trigger and the dedicated trigger but without succes. I know my ADC interrupt function is ok because it is triggered at the start of the program and if I do not reset the flag it loops out and in the ADC interrupt
Code:
//*****************ADC********************
ADCONbits.ASYNCSAMP =1; //CONSTANTLY SAMPLING
ADCONbits.FORM =0; //Integer OUTPUT
ADCONbits.SLOWCLK =0; //ADC is clock by the primary PLL (FVCO)
ADCONbits.SEQSAMP =1;
ADCONbits.ADCS =0; //FADC/1
ADCONbits.EIE =1; //Interrupt is generated after first conversion is completed
_SWTRG0=1;
ADPCFG =0b1111111111111101; //All digital but AN1
ADCPC0bits.TRGSRC0 =0b00100; //00100 = PWM Generator 1 primary trigger selected for an0 and an1
ADCPC0bits.IRQEN0 =1; //Enable IRQ generation when requested conversion of channels AN1 and AN0 is completed
IPC3bits.ADIP =7; // Set Common ADC Interrupt Priority Level (Level 1)
IFS0bits.ADIF =0; // Clear ADC Pair 0 Interrupt Flag
IEC0bits.ADIE =1; // Enable ADC Pair 0 Interrupt
//IFS6bits.ADCP1IF =0;
//IEC6bits.ADCP1IE =1;
//IPC27bits.ADCP1IP =7;//7 is highest priority
SRbits.IPL =0;
//****************PWM
//PWMH and PWML are active-high and controlled by PWM Module in push-pull
//Duty-cycle register is PDC1 and updates to the active MDC/PDCx/SDCx registers are immediate
//more code ...
//Try to trigger ADC
//The value in this register represents the captured PWM time base value when a leading edge is
//detected on the current-limit input.
TRGCON1 = 0;
SEVTCMP=0X000F; //Trying things here
TRIG1=250; //When period match trigger should occur
STRIG1=0X000F;
TRGCON1bits.TRGDIV = 0; // trigger every trigger event
TRGCON1bits.TRGSTRT = 0; // wait 0 pwm cycles to generate trigger
TRGCON1bits.DTM = 0;
// more code
ADCONbits.ADON =1; //Enable ADC
while(1);
The interrupt function is not include, ask for it if you think it is the problem
Please Help,
I'll give all my points to the one who found the error!