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!
Re: DSPIC33F Advance PWM fonctionnality (will giv all my poi
Think I found the solution, but I'm not happy of it. It seams that the TRIGx generate a PWM trigger (PWMCON1bits.TRGSTAT) not a start of conversion ... I must be missing something !!
Still looking for help here !!!
thank
A bit later ....
Found something Intresting, the ADC is updated but does not generate an interrupt
I still have an issue, it's looks like the DSPIC is exiting the while(1) after 5-10 min any Idea, I need an external oscillator ???? I have no idea, it's the first time this happen to me with PIC...
Re: DSPIC33F Advance PWM fonctionnality (will giv all my poi
Hi guys ..
I did a project like two months ago ,I used a dspic33F32MC..I needed to start a conversion cycle triggered by a pwm unit .I couldn't make it to work under MPLAB simulation .I runned the program in PROTEUS .And all was working perfectly .I decided to call MICROCHIP support line .They documented the bug .And told me that their engineers will correct it in the next release of MPLAB.
So if you need more help i can post the C code i wrote !
let me know1