Inverted PWM

Hii.. Im just signed up here...
I need some help..

I want to make Driver Switching for mosfet using IR2110..
and the IR2110 needs 'High Input' and 'Low Input'..
and I use PWM to generate HIN and LIN..

I use "255-value" method like this:

int Freq = 9;
int Freq2 = 10;
int potenciometer = A0;

void setup(){
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(A0,INPUT);
  
  Serial.begin(9600);
}

void loop(){
  int value = analogRead(potenciometer);
  int Freq_speed = value/4;
  int Freq_speed2 = 255 - value/4;
  analogWrite(Freq,Freq_speed);
  analogWrite(Freq2, Freq_speed2);
  
  Serial.println(Freq_speed);
}

but when using osiloscope, I got that they are not perfectly inverted.. (the screenshoot at the attachment)
I need something like:

      ___         ___
     |   |       |   |
_____|   |_______|   |______

_____     _______     ______
     |   |       |   |
     |___|       |___|

is there any other way for inverting the PWM

SDS00005.jpg

the screenshoot at the attachment

You seem to have forgotten something...

PaulS:
You seem to have forgotten something...

added

You need to make two changes to make this work:

void loop(){
  int value = analogRead(potenciometer);
  int Freq_speed = value/4;
  analogWrite(Freq,Freq_speed);
  analogWrite(Freq2, Freq_speed);  // same value for both
  TCCR1A |= bit (COM1A0);          // inverting mode
  Serial.println(Freq_speed);
}
  • Send the same value to both pins.
  • Set one of them to inverting mode output as shown

Now it works as expected.

Btw, I think for a lot of applications it's not necessary to drive both the Hi and the LOW side. Just fixing the LOW and PWM the HIGH will work as well. Only the load stays connected to the GND/LOW side.

thankyou..

this is what im looking for..

have a nice day

It looks like you need a minimum of 9.5V to get a logic 1 on those inputs. How are you doing that from the Arduino?

http://www.irf.com/product-info/datasheets/data/ir2110.pdf

In this case you print pin 9 and invert pin 10 , so can you tell me how i can print pin 11 and invert pin 3 please?

Do a similar thing to Timer 2. You know, reading the datasheet can be very helpful.

int Freq = 3;
int Freq2 = 11;
int potenciometer = A0;

void setup(){
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(A0,INPUT);
  
}

void loop(){
  int value = analogRead(potenciometer);
  int Freq_speed = value/4;
  analogWrite(Freq,Freq_speed);
  analogWrite(Freq2, Freq_speed);  // same value for both
  TCCR2A |= bit (COM2A0);          // inverting mode
}

Thanks for these great examples so far. I'm writing some code for a brushless motor controller and I have a couple of questions.

  1. Why is the line of code to enable inverting mode called after the analogWrite commands for both the inverted and regular pins? Wouldn't the inverting mode code want to be called first before the analogWrite lines?

  2. I am using an Arduino Uno with the Atmel 328P. What would each line of code look like for pins 5, 6 and 9 to make them have inverted PWM? Ie: The equivalent of " TCCR2A |= bit (COM2A0); //inverting mode " in your example.

  3. How would I write a line of code to restore the PWM of each pin back to non-inverted?

I'm trying to fix some bad behavior that the analogWrite function has when it is at 0 duty cycle, it calls digitalWrite instead.