PWM Expansion Coding for LEDS

Do you have a question on how to do something.
Ask in here.
Post Reply
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

PWM Expansion Coding for LEDS

Post by najluni15 »

Hi all,

I just built a new light and I am having trouble getting the lights to dim...They are super powerful so they have to be dimmed so I don't bleach anything.
I am using meanwell LDD drivers and they are connected to the Dimming Expansion Module. I was also told that the GND from the pwm expansion module had to be connected to the Vin- from my power supply, is this true?

Here is my code, please help if you can

// RA_111312_2128.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File:
#define DisplayImages
#define ATOSetup
#define DisplayLEDPWM
#define RelayExp
#define InstalledRelayExpansionModules 8
#define PWMEXPANSION
*/


#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <PH.h>
#include <ReefAngel.h>

byte x,y;
char text[10];

void DrawCustomMain()
{
// the graph is drawn/updated when we exit the main menu &
// when the parameters are saved
ReefAngel.LCD.Clear(BtnActiveColor,5,0,127,11);
ReefAngel.LCD.DrawText(DefaultBGColor,BtnActiveColor,30,3,"My Reef Angel");
ReefAngel.LCD.DrawDate(6, 122);
pingSerial();
ReefAngel.LCD.DrawMonitor(15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
pingSerial();
ReefAngel.LCD.Clear(DefaultFGColor,5,52,127,52);
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,30,55,"PWM Expansion");
x=15;
y=68;
for (int a=0;a<6;a++)
{
if (a>2) x=75;
if (a==3) y=68;
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :");
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a);
ConvertNumToString(text, ReefAngel.PWM.GetChannelValue(a), 1);
strcat(text," ");
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,text);
y+=10;
}
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 103, TempRelay);
}

void DrawCustomGraph()
{
}



void setup()
{
ReefAngel.Init(); //Initialize controller
ReefAngel.AddDateTimeMenu();
ReefAngel.PHMin=298;// 298=PH7.0
ReefAngel.PHMax=580;// 580=PH10.0
ReefAngel.FeedingModePorts = Port1Bit |Port2Bit | Port4Bit | Port5Bit | Port6Bit;
ReefAngel.WaterChangePorts = Port1Bit|Port2Bit | Port4Bit | Port5Bit |Port6Bit | Port7Bit;
ReefAngel.LightsOnPorts = 0;

// Ports that are always on
ReefAngel.Relay.On(Port2);
ReefAngel.Relay.On(Port4);
ReefAngel.Relay.On(Port5);
ReefAngel.Relay.On(Port6);
}

void loop()
{

ReefAngel.PWM.SetChannel(1,TunzeLongPulse(30,100,10,false));
ReefAngel.PWM.SetChannel(0,TunzeLongPulse(30,100,10,true));
if (hour()<20 && hour ()<8)
ReefAngel.PWM.SetChannel(0,(30));
ReefAngel.PWM.SetChannel (1,(30));
ReefAngel.PWM.SetChannel(2,PWMSlope(11,00,22,00,0,50,180,0));
ReefAngel.PWM.SetChannel(3,PWMSlope(11,30,21,30,0,75,180,0));
ReefAngel.PWM.SetChannel(4,PWMSlope(11,30,21,30,0,75,180,0));
ReefAngel.PWM.SetChannel(5,PWMSlope(11,30,21,30,0,75,180,0));

ReefAngel.StandardLights(Port1,8,0,22,0);
ReefAngel.StandardHeater(Port3,778,782);
ReefAngel.StandardATO(Port7,15);
ReefAngel.StandardLights(Port8,21,0,8,0);
ReefAngel.PWM.SetDaylight(PWMSlope(11,30,21,30,0,50,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(11,0,22,30,0,100,180,0));
ReefAngel.Portal("najluni15");
ReefAngel.ShowInterface();
}


byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
byte tspeed=0;
PulseMinSpeed=constrain(PulseMinSpeed,0,100);
PulseMaxSpeed=constrain(PulseMaxSpeed,0,100);
tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
if (PulseSync)
return tspeed;
else
return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by rimai »

Did you check the voltage on the expansion ports?
According to your code, you should have about 3V on channel 0 and 1.
Roberto.
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

I did not check voltage....The tunze pumps that are on channel 0-1 are analog and they are reving up and down as they are supposed to. Channel 2-5 are pwm.
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

Hi Roberto

After doing some investigative work I am wondering if it has to do with my ground. I have two tunze pumps plugged into the dimming expansion with a shared ground reference in port 6.

I then have 5 ldd drivers using channels 2-5 and using the ground reference in port 7 which is connected to the vin- of the power supply.

Could the problem be that I have two ground references? And if so how can I fix that
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by rimai »

The last 3 pins on the right-most side of the connector are all the same ground reference.
They are all tied together.
Roberto.
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

So would I be causing any problems if I have the Tunze Pumps and the LED Drivers connected to the same ground reference?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by rimai »

I doubt it.
Roberto.
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

How would I go about checking the voltage?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by rimai »

multimeter
Roberto.
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

Thanks...good point
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

After testing with the multimeter (assuming I did it right) it came out at around 1.5 v.....advise?
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

Also I just noticed my tunze pumps are not cycling speeds
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by rimai »

ReefAngel.PWM.SetChannel(0,(30));
ReefAngel.PWM.SetChannel (1,(30));
This tells me that the tunzes are set to 30% constant.
1.5V is 15%. What is that you see in the screen?
Roberto.
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

I edited my code a little. I took out the constant speed in the evening since it didn't work.
So now they alternative from 30-100%.
When I look at the reef angel head unit it shows that the pwm is in fact supposed to be switching back and forth, but I don't believe they actually are. I put my hand in front of the pump and couldn't tell a difference. They used to have a noticeable difference. I also made sure the controller cable for the pumps were fully plugged in. The head unit also shows the light dim percentages, but they are all on full bright I think...They don't change when I change the values and upload code

// RA_111312_2128.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File:
#define DisplayImages
#define ATOSetup
#define DisplayLEDPWM
#define RelayExp
#define InstalledRelayExpansionModules 8
#define PWMEXPANSION
*/


#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <PH.h>
#include <ReefAngel.h>

byte x,y;
char text[10];

void DrawCustomMain()
{
// the graph is drawn/updated when we exit the main menu &
// when the parameters are saved
ReefAngel.LCD.Clear(BtnActiveColor,5,0,127,11);
ReefAngel.LCD.DrawText(DefaultBGColor,BtnActiveColor,30,3,"My Reef Angel");
ReefAngel.LCD.DrawDate(6, 122);
pingSerial();
ReefAngel.LCD.DrawMonitor(15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
pingSerial();
ReefAngel.LCD.Clear(DefaultFGColor,5,52,127,52);
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,30,55,"PWM Expansion");
x=15;
y=68;
for (int a=0;a<6;a++)
{
if (a>2) x=75;
if (a==3) y=68;
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :");
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a);
ConvertNumToString(text, ReefAngel.PWM.GetChannelValue(a), 1);
strcat(text," ");
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,text);
y+=10;
}
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 103, TempRelay);
}

void DrawCustomGraph()
{
}



void setup()
{
ReefAngel.Init(); //Initialize controller
ReefAngel.AddDateTimeMenu();
ReefAngel.PHMin=298;// 298=PH7.0
ReefAngel.PHMax=580;// 580=PH10.0
ReefAngel.FeedingModePorts = Port1Bit |Port2Bit | Port4Bit | Port5Bit | Port6Bit;
ReefAngel.WaterChangePorts = Port1Bit|Port2Bit | Port4Bit | Port5Bit |Port6Bit | Port7Bit;
ReefAngel.LightsOnPorts = 0;

// Ports that are always on
ReefAngel.Relay.On(Port2);
ReefAngel.Relay.On(Port4);
ReefAngel.Relay.On(Port5);
ReefAngel.Relay.On(Port6);
}

void loop()
{

ReefAngel.PWM.SetChannel(1,TunzeLongPulse(30,100,10,false));
ReefAngel.PWM.SetChannel(0,TunzeLongPulse(30,100,10,true));
ReefAngel.PWM.SetChannel(2,PWMSlope(11,00,22,00,0,70,180,0));
ReefAngel.PWM.SetChannel(3,PWMSlope(11,30,21,30,0,60,180,0));
ReefAngel.PWM.SetChannel(4,PWMSlope(11,30,21,30,0,60,180,0));
ReefAngel.PWM.SetChannel(5,PWMSlope(11,30,21,30,0,60,180,0));

ReefAngel.StandardLights(Port1,8,0,22,0);
ReefAngel.StandardHeater(Port3,778,782);
ReefAngel.StandardATO(Port7,15);
ReefAngel.StandardLights(Port8,21,0,8,0);
ReefAngel.Portal("najluni15");
ReefAngel.ShowInterface();
}


byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
byte tspeed=0;
PulseMinSpeed=constrain(PulseMinSpeed,0,100);
PulseMaxSpeed=constrain(PulseMaxSpeed,0,100);
tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
if (PulseSync)
return tspeed;
else
return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}
najluni15
Posts: 60
Joined: Sat Mar 10, 2012 6:47 pm

Re: PWM Expansion Coding for LEDS

Post by najluni15 »

Ok...tested again...When it is on 30% it is at 3, when it is at 100% it is at around 9.5V so apparently it is working

Also, the multimeter is reading correct for the lights.....

Thank you!
Post Reply