Code deadtime pwm arduinoyUNO

Hi I'm making project using arduino to produce pwm from two output pin of my Arduino uno to the gate of two MOSFETs, so I'm stopped because of difficulty on the code this is my code to produce pwm 20KHZ.


#include <TimerOne.h>

const int P1 = 9;
const int P2 = 10;

void setup(void)
{
   Timer1.initialize(50); // 50 us = 20 kHz
   Serial.begin(9600);
}

void loop(void)
{
   Timer1.pwm(P1, (341));
      Timer1.pwm(P2, (682));
         
}
// 341, 682  is duty cycle Full = 1023

The problem i want to add code to this to make deadtime so that the two MOSFETs not work together at the same time either in off or on.

Please any one can make this happen.

Set the timer to Phase and Frequency Correct PWM Mode.

I reverse or flip one wave or pwm now i have to make shift by for example half micro to make deadtime how i make this happen

Adjust the timer prescaler for a fast enough clock rate. With 1:1 and a 16 MHz clock set the OCRx 8 apart for 16/8 MHz or 1/2 µs.

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