Two PWM Signal with Dead Time

Hello!

So I was trying to achieve a dead time using this code in the video and down below. The frequency used in the video and the code attached below is only for 31KHz. When I copied the code and uploaded it to my Arduino, it was working fine with expected results.

#define ANALOG_IN_PIN A0

void setup ()
{ 
  //TCCR2B = TCCR2B & 0xF8 | 0x01; 
  //TCCR0B = TCCR0B & B11111000 | B00000001; // 62.5KHz //D4 & 13
  //TCCR0A |= 0x30; // inversion
  TCCR1B = TCCR1B & B11111000 | B00000001; // 31KHz //D11 & 12
  TCCR1A |= 0x30; // inversion
}

void loop()
{
  int duty = map(A0, 0, 1023, 0, 122);
  analogWrite(4,duty)
  analogWrite(13,255 - duty);
}

However, I need it to work with 62.5KHz. When I change the code to make it a 62.5KHz, we only got a dead-time on one end of the Squarewave but not the other, as shown below.

#define ANALOG_IN_PIN A0

void setup ()
{ 
  TCCR0B = TCCR0B & B11111000 | B00000001; // 62.5KHz //D4 & 13
  TCCR0A |= 0x30; // inversion
}

void loop()
{

  int duty = map(31000, 0, 1023, 0, 122);
  analogWrite(4,duty);
  analogWrite(13,255 - duty);
}

Can someone help me navigate this problem!

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Please show the scope output for the initial code.
Which Arduino/controller are you using?

Please fix that crap.

Why do you use timer 0 which is used for system timing?

Why do you expect that the previously working code will continue working after you apply weird modifications to it?

I do not have time to read code from a video, I will help somebody else with the time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.