Electronic – Activate 3 or more PWM signals in PIC

microcontrollerpicpwmxc8

I am doing a PWM with the PIC18f4550 and it managed to do it.
But only activate an output by varying the value of CCP1CON.
What I want to achieve is to have three PWM outputs and then be able to offset them to control a BLDC motor.

I attach the part of the code where I initialize the PWM:

public override PWM_Initialize ()
{
   PR2 = ("% # x", (_XTAL_FREQ / (PWM_freq * 4 * TMR2PRESCALE)) - 1);
   CCPR1L = 0x1F;
   TRISCbits.RC1 = 0;
   TRISCbits.RC2 = 0;
   TRISDbits.RD5 = 0;
   TRISDbits.RD6 = 0;
   TRISDbits.RD7 = 0;
   T2CON = 0x03;

   //CCP1CON = 0b01001100;
   CCP1CON = 0b11001100;

   TMR2 = 0;
   T2CONbits.TMR2ON = 1;
}

Attached image of the idea I have of the driver for the BLDC

enter image description here

Best Answer

If you have the 40-pin PIC18 then CCP1 has been replaced by the ECCP and you shouldn't have any problems.

Just enable Quad PWM mode and you will have 4 PWM channels: P1A, P1B, P1C, and P1D.

That's not entirely ideal though since for a BLDC you want 6 PWM signals since you have 6 transistors and you want to be able to control the dead-time between them.

That means that you have to forego complimentary PWM since you can't have independent control of all 6 switches for dead-time control or signal inversion which would be required if you are using NMOSFETs on both high-side and low-side.

You will probably have to PWM just high-side switches and use regular logic signals to just turn on the low-side switches during the commutation cycle with no PWM.

If you have a high-side bootstrap capacitor, this might need tweaking, especially during startup where RPM is lower so commutation cycles are longer. The reason is that the bootstrap cap needs to be constantly refreshed and therefore requires the low-side switch to turn on regularly enough to recharge the cap and you won't be able to do that regularly during a commutation cycle without complimentary PWM. The easiest thing to do is probably just to oversize your bootstrap capacitor so it can sustain the switching required throughout an entire commutation period without needing to be refreshed. After the commutation cycle is over the low-side switch for that half-bridge will get a chance to turn on during the commutation cycle for another phase so you can recharge the bootstrap cap.

Related Topic