Go Down

Topic: Arduino due - problem with dead time (Read 834 times) previous topic - next topic

Milan_UNIBO

Dear all,

I have been trying to implement dead time on the Arduino Due board using complementary PWM outputs in order to control H-bridge inverter.  On the first view, my program code works, but  not completely correct. Actually, two problem are appeared :

- at the beginning and in the end of the output signals I get overlaps - dead time in this two points does not have reaction
- if I adjust constant modulation signal instead of sin, every some time I can see bigger value of the dead time than adjusted value in the program code.

Does anybody know how I can solve this problem?
Maybe, I cannot see some detail which makes  this problem.

One part of my program code is :

PWMC_ConfigureChannelExt(PWM,
                           0,
                           PWM_CMR_CPRE_CLKA,
                           PWM_CMR_CALG,
                           0,
                           PWM_CMR_CES,
                           PWM_CMR_DTE,
                           0,
                           0);
  PWMC_SetPeriod(PWM, 0, cprd);
  PWMC_SetDutyCycle(PWM, 0, Ton1);
  PWMC_SetDeadTime(PWM, 0, DeadTimeHigh, DeadTimeLow);
 

Thank you.

Milan UNIBO

PaulS

Quote
Does anybody know how I can solve this problem?

Without seeing your code? No.

This belongs in the Due section.

Milan_UNIBO

Here is my program code, for  channel 0 : 

float x = 0; // argument of the sine function
const float pi = 3.1415;
int i = 0;
int k = 0;
float carrierfreq = 4000; // Carrier frequency
float modfreq = 50; // Modulation frequency
float ris = carrierfreq / modfreq; // points where the sine function is divided
float Ton1 = 0; // ignition time, random initialization
int DeadTimeHigh = 500;
int DeadTimeLow = 500;
float lookup1[2500]; 
int clkfreq = 42000000;
float cprd = (clkfreq /(carrierfreq*2));

void lookuptable() {
  for (i = 0; i <= ris; i++) {
    lookup1 = sin(x);
   x = x + 2 * pi / ris;
  }
}

void PWM_Handler(void)
{
  PWM->PWM_ISR2;

  Ton1 = abs(lookup1[k + 1]) * cprd;

  if (lookup1[k + 1] >= 0) {
    PWM->PWM_CH_NUM[0].PWM_CDTYUPD = Ton1;
    PWM->PWM_CH_NUM[0].PWM_DTUPD = DeadTimeHigh;
  }

  else {
    PWM->PWM_CH_NUM[0].PWM_CDTYUPD = 0;
    PWM->PWM_CH_NUM[0].PWM_DTUPD = DeadTimeLow;
  }

  if ((k + 1) < ris) {
    k++;
  }
  else {
    k = 0;
  }

}


void setPWMpin(uint32_t pin) {
  PIO_Configure(g_APinDescription[pin].pPort,
                PIO_PERIPH_B,
                g_APinDescription[pin].ulPin,
                g_APinDescription[pin].ulPinConfiguration);

}


void setup() {

  Serial.begin(9600);

  lookuptable(); // calling the function to be done

  // Making active desired PWM pin

  setPWMpin(34); //PWML0
  setPWMpin(35); //PWMH0

  pmc_enable_periph_clk(ID_PWM);

  PWMC_DisableChannel(PWM, 0); 

  PWMC_ConfigureClocks(clkfreq, 0, VARIANT_MCK);
 
  PWMC_ConfigureSyncChannel (PWM, PWM_SCM_SYNC0, PWM_SCM_UPDM_MODE1, 0, 0);

  PWMC_ConfigureChannelExt(PWM,
                           0,               
                           PWM_CMR_CPRE_CLKA,   
                           PWM_CMR_CALG,   
                           0,     
                           PWM_CMR_CES,         
                          PWM_CMR_DTE,         
                           0,                   
                           0);                 
  PWMC_SetPeriod(PWM, 0, cprd);       
  PWMC_SetDutyCycle(PWM, 0, Ton1);     
  PWMC_SetDeadTime(PWM, 0, DeadTimeHigh, DeadTimeLow);


  PWMC_EnableChannel(PWM,0); // Enabling the channel 0

  NVIC_DisableIRQ(PWM_IRQn);
  NVIC_ClearPendingIRQ(PWM_IRQn);
  NVIC_SetPriority(PWM_IRQn, 0);
  NVIC_EnableIRQ(PWM_IRQn);
  PWMC_EnableIt(PWM, 0, PWM_IER2_WRDY);
}

void loop() {

  Serial.println(34);

}





Go Up