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.

[SOLVED] dsPIC33 2 PWM generate with 180 phase angles with equal duty need help

Status
Not open for further replies.

online79

Member level 1
Joined
Jun 12, 2013
Messages
37
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,510
dsPIC33 2 channel PWM generate with 180 phase angle with equal duty need help

I need help dsPIC33 pwm generate in which 2 pwm generate in 180 degree phase angle with equal duty cycle. Please help me by providing sample code in mikroc pro for dsPIC if anybody have......
 
Last edited:

Re: dsPIC33 2 channel PWM generate with 180 phase angle with equal duty need help

Mention exact dsPIC33 device name.
 

Re: dsPIC33 2 channel PWM generate with 180 phase angle with equal duty need help

for getting help of simulation in proteus i select dsPIC33FJ32MC204
 

Re: dsPIC33 2 channel PWM generate with 180 phase angle with equal duty need help

You have to configure PWm to get complementary signals on one of the paired PWM channels. Did you read the dsPIC33 device datasheet's PWM section ?
 

Re: dsPIC33 2 channel PWM generate with 180 phase angle with equal duty need help

yes i know it i already read the datasheet. I already generate 2 pwm, but want to generate 180 degre phase angle with adjustable duty..........

- - - Updated - - -

in complementary mode, the two pwm generate 180 degree, but generate same start time & same end time, i want to generate it like push pull.

- - - Updated - - -

like this ................ pwm.JPG
 

Re: dsPIC33 2 channel PWM generate with 180 phase angle with equal duty need help

Complementary signals are for push-pull. They are already 180 degrees phase shifted.

Do you want SPWM signals for Inverter ? If yes, then you have to manually vary the duty registers in Timer Interrupt.

Both signals start at the same time and one will be high and another low. So, You can use IR2112 to drive High-Side and Low-Side Mosfets with complementary signals.

Show your code.
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

//////////// code in mikroc for dsPIC /////////////////

Code:
  void interrupt(){
    IFS3bits.PWM1IF = 0;
    if(P1OVDCONbits.POVD1H){
    PWMCON1bits.PEN1H = 0;
    PWMCON1bits.PEN1L = 1;
    }
    else{
    PWMCON1bits.PEN1H = 1;
    PWMCON1bits.PEN1l = 0;
    }
  }

   void main(void){
   PORTA = 1;
   TRISA = 0x00;
   TRISB = 0x0000; // Configure RB0 as a digital output for an indicator LED
   PWMCON1bits.PMOD1 = 1; //   PMOD1 = 1; // Enable PWM channel 1 in independent mode
   PWMCON1bits.PEN1H = 1; //   PEN1H = 1; // Enable PWM1H pin
   PWMCON1bits.PEN1L = 1; //   PEN1L = 1; // Enable PWM1L pin
   P1OVDCONbits.POUT1L = 0; //  POUT1L = 0; // When PWM1L is overriden, set it low
   P1OVDCONbits.POUT1H = 0;  // POUT1H = 0; // When PWM1H is overriden, set it low
   P1OVDCONbits.POVD1L = 1; //   POVD1L = 1; // Initially, enable override on PWM1L
   P1OVDCONbits.POVD1H = 1; //   POVD1H = 0; // Initially, enable override on PWM1H
   PWM1CON2bits.OSYNC = 1; //   OSYNC = 1; // Synchronise PWM override changes with PTMR reset
   IEC3bits.PWM1IE = 1;
   P1TCONbits.PTCKPS = 3; //   PTCKPS = 0; // prescale=1:64 (0=1:1, 1=1:4, 2=1:16, 3=1:64)
   P1TPER = 1569; // Set PWM frequency to 50 Hz
   PDC1 = 1050; // Set duty cycle to 10%
   PTCONbits.PTEN = 1; //   PTEN = 1; // Enable PWM time base
   while(1){
    }
   }

- - - Updated - - -

simulation is ..............pwm1.JPG

- - - Updated - - -

///& if the code is...............//
Code:
  void interrupt(){
    IFS3bits.PWM1IF = 0;
    if(P1OVDCONbits.POVD1H){
    PWMCON1bits.PEN1H = 0;
    PWMCON1bits.PEN1L = 1;
    }
    else{
    PWMCON1bits.PEN1H = 1;
    PWMCON1bits.PEN1l = 0;
    }
  }

   void main(void){
   PORTA = 1;
   TRISA = 0x00;
   TRISB = 0x0000; // Configure RB0 as a digital output for an indicator LED
   PWMCON1bits.PMOD1 = 0; //   PMOD1 = 1; // Enable PWM channel 1 in independent mode
   PWMCON1bits.PEN1H = 1; //   PEN1H = 1; // Enable PWM1H pin
   PWMCON1bits.PEN1L = 1; //   PEN1L = 1; // Enable PWM1L pin
   P1OVDCONbits.POUT1L = 0; //  POUT1L = 0; // When PWM1L is overriden, set it low
   P1OVDCONbits.POUT1H = 0;  // POUT1H = 0; // When PWM1H is overriden, set it low
   P1OVDCONbits.POVD1L = 1; //   POVD1L = 1; // Initially, enable override on PWM1L
   P1OVDCONbits.POVD1H = 1; //   POVD1H = 0; // Initially, enable override on PWM1H
   PWM1CON2bits.OSYNC = 1; //   OSYNC = 1; // Synchronise PWM override changes with PTMR reset
   IEC3bits.PWM1IE = 1;
   P1TCONbits.PTCKPS = 3; //   PTCKPS = 0; // prescale=1:64 (0=1:1, 1=1:4, 2=1:16, 3=1:64)
   P1TPER = 1569; // Set PWM frequency to 50 Hz
   PDC1 = 1050; // Set duty cycle to 10%
   PTCONbits.PTEN = 1; //   PTEN = 1; // Enable PWM time base
   while(1){
    }
   }

- - - Updated - - -

simulation like this.................pwm2.JPG

- - - Updated - - -

but i need...........pwm.JPG
 
Last edited by a moderator:

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

The code you posted is XC16 code and not mikroC PRO dsPIC Code. Do you want XC16 code to be ported to mikroC PRO dsPIC ?

Both channels are configured as independent and delay is provided before starting the second signal.

What is your PWM frequency ?

What duties you want ?
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

i have no xc16, i build this code in mikroc PRO for dsPIC, you test it just past it in mikroc PRO for dsPIC.....
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

Ok. Are you using Standard PWM or Motor Control PWM ?
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

Standard pwm..........

- - - Updated - - -

Just a minute, i not use any library of mikroC Pro dsPic....

- - - Updated - - -

Thank's for your reply & try to help me........
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

It is better to use mikroC PRO dsPIC library. It can be done using mikroC PRO dsPIC library functions.
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

I already try the library, but no pulse generate, not understand why........ i just try this by doing only copy pase the example code......do you help me to identify where i make the mistake to use the library.......
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

Ok. Post your mikroC PRO dsPIC code which uses library functions. I will check it.
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

Code:
unsigned int current_duty, old_duty, current_duty1, old_duty1;
unsigned int pwm_period1, pwm_period2;

void InitMain() {
  ADPCFG = 0xFFFF;                           // Configure AN pins as digital I/O
                           // configure PORTB pins as input
  PORTB = 0;                                 // set PORTD to 0
  TRISB = 0;                                 // designate PORTD pins as output
}

void main() {
  InitMain();
  current_duty  = 16;                        // initial value for current_duty
  current_duty1 = 16;                        // initial value for current_duty1

  pwm_period1 = PWM_Init(5000 , 1, 1, 2);
  pwm_period2 = PWM_Init(10000, 2, 1, 3);

  PWM_Start(1);
  PWM_Start(2);

  PWM_Set_Duty(current_duty,  1);            // Set current duty for PWM1
  PWM_Set_Duty(current_duty1, 2);            // Set current duty for PWM2

  while (1) {                                // endless loop
    if (RB0_bit) {                           // button on RB0 pressed
      Delay_ms(20);
      current_duty++;                        // increment current_duty
      if (current_duty > pwm_period1) {      // if we increase current_duty greater then possible pwm_period1 value
        current_duty = 0;                    // reset current_duty value to zero
      }
      PWM_Set_Duty(current_duty,  1);        // set newly acquired duty ratio
     }

    if (RB1_bit) {                           // button on RB1 pressed
      Delay_ms(20);
      current_duty--;                        // decrement current_duty
      if (current_duty > pwm_period1) {      // if we decrease current_duty greater then possible pwm_period1 value (overflow)
        current_duty = pwm_period1;          // set current_duty to max possible value
      }
      PWM_Set_Duty(current_duty,  1);        // set newly acquired duty ratio
     }

    if (RB2_bit) {                           // button on RB2 pressed
      Delay_ms(20);
      current_duty1++;                       // increment current_duty1
      if (current_duty1 > pwm_period2) {     // if we increase current_duty1 greater then possible pwm_period2 value
        current_duty1 = 0;                   // reset current_duty1 value to zero
      }
      PWM_Set_Duty(current_duty1,  2);       // set newly acquired duty ratio
     }

    if (RB3_bit) {                           // button on RB3 pressed
      Delay_ms(20);
      current_duty1--;                       // decrement current_duty1
      if (current_duty1 > pwm_period2) {     // if we decrease current_duty1 greater then possible pwm_period1 value (overflow)
        current_duty1 = pwm_period2;         // set current_duty to max possible value
      }
      PWM_Set_Duty(current_duty1,  2);
     }

    Delay_ms(5);                             // slow down change pace a little
  }
}
 
Last edited by a moderator:

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

Ok. I will check.
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

//// I also try ///////////

Code:
unsigned int current_duty, old_duty, current_duty1, old_duty1;
unsigned int pwm_period1, pwm_period2;

void InitMain() {
  ADPCFG = 0xFFFF;                           // Configure AN pins as digital I/O

  PORTB = 0;                                 // set PORTB to 0
  TRISB = 0;                                 // designate PORTB pins as output
  
  PORTC = 0;                                 // set PORTC to 0
  TRISC = 0xFFFF;                                 // designate PORTC pins as input
}

void main() {
  InitMain();
  current_duty  = 16;                        // initial value for current_duty
  current_duty1 = 16;                        // initial value for current_duty1

  pwm_period1 = PWM_Init(5000 , 1, 1, 2);
  pwm_period2 = PWM_Init(10000, 2, 1, 3);

  PWM_Start(1);
  PWM_Start(2);

  PWM_Set_Duty(current_duty,  1);            // Set current duty for PWM1
  PWM_Set_Duty(current_duty1, 2);            // Set current duty for PWM2

  while (1) {                                // endless loop
    if (RC1_bit) {                           // button on RB0 pressed
      Delay_ms(20);
      current_duty++;                        // increment current_duty
      if (current_duty > pwm_period1) {      // if we increase current_duty greater then possible pwm_period1 value
        current_duty = 0;                    // reset current_duty value to zero
      }
      PWM_Set_Duty(current_duty,  1);        // set newly acquired duty ratio
     }

    if (RC2_bit) {                           // button on RB1 pressed
      Delay_ms(20);
      current_duty--;                        // decrement current_duty
      if (current_duty > pwm_period1) {      // if we decrease current_duty greater then possible pwm_period1 value (overflow)
        current_duty = pwm_period1;          // set current_duty to max possible value
      }
      PWM_Set_Duty(current_duty,  1);        // set newly acquired duty ratio
     }

    if (RC3_bit) {                           // button on RB2 pressed
      Delay_ms(20);
      current_duty1++;                       // increment current_duty1
      if (current_duty1 > pwm_period2) {     // if we increase current_duty1 greater then possible pwm_period2 value
        current_duty1 = 0;                   // reset current_duty1 value to zero
      }
      PWM_Set_Duty(current_duty1,  2);       // set newly acquired duty ratio
     }

    if (RC4_bit) {                           // button on RB3 pressed
      Delay_ms(20);
      current_duty1--;                       // decrement current_duty1
      if (current_duty1 > pwm_period2) {     // if we decrease current_duty1 greater then possible pwm_period1 value (overflow)
        current_duty1 = pwm_period2;         // set current_duty to max possible value
      }
      PWM_Set_Duty(current_duty1,  2);
     }

    Delay_ms(5);                             // slow down change pace a little
  }
}
 
Last edited by a moderator:

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

Ok. I am checking. Are you testing in hardware because Proteus might have bugs related to standard PWM channels working.
 

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

no, i not check in hardware, presently i just test it in proteus, the chip is not available in local market, but with my first code, the pulse show in proteus oscilloscope is ok.

- - - Updated - - -

Mr. baileychic, sorry to say, but from the starting of this discussion, i provide you code, picture all what you need, but you not provide a single, i am confused what are you doing? have you any knowledge about it or you gather the knowledge from me?
 
Last edited:

Re: dsPIC33 2 PWM generate with 180 phase angle with equal duty need help

I tried Mc PWm and it works. I am now trying standard PWM. My code is simple using mikroC PRO dsPIC library functions.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top