Dc/DC Converter project - Arduino switches by itself when connected to circuit

Hi!

My project is to make a two quadrant DC/DC converter. For now, I am just trying to make the buck converter functionality work.

Circuit:
My circuit wiring is attached to the post.

I had to change the mosfet driver in favor of an easier one to solder (LM5107 of Texas), but the working principle is the same. The only difference is that the bootstrap diode D1 is integrated in the driver, so I removed it from my circuit.

Program:
I did the PWM programming on Arduino in advance, for both buck converter und boost converter mode.
I have two PWM output, pin10 and pin9, controlling respectively the high and low input of the mosfet driver. I never need both at the same time, and because of the initialization, the program goes directly in buck mode (PWM output at pin 10). To switch between using one pin or the other, I programmed a switch using interrupt on pins D2 and D3. If pin3 contacts ground, the device should go in boostmode, meaning I get a PWM out of pin 9 in the bottom input of the mosfet driver. If pin2 contacts the ground, then the buckmode is set, and there is a PWM output at pin 10 aand none at pin 9.
Here is the code:

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

const int ModeSwitchHigh = 2;
const int ModeSwitchLow = 3;
const int LowSideMos = 9;
const int HighSideMos = 10;
volatile boolean IsCharging = true;  //True -> Buck converter mode, using only High-side Mosfet. False -> Boost converter mode, using only Low-Side Mosfet
volatile boolean TimerSet = false;


void setup() {
 pinMode(ModeSwitchHigh,INPUT_PULLUP);
 pinMode(ModeSwitchLow,INPUT_PULLUP);
 pinMode(HighSideMos, OUTPUT);
 pinMode(LowSideMos, OUTPUT);

attachInterrupt(digitalPinToInterrupt(ModeSwitchHigh), Buckmode, FALLING);    //Buckconverter mode, Battery loading, High-Side Mosfet
attachInterrupt(digitalPinToInterrupt(ModeSwitchLow), Boostmode, FALLING);    //Boostconverter mode, Battery unloading, Low-Side Mosfet 

//InitTimer1
 TCNT1  = 0;
 TCCR1A = 0; 
 TCCR1B = 0; 
  
// set to mode 14 fast pwm.
// TCCR1B
// Bit                 7      6      5       4     3      2      1      0
// Bit Name          COM1A1 COM1A0 COM1B1 COM1B0 -----  ----- WGM11  WGM10
// Initial Value       0      0      0       0     0      0      0      0
// changed to          1      0      1       0     0      0      1      0

 TCCR1A = B10100010;      
   
// TCCR1B
// Bit             7     6      5       4       3      2        1       0
// Bit Name      ICNC1  ICES1 ----   WGM13    WGM12    CS12    CS11     CS10
// Initial Value    0     0     0        0       0      0        0       0
// changed to       0     0     0       1       1      0        0       1
 
 TCCR1B = B00011001;
  
ICR1 = 159;   //Set Top Value, -> frequency 100 kHz 16 MHz/100kHz-1, 16 MHz internal clock
OCR1A = 50; // init Wert 5 mikro sek
OCR1B = 50;  
 }

void loop() {
//Buckmode  
 if ((IsCharging == true)&&(TimerSet==false)) {
 // Here Pin 9 stoppen, Pin 10 enable   
 TCCR1A &= ~(1 << COM1A1);
 TCCR1A |= (1 << COM1B1);
 digitalWrite(LowSideMos, LOW);
 OCR1B = 100; 
 TimerSet=true;
}
 //Boostmode
 else if ((IsCharging == false)&&(TimerSet==false)){
 TCCR1A &= ~(1 << COM1B1);
 TCCR1A |= (1 << COM1A1);
 digitalWrite(HighSideMos, LOW);
 OCR1A = 70; 
 TimerSet = true;
  }
}

void Buckmode(){
 IsCharging = true;
 TimerSet = false;  
}

void Boostmode(){
 IsCharging = false;
 TimerSet = false;
}

I tested the program on my Arduino nano as standalone (USB powered), and both the PWm outputs as well as the switching function were working very properly.

Problem:
Now, as already said, I’m currently trying to test solely the buck converter mode. As the program directly begins in buck mode, I do not need the switching function yet, at all. There is still absolutely nothing connected to pin 2 an 3, so they shouldn’t do anything, and I should only have a nice PWM at my pin10 output.
But I don’t.
Each time I tried to make the buck converter functions, the Arduino would directly switch the output PWM to pin9. The compare value is the one I set for this PWM output in the main loop (boost converter mode) of the program, not in the initialization, so it really seems that the Arduino had switched by itself.

Tests:
I tried to swap the connections of pin 9 and pin 10, to try and get some PWM at the high input of my mosfet Driver, even with this bug, but then the error doesn’t appear anymore, my PWM is nicely at pin 10, and I get nothing at pin 9 now connected with the top input of the driver.
If I actively switch between the mode by making a contact between gnd and pin 3 or 2, the PWM at the pin connected to the low input of the driver stops (which it should), but I do not get any PWM from the other pin, and then I cannot get any PWM from either of the pins anymore.

In short:
Essentially, whatever I try, I cannot get a PWM in the high Input of mosfet driver. The PWM mode will be either switched, or I won’t get any PWM at all anymore.

I did not find many helpful ressources in internet to this weird problem. Some people had self-switching arduinos problem because there was no pull up in the switch input, but I think this is solved by the
“pinMode(ModeSwitchHigh,INPUT_PULLUP);
pinMode(ModeSwitchLow,INPUT_PULLUP);" lines.

What’s more, it seems the self-switching is only a consequence of whatever problem there is, that prevents the high input of the mosfet driver to get a PWM.

When working on the code, I got help with a problem here, though I’m not sure whether this topic will be of any help.

Hi,
OPs original circuit.
buck converter.png

Thanks… Tom… :slight_smile:

Hi,
I think you will find D1 needs to be a Schottky Doide, not 1N4004.
buck11.jpg

Tom... :slight_smile:

buck11.jpg

Hi,

I had to change the mosfet driver in favor of an easier one to solder (LM5107 of Texas), but the working principle is the same. The only difference is that the bootstrap diode D1 is integrated in the driver, so I removed it from my circuit.

Well you had better post that circuit, cos the one you posted is not relevant.

Tom.. >:( >:( >:(

Right, I corrected the diagram, here is the up-to-date version.

Hi,

I did some further tests to try and determine the problem.

First, I reduced the code to a strict to just produce one PWM at pin9

Here is the code:

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

const int LowSideMos = 9;
const int HighSideMos = 10;

void setup() {
  pinMode(LowSideMos, OUTPUT);
  pinMode(HighSideMos, OUTPUT);
  digitalwrite(HighSideMos, LOW);

  //InitTimer1
  TCNT1  = 0;
  TCCR1A = 0;
  TCCR1B = 0;

  // set to mode 14 fast pwm.
  // TCCR1B
  // Bit                 7      6      5       4     3      2      1      0
  // Bit Name          COM1A1 COM1A0 COM1B1 COM1B0 -----  ----- WGM11  WGM10
  // Initial Value       0      0      0       0     0      0      0      0
  // changed to          1      0      1       0     0      0      1      0

  TCCR1A = B10000010;

  // TCCR1B
  // Bit             7     6      5       4       3      2        1       0
  // Bit Name      ICNC1  ICES1 ----   WGM13    WGM12    CS12    CS11     CS10
  // Initial Value    0     0     0        0       0      0        0       0
  // changed to       0     0     0       1       1      0        0       1

  TCCR1B = B00011001;

  ICR1 = 159;   //Set Top Value, -> frequency 100 kHz 16 MHz/100kHz-1, 16 MHz internal clock
  OCR1A = 80; // init Wert 5 mikro sek
  OCR1B = 80;
}

void loop() {
}

Results:

If I try to link the PWM output with High Input of the mosfet driver, I get

  • a very quick signal that is almost immediately set to null (too quick for me to print with the osco)
  • some sort of disturbance at the same time at most other pins (didn’t check them all), of variable amplitude, between 1 and 5 V maybe. I think it could explain my former self switching problem.
  • And then no signal at all until I turn the power supply off and on again. (Then, same problem)

If I try to link the PWM output of my arduino with the Low Input of the mosfet driver, then:
-everything is working properly, the PWM is steady, the mosfet driver drives the low output.
-there is a bit of sync noise at the other pins but nothing comparable to what I got in the first case

Also somewhere in the middle of this, I must have damaged my Arduino because I cannot load programs on it anymore. I checked with the blink program. The error is avrdude: ser_open(): can’t open device.
It’s still producing the PWM at pin 9 everytime I power it though.

Hi,
Please do not go back and edit the main parts of your posts, it make them dis-continuous and confusing to anyone later wanting to use this thread.

Tom.... :slight_smile:

Right, I'm sorry, I just worried that people would keep downloading the wrong circuit so I put the updated one instead.

I solved the loading error of the arduino, it was actually a simple USB cable problem. (My mini USB - USB adapter is a bit weird, with a second USB end, and I used the wrong one)

Hi,
What duty cycle are you trying to produce?
I would suggest a very low 10%, to see what you get out.

You have no feedback to regulate the PWM duty cycle so you have no dynamic control.

What output voltage do you want, especially with a 0R5 load?

What are you using as a power supply?

Thanks.. Tom... :slight_smile:

Thank you for your suggestions,

I am using a labor power supply, with 9 V and a current limitation of 2 A (The mosfet driver output are supposed to have an output current about 1,4 A max). On the former tests, there were barely10 mA used, as long as the PWM have worked.

I tried with a duty cycle of 10% as you suggested. (OCR1A = 16, Ton = 1us, Toff = 10 us)
I tried linking the PWM to the High Input, and to the Low input, with the same result in both cases:

A continuous voltage at the pins (not only the PWM pin, other pins too) of about 4 V. The current goes up against the limitation of 2 A. Arduino still alive, but I did not try extensively, worried about overpowering it.

I don't understand what you say about the dynamic control. Is something missing in the program?

With a duty cycle of 10% I should theoretically get an output voltage of 0,1 * 9 V = 0.9 V out of the converter. That is, if I manage to get the PWM in the High Input of the mosfet driver.

Hi,
I think you had better get your download problem fixed first;
Can you download now?
Have you selected the correct COM port?

You have got ALL the gnds connected together?

Thanks.. Tom... :slight_smile:

Yes, my download problem is solved, I mentioned it in post 7. It was a simple cable problem.

And yes, all the GND are connected together. This precise error was the death of my first arduino last week, but I corrected it and double checked all the rest.

Also, I forgot to ask, what do you mean by OR5 load?

Hi,
I hope you haven’t got your circuit connected as in your diagram?
Buck converter LM5107what.jpg

It should resemble this.
buckedit.jpg
Tom… :slight_smile:

Where did you find this diagram ? I couldn't find it or anything alike in the datasheet. I helped myself with the pin indications of the datasheet.

I don't have the capacitor between the high mosfet drain and source. what is it for and how big should it be (or how do I calculate its value)?

I also don't have the gate resistor, because I calculated with the method I found here that the internal gate resistor of the mosfets were enough.
But I just noticed a stupid mistake I made using the method, so it's just wrong. I definitely need those resistors

I don't have the antiparallel diodes to the gate resistors either, what are they for?

I'm going to fix my circuit and test it right away.

Murmeltier:
Where did you find this diagram ? I couldn't find it or anything alike in the datasheet. I helped myself with the pin indications of the datasheet.

I googled LM5107 data

Can't attach it too big.

Tom.. :slight_smile:

Murmeltier:
Where did you find this diagram ? I couldn't find it or anything alike in the datasheet. I helped myself with the pin indications of the datasheet.

I don't have the capacitor between the high mosfet drain and source. what is it for and how big should it be (or how do I calculate its value)?

Ignore that, its just the class-D output load which isn't relevant.

I also don't have the gate resistor, because I calculated with the method I found here that the internal gate resistor of the mosfets were enough.
But I just noticed a stupid mistake I made using the method, so it's just wrong. I definitely need those

I don't have the antiparallel diodes to the gate resistors either, what are they for?

No, you don't need resistors, the output impedance of the driver will do the job for you. The diodes are a way
of having fast switch-off and slow switch-on, assuming you wanted slow switch on in the first place
(I've never needed that!)

I'm going to fix my circuit and test it right away.

Its OK to just drive the gates directly from the chip, that gives the best switching efficiency (although can
produce more EMI/noise). Fewer parts simplifies things. The driver chip must have good decoupling though,
10uF ceramic or so directly across its supply is probably going to work nicely.

This driver chip has no protection against shoot-through, note, so its up to you to ensure you allow
enough dead-time.

And the bootstapping method means the hi input must be parked low, never parked high (which for PWM
means never going above about 95% duty cycle).

Well, I didn't have a 10uF ceramic so I put a 15uF Elko instead.

I also added 8 Ohm each gate, basing on the mosfet driver datasheet.

Still not working.

If the PWM goes in the Low Input of the driver, it's working alright, although not as cleanly as before.

But if the PWM output and the High Input of the driver are linked, still nothing beside the occasional quick signal distortion after a few seconds

Hi,

But if the PWM output and the High Input of the driver are linked, still nothing beside the occasional quick signal distortion after a few seconds

Do you have an oscilloscope?
Do you have a DMM?

Can you post an up to date circuit diagram please, and a picture of your project?

Thanks.. Tom.. :slight_smile:

I have both an Oscilloscope and a DMM.

Here are a the updated circuit as well as pictures of it.

The two mosfets are hidden by the cooling element.

I also tried the whole thing with the anti parallel diode to the gate resistors, and the capacitor between the drain of the High Side mosfet and the inductor just to be sure, but I didn’t get any different result.
Thanks to MarkT’s explanations, I’m pretty sure I do not need them, so they’re off again.



I replace the output resistor by a 10k Ohm one, and was finally able to get a signal in and out the mosfet driver (high side). Here it is:

https://img15.hostingpics.net/pics/436000ens10hz108.png

https://img15.hostingpics.net/pics/527270ens10hz109.png

In both pictures, the yellow signal (ch 1) is the output PWM of the mosfet.
The pink signal (ch 2) is the high output of the mosfet driver.

The only difference between the pictures is the time resolution (bottom right corner of each pictures). The output of the circuit, at the 10k resistor, looks exactly like the output of the mosfet dirver (pink line)

So my three questions now are:

  • Why isn’t the output of the mosfet a PWM to drive the mosfet?

-Why isn’t the output of the circuit a continuous voltage? (because of the weird driving maybe? Or is it a capacitor problem? )

My aim is to load a battery with this circuit, with current up to 10 A. The internal resistance of a battery is about 0,5 Ohm, maybe 1 Ohm. I cannot keep the 10k Ohm resistor.
So:

-why isn’t the mosfet driver working with such a small load? (or how do I make it work)

Here is the circuit once more. Only changed thing is the resistor value on the right.