CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Complementary outputs with PWM with dsPIC33EP

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rufinopc@rufinogg.com



Joined: 11 Mar 2023
Posts: 20

View user's profile Send private message

Complementary outputs with PWM with dsPIC33EP
PostPosted: Sun Feb 02, 2025 3:08 pm     Reply with quote

Until now I was using the DRV8432 dual motor driver with the dsPIC33EP512MC806 micro. I configured the driver so that with a single PWM input for each motor I got from 5% to 50% the motors would turn and change speed in one direction and from 50% to 100% in another (50% stopped)
Currently Texas Instrument has stopped manufacturing the driver and they say that the equivalent is the DRV8262. I have performed different tests with this driver and so far I have found that it needs complementary PWM for each channel.

The compiler version I use is 5.109 and I don't see a way to have complementary outputs.

The example I show is using the old driver and with a PWM output per channel.
Code:

#include <33EP512MC806.h>

#include "ctype.h"
#include "string.h"
#include "stdlib.h"



#FUSES PR_PLL         //Primary Oscillator with PLL
#FUSES HS            //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOGSSK         //General Segment Key bits, use if using either NOWRT or NOPROTECT fuses
#FUSES CKSNOFSM         //Clock Switching is enabled, fail Safe clock monitor is disabled
#FUSES NOIOL1WAY      //Multiples reconfiguraciones
#FUSES ALTI2C1         //I2C1 mapped to SDA1/SCL1 pins
//   #FUSES ALTI2C2         //I2C2 mapped to SDA2/SCL2 pins
#FUSES NOJTAG         //JTAG disabled
#FUSES NOAPLK
#FUSES WDT
#FUSES NOBROWNOUT
#FUSES NOWRT

#use delay(clock=120MHz,crystal=8MHz,RESTART_WDT)


     ////////////////////// Configuración de los PWM
    #define PWMA1            PIN_E2          //M1     
    #define PWMA2            PIN_E4          //M2
    #define RESET2             PIN_E7          //
    #define RESET1            PIN_E6
    #USE PWM(OUTPUT=PWMA2, FREQUENCY=475kHz, DUTY=50, STREAM=MOTOR2) 
    #USE PWM(OUTPUT=PWMA1, FREQUENCY=475kHz, DUTY=50, STREAM=MOTOR1) 
   
    #define HabilitaM1()      output_high(RESET1)
    #define DesHabilitaM1()      output_low(RESET1)
    #define HabilitaM2()      output_high(RESET2)
    #define DesHabilitaM2()      output_low(RESET2)   
//////////////////////////////////////////////////////////////////////////
void TestDeGiro(void){
  boolean Bandera = TRUE;
  int16 Contador = 0;
 
  HabilitaM1();
  HabilitaM2();

  while(TRUE){
    for(Contador=-480; Contador <480; Contador++){
        delay_ms(10);
        pwm_set_duty_percent(MOTOR2,500+Contador);
        pwm_set_duty_percent(MOTOR1,500+Contador);
    }
     delay_ms(1000); 
     for(Contador=480; Contador >-480; Contador--){
        delay_ms(10);
        pwm_set_duty_percent(MOTOR2,500+Contador);
        pwm_set_duty_percent(MOTOR1,500+Contador);
    }   
    delay_ms(1000);   
     
   }
}

Does anyone please know how to get complementary outputs or know where to get information?
Thank you very much
rufinopc@rufinogg.com



Joined: 11 Mar 2023
Posts: 20

View user's profile Send private message

PostPosted: Sun Feb 02, 2025 3:21 pm     Reply with quote

Here is main()
Code:

//////////////////////////////////////////////////////////////////////////
 #ZERO_RAM 
void main(){
    HabilitaM1();
    HabilitaM2();
   
    pwm_set_duty(MOTOR1,50);
    pwm_set_duty(MOTOR2,50);   
   TestDeGiro();


}//end
temtronic



Joined: 01 Jul 2010
Posts: 9370
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 02, 2025 4:20 pm     Reply with quote

I don't use that PIC but....
maybe look in the header file ?
#include <33EP512MC806.h>

for all the options that CCS knows about.

? Does teh datasheet actually SHOW that you can have comp outputs ?
temtronic



Joined: 01 Jul 2010
Posts: 9370
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 02, 2025 5:15 pm     Reply with quote

OK, fixing my truck,need a break, downloaded the datasheet
saw this in the PWM chapter (16).
BITS 13 and 12 control 'pin polarity'
so my thinking is to make bit 13 high, bit 12 low will 'complement' the output pins ???

REGISTER 16-19: IOCONx: PWMx I/O CONTROL REGISTER
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PENH PENL POLH POLL PMOD<1:0>(1) OVRENH OVRENL
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
OVRDAT<1:0> FLTDAT<1:0> CLDAT<1:0> SWAP OSYNC
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15 PENH: PWMxH Output Pin Ownership bit
1 = PWM module controls PWMxH pin
0 = GPIO module controls PWMxH pin
bit 14 PENL: PWMxL Output Pin Ownership bit
1 = PWM module controls PWMxL pin
0 = GPIO module controls PWMxL pin
bit 13 POLH: PWMxH Output Pin Polarity bit
1 = PWMxH pin is active-low
0 = PWMxH pin is active-high
bit 12 POLL: PWMxL Output Pin Polarity bit
1 = PWMxL pin is active-low
0 = PWMxL pin is active-high

hay, this is only a semieducated guess froma very quik scan of the 600+ pages, but it sounds 'pretty good' in my head.....

All else fail, see what Application Notes Microchip have cause ,yeesh, that internal peripheral is waay more complicated than a 16C84 !!!
dyeatman



Joined: 06 Sep 2003
Posts: 1946
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Feb 03, 2025 6:52 am     Reply with quote

Also, hspwm has a complementary option.
_________________
Google and Forum Search are some of your best tools!!!!
rufinopc@rufinogg.com



Joined: 11 Mar 2023
Posts: 20

View user's profile Send private message

PostPosted: Tue Feb 04, 2025 1:22 am     Reply with quote

Thanks for your answers.
I'm sorry, but I haven't found any example of how to configure the complementary output pins of the PWM. I think the manual always presents any explanation in a very summarized way and unfortunately users have to turn to people like you to learn how to use the different configurations. An example that hardly requires explanation is the following:
#define PWMA1 PIN_E2
#USE PWM(OUTPUT=PWMA2, FREQUENCY=475kHz, SERVICE=50, FLUX=MOTOR2)
But as soon as you go beyond that the explanations are so brief that it is not possible to go into it in depth. Thanks again.
alan



Joined: 12 Nov 2012
Posts: 358
Location: South Africa

View user's profile Send private message

PostPosted: Tue Feb 04, 2025 1:44 am     Reply with quote

From the manual
Quote:
setup_hspwm_unit( )
Syntax:
setup_hspwm_unit(unit, mode, [dead_time], [alt_dead_time]);
set_hspwm_duty(unit, primary, [secondary]);
Parameters:
unit - The High Speed PWM unit to set.
mode - Mode to setup the High Speed PWM unit in. The valid option vary depending on
the device. See the device's header file for all options. Some typical options include:
HSPWM_ENABLE
Built-in Functions
HSPWM_ENABLE_H
HSPWM_ENABLE_L
HSPWM_COMPLEMENTARY
HSPWM_PUSH_PULL
dead_time - Optional 16-bit constant or variable to specify the dead time for this PWM
unit, defaults to 0 if not specified.
alt_dead_time - Optional 16-bit constant or variable to specify the alternate dead time for
this PWM unit, default to 0 if not specified.
Returns:
-----
Function:
Sets up the specified High Speed PWM unit.
Availability:
Only on devices with a built-in High Speed PWM module (dsPIC33FJxxGSxxx,
dsPIC33EPxxxMUxxx, dsPIC33EPxxxMCxxx, and dsPIC33EVxxxGMxxx devices)
Requires:
Constants are defined in the device's .h file
Examples:
setup_hspwm_unit(1,HSPWM_ENABLE|SHPWM_COMPLEMENTARY, 100,100);
dyeatman



Joined: 06 Sep 2003
Posts: 1946
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Feb 04, 2025 5:59 am     Reply with quote

You can also look in the examples at ex_hspwm.c
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19649

View user's profile Send private message

PostPosted: Tue Feb 04, 2025 6:21 am     Reply with quote

Lets just slow down a touch.
You were originally trying to use the standard PWM module and program
a complementary output using this. The issue with this is that most
switching gates have very slightly different off switching times to on
switching times. If you use a simple complementary input, you have the
risk that there will be a tiny moment when both gates are conducting
a bit at the same time. Result increase in power consumption and more
RF noise.
This is why systems designed for complementary drive, normally allow
you to very slightly delay the time of one signal relative to the other.
The HSPPM module supports this. Now this has to be setup using the
setup_hspwm_unit command rather than the #USE PPM. However as
general advice I would suggest using this. Means you have to change to
usinge it's duty commands as well.
Key thing though is that you can add a tiny value for the dead_time
figures, and may well find the system runs better for this.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group