PWM - 180 degrees out of phase

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Lord Grezington
Flowcode V4 User
Posts: 229
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 18 times
Been thanked: 23 times
Contact:

PWM - 180 degrees out of phase

Postby Lord Grezington » Thu May 16, 2019 10:04 am

Hello All (and to @medelec35)

I have come across an old post where Martin simulated an inverse PWM viewtopic.php?f=29&t=8701&p=26384&#p26295 .Has anyone managed to test this on hardware?

Martin, could you perhaps simulate what would happen on your simulator if you had a dsPIC33EP running 120Mhz and a PWM frequency of 29.28Khz? (Period Overflow 2048, prescaler = 1)

Thanks

Lord Grezington
Flowcode V4 User
Posts: 229
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 18 times
Been thanked: 23 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Lord Grezington » Tue May 21, 2019 7:14 pm

With this...

Is there not a better way of doing this rather than using a timer interupt? If we can somehow use and interupt on change, but rather than a change on a pin use the ccpril variable? Would this not make a much more responsive inverse PWM with a smaller phase shift? pProblem bieng is that a lafter phase shift would mean a longer required dead time when driving mosfets in a totem pole configuration, and has Martin mensions in the post the higher frequencies will cause phase shift issues when its timer based.

Doing it hardware based is a hassle as I need to disable the totem pole (both fets open at the same time) during certain instances, and I cant do this with a synchronous fet driver. I have looked at using hardware to do it (logic gates) but it starts looking messy (I will need a few totem poles, not just the one).

I am looking to use the dsPIC33EP

Any advise on this would be very usefull

Thanks

User avatar
Benj
Matrix Staff
Posts: 14151
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4079 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Benj » Wed May 22, 2019 10:39 am

Hello,

We support the H-bridge feature on 8-bit PIC devices. I could look to add this to the 16-bit devices too. This includes things like dead time and out of phase PWM.

Let me know which device you're looking at and I'll see if it has the functionality for you and how easy it would be to add support for.

Lord Grezington
Flowcode V4 User
Posts: 229
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 18 times
Been thanked: 23 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Lord Grezington » Wed May 22, 2019 1:17 pm

Hi Ben

I will be looking at using the dsPIC33EP32MC504 with three half bridges

Thanks

Lord Grezington
Flowcode V4 User
Posts: 229
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 18 times
Been thanked: 23 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Lord Grezington » Wed May 22, 2019 5:39 pm

Hi Ben

Another question... if the 3 pairs of advanced PWM were used for the 3 half bridges would there still be 4 normal PWM's for other outputs?..

Thanks

User avatar
Benj
Matrix Staff
Posts: 14151
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4079 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Benj » Thu May 23, 2019 9:36 am

Hello,

I will be looking at using the dsPIC33EP32MC504 with three half bridges


Yes that should be fine. Let's start by using C code to drive the peripherals and once that is working maybe we can move this into the H-bridge component.

I'll see if I can generate some reference code for you to have a play with.

if the 3 pairs of advanced PWM were used for the 3 half bridges would there still be 4 normal PWM's for other outputs?..


Yes looking at the datasheet I believe this is correct.

Lord Grezington
Flowcode V4 User
Posts: 229
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 18 times
Been thanked: 23 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Lord Grezington » Thu May 23, 2019 4:11 pm

Thanks Ben

Once you get some reference code together I will be happy to test it.

Thanks

User avatar
Benj
Matrix Staff
Posts: 14151
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4079 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Benj » Fri May 24, 2019 3:47 pm

Right, this is some C code I am currently using here for a high speed PWM operation. It won't be quite what you need but it should hopefully point you in the right direction. Have a look through the high speed PWM section of the device datasheet and go through the various control registers tweaking the values to get the operation you need.

Code: Select all

asm volatile("mov #0xabcd,w10 ; Load first unlock key to w10 register");
asm volatile("mov #0x4321,w11 ; Load second unlock key to w11 register");
asm volatile("mov #0x0003,w0 ; Load desired value of FCLCON1 register in w0");
asm volatile("mov w10, PWMKEY ; Write first unlock key to PWMKEY register");
asm volatile("mov w11, PWMKEY ; Write second unlock key to PWMKEY register");
asm volatile("mov w0,FCLCON3 ; Write desired value to FCLCON1 register");

PTCON2 = 0x0000;      // Master prescaler = 1:1 (128975000Hz)
PTPER = 0xFFFF;       // Master period = 0xffff (calc at max resolution)
PDC3 = 0x0000;        // Duty = 0

asm volatile("mov #0xabcd,w10 ; Load first unlock key to w10 register");
asm volatile("mov #0x4321,w11 ; Load second unlock key to w11 register");
asm volatile("mov #0x0000,w0 ; Load desired value of IOCON1 register in w0");
asm volatile("mov w10, PWMKEY ; Write first unlock key to PWMKEY register");
asm volatile("mov w11, PWMKEY ; Write second unlock key to PWMKEY register");
asm volatile("mov w0,IOCON1 ; Write desired value to IOCON1 register");

asm volatile("mov #0xabcd,w10 ; Load first unlock key to w10 register");
asm volatile("mov #0x4321,w11 ; Load second unlock key to w11 register");
asm volatile("mov #0x0000,w0 ; Load desired value of IOCON1 register in w0");
asm volatile("mov w10, PWMKEY ; Write first unlock key to PWMKEY register");
asm volatile("mov w11, PWMKEY ; Write second unlock key to PWMKEY register");
asm volatile("mov w0,IOCON2 ; Write desired value to IOCON2 register");

asm volatile("mov #0xabcd,w10 ; Load first unlock key to w10 register");
asm volatile("mov #0x4321,w11 ; Load second unlock key to w11 register");
asm volatile("mov #0x5000,w0 ; Load desired value of IOCON1 register in w0");
asm volatile("mov w10, PWMKEY ; Write first unlock key to PWMKEY register");
asm volatile("mov w11, PWMKEY ; Write second unlock key to PWMKEY register");
asm volatile("mov w0,IOCON3 ; Write desired value to IOCON3 register");

PTCONbits.PTEN = 1;   // Enable....


Then load the duty using this C code.

Code: Select all

PDC3 = FCL_RDUTY2;


Let me know how you get on and if you're struggling then I can either have a look at your code or have a go myself.

Lord Grezington
Flowcode V4 User
Posts: 229
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 18 times
Been thanked: 23 times
Contact:

Re: PWM - 180 degrees out of phase

Postby Lord Grezington » Mon May 27, 2019 7:27 pm

OK Ben

Will try and load it into hardware with the added variables tomorrow.