trouble sync mcpwm

arnoldg
Posts: 3
Joined: Sun Sep 01, 2019 6:07 am

trouble sync mcpwm

Postby arnoldg » Sun Sep 01, 2019 6:11 am

I have a test setup to dim a light.
the hardware conssist of a ZCD connected to GPIO22
a vom1271 gate connected to GPIO23
The vom controlles 2 mosfets back to back.

i have the the code working, only the light is flickering and the pwm signal isn't stable.
what can i do to get a more stable pwm signal.

below is the code
to see what is happening see this video, you see on the lower part of the scope the ZCD, the upper part is the PWM signal, you see the pwm signal isn't stable and below the scope you sometimes see the light flickering.

Youtube clip of flickering and scope image

Code: Select all

#include "driver/mcpwm.h"

#define GPIO_SYNC0_IN 23       //pin for the external interrupt (Input with Pullup)                         
#define MOSFET 22          //pin to trigger the MOSFET (Output) pin22

void setup() {
  // put your setup code here, to run once:
  mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, MOSFET);


  mcpwm_pin_config_t pin_config; 
    pin_config.mcpwm_sync0_in_num  = GPIO_SYNC0_IN;
      
  mcpwm_config_t pwm_config;
    pwm_config.frequency = 60;    //frequency = 110Hz
    pwm_config.cmpr_a = 100;       //duty cycle of PWMxA = 60.0%
    pwm_config.counter_mode = MCPWM_UP_COUNTER;
    pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
    
  mcpwm_set_pin(MCPWM_UNIT_0, &pin_config);
  mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);   //Configure PWM0A & PWM0B with above settings
  mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0);
  mcpwm_start(MCPWM_UNIT_0, MCPWM_TIMER_0);
  mcpwm_sync_enable(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SELECT_SYNC0, 0);

  mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A,25);
}

void loop() {
}

Who is online

Users browsing this forum: No registered users and 97 guests