[ SOLVED ] PWM pins and LDD-700H drivers

Hi. I am making a fish tank light unit and have four Meanwell LDD-700H drivers on a PCB made for this purpose. I have a separate 48v 300w PSU going to that PCB to run the drivers and LEDS, and I have the dimmer pin on the drivers running to PWM pins 8,9,10 and 11 on my arduino mega.

In a nut shell I have four different light modes, lunar/low sun/midsun/high sun, each with their own levels for all four channels.

I have noticed during my testing phase that when three channels are on, everything is fine, but as soon as the fourth is introduced, they all start to dim down.

Why does it do this? I am thinking its because the Mega is trying to put out (for example) 4v to each dimmer channel and obviously doesn't have enough power to send 4v out to all4 channels. However, I have tried powering the mega with a separate 12v 700mA plug and it doesn't make any difference at all.

Thanks,
Steve

If you think a copy of the sketch would help, let me know and I'll attach.

Why does it do this?

Either your software has a flaw, or your hardware does. You haven't posted the software, and the hardware description was rather vague (no schematic).

I am thinking its because the Mega is trying to put out (for example) 4v to each dimmer channel and obviously doesn't have enough power to send 4v out to all4 channels.

It does IF the channels are not sucking more power than the Arduino can supply.

Hi.

This is the board that the drivers are run on.

This is the data sheet for the actual drivers.

And the sketch is attached. (it is looooong and I am new to this so it will not be written in the best and cleanest way.)

Hope this info might help.
Thanks,
Steve

Complete_build_v2.ino (234 KB)

You do have a schematic or connection diagram, right? It's just easier to verify the hardware at this point than to wade through 234 kb of code.

Actually, have you verified the sketch by running it in a test circuit (just running into small LEDs, instead of the power setup)?

At the moment I only have pins 8,9,10 and 11 connected to the led driver PCB and a Tiny RTC, thats it. Do you want a wiring diagram to show that?

No I have not tested it with smaller less as I assume it will be the same principle and the same occurrence.

EEPROM.read() returns a byte. EEPROM.write() stores a byte. It makes no sense at all to call EEPROM.write() and pass it a float. It makes no sense to store the value read from EEPROM in a float.

If the data fits in a byte, pissing away three more using a float makes no sense.

Your RGBW struct needs to be reworked.

You need to be using more arrays and more functions. Read and/or write related data in EEPROM using a function. getTimes() and saveTimes(). getColors() and setColors().

That way, we can look at getTimes() and see that it is, or is not, doing reasonable things, and then forget about it. We see a call to getTimes(), and we know that it works.

A reasonable amount of white space between blocks of code is one line. More than that is annoying.

Consistent indenting is good. Yours is not. Tools + Auto Format will deal with that.

Sometimes comments are good. Sometimes, you really need a users manual. Guess which case this is.

A big block of comments that says FEEDING MENU, followed by the menu4() function makes me want to come kick your ass. What's wrong with skipping the comments and simply calling the function feedingMenu()?

 if (menu == 7)

You should do some research involving enums. if(menu == FEEDING) or if(menu == LOWSUN) makes so much more sense.

Having ONE function to turn power pins on or off that takes a pin number and a state makes more sense than 16 functions that do nearly identical things.

Having a way to look up the EEPROM address for write the state of the nth pin makes more sense than hardcoding the addresses.

         if (ch3bar >= 5) { myGLCD.fillRect(180,171,200,176); }
          if (ch3bar >= 10) { myGLCD.fillRect(180,166,200,176); }
          if (ch3bar >= 15) { myGLCD.fillRect(180,161,200,176); }
          if (ch3bar >= 20) { myGLCD.fillRect(180,156,200,176); }
          if (ch3bar >= 25) { myGLCD.fillRect(180,151,200,176); }
          if (ch3bar >= 30) { myGLCD.fillRect(180,146,200,176); }
          if (ch3bar >= 35) { myGLCD.fillRect(180,141,200,176); }
          if (ch3bar >= 40) { myGLCD.fillRect(180,136,200,176); }
          if (ch3bar >= 45) { myGLCD.fillRect(180,131,200,176); }
          if (ch3bar >= 50) { myGLCD.fillRect(180,126,200,176); }
          if (ch3bar >= 55) { myGLCD.fillRect(180,121,200,176); }
          if (ch3bar >= 60) { myGLCD.fillRect(180,116,200,176); }
          if (ch3bar >= 65) { myGLCD.fillRect(180,111,200,176); }
          if (ch3bar >= 70) { myGLCD.fillRect(180,106,200,176); }
          if (ch3bar >= 75) { myGLCD.fillRect(180,101,200,176); }
          if (ch3bar >= 80) { myGLCD.fillRect(180,96,200,176); }
          if (ch3bar >= 85) { myGLCD.fillRect(180,91,200,176); }
          if (ch3bar >= 90) { myGLCD.fillRect(180,86,200,176); }
          if (ch3bar >= 95) { myGLCD.fillRect(180,81,200,176); }
          if (ch3bar >= 99) { myGLCD.fillRect(180,76,200,176); }

A little modulo arithmetic, and this could be one line of code.

Anyway, that's way too much code to determine whether you have a software problem or a hardware problem.

void loop()
{
    analogWrite(pin1, 250);
    delay(1000);
    analogWrite(pin2, 250);
    delay(1000);
    analogWrite(pin3, 250);
    delay(1000);
    analogWrite(pin4, 250);
    delay(10000);
}

If the first light comes on bright, and the second one does, and the third one does, but the 4th one causes all the lights to dim, then switch the order around. If turning the 4th pin on, regardless of which one is 4th, then you have a hardware problem.

Stevelondon:
At the moment I only have pins 8,9,10 and 11 connected to the led driver PCB and a Tiny RTC, thats it. Do you want a wiring diagram to show that?

Yes, because I want to see your ground and power supply connections.

Stevelondon:
No I have not tested it with smaller less as I assume it will be the same principle and the same occurrence.

Well, that assumption is not a good troubleshooting philosophy.

Hi Paul. Thanks for your comments. By all means come round and kick my ass, as long as you sort my code out afterwards it's cool with me.

I know how frustrating it is when someone asks a question and the answer is pretty obvious to you but they don't have a clue. But please bare in mind that this is the first time I have ever tried to do something on an Arduino and more to the point, the first time I have ever seen C++ coding. So please bare with me. I know it's not the best or cleanest way to code it, but as long as it works, which the majority does, I was going to complete it and then rework each individual bit to tidy it up.

The comments at just to help me understand it and things like the menu7 was because I was taught a basic menu and built from there, but my plan is to tidy it all up.

Great idea about the code you put in to test each channel, I will do that when I get home and see if it's what I thought it was. If it works fine, it must be something else.

Overall though, I don't think I've done too bad for a complete novice. Just wished people would take that on board when replying to threads.

Cheers. Steve.

The idea is divide and conquer. If you can split the system, and test the halves, and one half is bad, you have reduced the difficulty of finding the problem by two. Rinse and repeat until the problem is solved..

Or even better, use the constructive version. Build everything in self contained modules, specify the interfaces carefully and explicitly. Then test them so you know they work. Assemble them together. Only rarely, do things not work that way.

Overall though, I don't think I've done too bad for a complete novice. Just wished people would take that on board when replying to threads.

I did. If you were an experienced programmer, I'd have been rougher. 8)

PaulS:
I did. If you were an experienced programmer, I'd have been rougher. 8)

No I weren't talking about you mate. At least you gave an actual constructive example of what to try. Unfortunately many others on here don't. Will run that check tonight and see how it goes.

Right, found the problem. I ran various tests and come come to the conclusion that it was what I thought and that the Arduino is not capable of sending enough through all 4 PWM channels when powered simultaneously.
Here are my results with multimeter across the wpm output voltage...

With 5v USB power...
1 channel @ PWM 250 = 4.02v
2 channel @ PWM 250 = 3.72v
3 channel @ PWM 250 = 3.16v
4 channel @ PWM 250 = 0.48v

With indépendant 12v power supply...
1 channel @ PWM 250 = 4.28v
2 channel @ PWM 250 = 3.97v
3 channel @ PWM 250 = 3.36v
4 channel @ PWM 250 = 0.48v

Clearly there is a dip on each and a massive dip when all 4 are on. But this is also true when the values are set at PWM 100.

Would you agree that this is going to be that the Arduino simply cannot power 4 separate PWM channels at the same time? And if so, do you know of a work around?

Would you agree that this is going to be that the Arduino simply cannot power 4 separate PWM channels at the same time?

In general, that is not true. In YOUR circuit, I have no reason to doubt that it is true.

do you know of a work around?

Redesign your circuit so it doesn't draw so much current (which is what you really need to be measuring, not voltage).

PaulS:
Redesign your circuit so it doesn't draw so much current (which is what you really need to be measuring, not voltage).

Do you mean the circuit or the sketch? The circuit seems ridiculously simple. Its just 4 PWM pins being used going to the drivers and nothing else being drawn from it. How can I redesign that to not draw any more current?

Stevelondon:
Do you mean the circuit or the sketch? The circuit seems ridiculously simple. Its just 4 PWM pins being used going to the drivers and nothing else being drawn from it. How can I redesign that to not draw any more current?

What happens when you disconnect the drivers?

Probably not much. The LEDs will go out? Lol.

What exactly do you mean? Think I'm missing the point?

Stevelondon:
Probably not much. The LEDs will go out? Lol.

What exactly do you mean? Think I'm missing the point?

No more or less than what I say. Disconnect the power circuit and repeat the measurements, this time on the unloaded Arduino pins.

Think I know where I went wrong. The voltage over the dim pin and Arduino ground stayed constant when not loaded with the drivers and even when they were.

I've just looked at a couple more diagrams and realised the one I followed was probably wrong. I only had the PWM pins going to the drivers and not the Arduino ground aswell. Gonna try that now.

Yes yes yes. It was that I didn't have the drivers grounded to the Arduino as well as to the PSU. the wiring diagram I was reading didn't have it conneted but after doing a bit more searching I found that others had it connected and hey presto, sorted.

Thanks for all your replies, albeit some of them sarcastic and condescending, but thank you anyway.