Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pwm with interrupt not work

Status
Not open for further replies.

abolfazlk873

Junior Member level 3
Joined
Dec 2, 2012
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,488
hi everybody
following program is written for dspic33ep256mu806 by microC pro for dspic . the purpose of program is generating pwm output.
in my program pwm generator 1 is set to work and independent interrupt for pwm generator 1 is set to work .
pwm generator 1 is work but interrupt doesn't work .
in my last program i was using the Special event interrupt and it works well. but i need to use 1 interrupt for each pwm generator.
Any help is appreciated .
compiler : microC pro for dspic
my program :
Code:
/////////GLOBAL defined
#define  test_periode   364                     // Diagnostic frequency = 3 KHz
#define  test_duty      160
#define  test_sev       155
#define  work_periode   54687               // Work frequency = 20 Hz
#define  work_duty      4000
#define  work_sev       16770
         
///////GLOBAL FUNCTION////////////////////
void power_up_pwm(void);
void IER_1 (void);
void ADC_initial (void);
/////
static unsigned int ADCValues_1[4] = {0, 0, 0, 0};
static char value[8] ;

//////// ISR //////////////////////////////

void pwm_1() iv IVT_ADDR_PWM1INTERRUPT ics ICS_AUTO {
     while( !AD1CON1bits.DONE );
     AD1CON1bits.DONE=0;
     ADCValues_1[1] = ADC1BUF0;     // Read the AN0 conversion result

     IntToStr( ADCValues_1[1], value);

     IFS5bits.PWM1IF=0;
     return;
}

///////MAIN FUNCTION/////////////////////
void main()
{
////////OSCILLATOR CONFIGURATION   Fosc=70 MHz
             CLKDIV.DOZE_0=0;
             CLKDIV.DOZE_1=0;
             CLKDIV.DOZE_2=0;

             CLKDIV.PLLPRE_0=0;        //0+2
             CLKDIV.PLLPRE_1=0;
             CLKDIV.PLLPRE_2=0;
             CLKDIV.PLLPRE_3=0;
             CLKDIV.PLLPRE_4=0;

             CLKDIV.PLLPOST_0=1;      //2(1+1)
             CLKDIV.PLLPOST_1=0;

             PLLFBD=0x0044;           //68+2  

/////////PIN CONFIGURATION
              RPINR12 = 0x7677;  // fault inputs
              RPINR18 = 0x0047;  // uart1 receive
              RPOR3 = 0x0001;     // uart1 tx
////////
              ANSELB=0x01df;
              ANSELC=0x0000;
              ANSELD=0x0000;
              ANSELE=0x0000;
              ANSELG=0x0000;
////////
              TRISB=0xf9df;
              TRISC=0x1000;
              TRISD=0x0088;
              TRISE=0x0000;
              TRISF.B1=0;
              TRISG.B8=0;
              TRISG.B9=0;
///////// pwm configuration
              UART1_Init(115200);
              ADC_initial ();
              IER_1 ();
              power_up_pwm();
              while(1){
                        UART1_Write(13);
                        UART1_Write_Text("phase_1:");
                        UART1_Write_Text(value);
              }

}

void power_up_pwm(void){
              SPHASE1 = test_periode;
              /* Set Duty Cycles */
              SDC1 = test_duty;
              /* Set Dead Time Values */
              DTR1 = DTR2 = DTR3 = 0;
              ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
              /* Set PWM Mode to Independent */
              IOCON1 = IOCON2 = IOCON3 = 0x4C00;
              /* PHASEx/SPHASEx registers provide time base period for this
                 PWM generator,Edge-Aligned Mode and independent Duty Cycles , enable trigger for interrupt */
              PWMCON1 = PWMCON2 = PWMCON3 = 0x0601;
              /* Configure Faults */
              FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
              /* 64:1 Prescaler */
              PTCON2 = 6;
              /* ADC Special Event Trigger Configuration */
              TRIG1 = test_sev;                                       /* Event Trigger value  */
              TRGCON1bits.TRGDIV = 0;                      /* Event Trigger output postscaler set to 1:1 selection */
              TRGCON1bits.TRGSTRT =0;
              /* Enable PWM Module ,  event interrupt is enabled */
              PTCON = 0x8400;
}

void IER_1 (void){
     /* Enable level 1-7 interrupts */
     INTCON2bits.GIE=1;
     /* Interrupt nesting enabled here */
     INTCON1bits.NSTDIS = 0;
     /* Set PWM1  Event Match interrupt priority*/
     IPC23bits.PWM1IP=7;
     /* Reset PWM1  Event Match interrupt flag */
     IFS5bits.PWM1IF=0;
     /* Enable PWM1  Event Match interrupt */
     IEC5bits.PWM1IE=1;
     return;
}

void ADC_initial (void){
                AD1CON1 = 0x0010;     	// PWM Generator 1 primary trigger compare ends sampling and starts
                AD1CON2 = 0x0000;
                AD1CON3 = 0x008B;
                AD1CON4 = 0x0000;
                AD1CHS0 = 0x0000;     	// select AN0 for convert
                AD1CHS123 = 0x0000;
                AD1CSSH = 0x0000;
                AD1CSSL = 0x0000;
                AD1CON1bits.ADON = 1;       // Turn on the A/D converter
                Delay_us(10);

}
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top