Hi,

I want to use all 6 PWM outputs in uC separately to generate impulse 1ms- 2ms with period of 20ms. I calculated everything and get correct values. Problem is that to achieve six completely separate outputs I must reverse all outputs. My question is : Is bit 5 (POINV) i register PWMCON1 work correctly? In my code changing the bit doesn't change output polarity.

GP3CON &= ~(0xF << (PWM1 << 2));

GP3CON &= ~(0xF << (PWM2 << 2));

GP3CON &= ~(0xF << (PWM3 << 2));

GP3CON &= ~(0xF << (PWM4 << 2));

GP3CON &= ~(0xF << (PWM5 << 2));

GP3CON &= ~(0xF << (PWM6 << 2));

GP3CON |= (1U << (PWM1 << 2));

GP3CON |= (1U << (PWM2 << 2));

GP3CON |= (1U << (PWM3 << 2));

GP3CON |= (1U << (PWM4 << 2));

GP3CON |= (1U << (PWM5 << 2));

GP3CON |= (1U << (PWM6 << 2));

PWM1LEN = SERVO_PERIOD; //20ms

PWM2LEN = SERVO_PERIOD;

PWM3LEN = SERVO_PERIOD;

PWM1COM3 = SERVO_MAX;

PWM1COM2 = 5222;

PWM1COM1 = 5222 + SERVO_MAX;

PWM2COM3 = SERVO_MAX;

PWM2COM2 = 5222;

PWM2COM1 = 5222 + SERVO_MAX;

PWM3COM3 = SERVO_MAX;

PWM3COM2 = 5222;

PWM3COM1 = 5222 + SERVO_MAX;

//     PWMCON1 = 0x38E1;

PWMCON1 = 0x38E1;

This code should generate 1ms impulse witch period 20ms on all 6 outputs.

• Sorry for not conning back earlier. But I have seen you also read other threads on this PWM topic.

The simple way does not work - PWMCON1 POINV is only working for H-bridge-mode - that may need to be clarified a bit more in the data-sheets. But you can invert individually all  2nd outputs for each channel (PWM2, PWM4 & PWM6).

Easiest for your application to use an external HW inverter and generate low pulses with the PWM as a solution.

I would anyway recommend for general applications to do it that way, because after POR (power-on-reset) all pin's are configured as inputs with weak-pull-ups - so for example a motor driver can generate a short-circuit. With a inverter this doesn't hurt your power-stage.

Or if you have pins available which are connected to PLA outputs, you can use the PLA to invert the signal on chip - all port P3 pins are internally connected to PLA inputs. But again, after POR all pins are inputs with a pull-up - so be prudent in how you implement it.

updated by MMA