LED Lights "Pulsing" with PWM Module / Slope

Expansion modules and attachments
Post Reply
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

LED Lights "Pulsing" with PWM Module / Slope

Post by TanksNStuff »

I've got 2 LED fixtures using a total of 4 meanwell ELN-60-48D drivers, and my PWM Module was modified by Roberto to send analog signals in lieu of PWM signals. I'm using channels 0-3 on the PWM module (0 & 1 for blues/actinics, 2 & 3 for whites/daylights).

When I first received the modified module, I hooked up my lights and loaded some test code that allowed me to manually select an intensity % for each channel. It seemed to work flawlessly. Well, my lights would flicker briefly then power off at 9% which is typical for these drivers (10% was fine for all channels) but other than that the lights worked at any % from 10-100.

After uploading new coding with PWM slope function to control ramping up/down my LED's... I now get this "pulsing" affect on all channels while the slope is either ramping up or ramping down. It appears to be fine in between the ramping durations, so I'm thinking there might be something wrong with how this is working.

When I say it's "pulsing" I mean that it's a tiny increase in brightness for a split second, at about every 1-2 second intervals. IE. if the channel is at 10%, about every second or two (too fast to actully time it) the lights will appear to brighten up to about 15% (just a guess based on appearance) and then back to 10%. It's like a heart beat on a heart-rate monitor. Sorry, best way I can explain it.

When I look at my controller head unit, my display seems to refresh at almost the same instance as the lights pulsing. So, my gut feeling is that the pulse is happening on every round of the loop section. Could it be that the slope calculation is causing some confusion to the drivers?

Here's my current .ino file

Code: Select all

// Autogenerated file by RAGen (v1.2.1.158), (03/08/2012 22:54)
// RA_030812_2254.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define DisplayImages
#define DateTimeSetup
#define DirectTempSensor
#define DisplayLEDPWM
#define wifi
#define StandardLightSetup
#define SaveRelayState
#define RelayExp
#define InstalledRelayExpansionModules 1
#define WDT
#define PWMEXPANSION
#define CUSTOM_MAIN
#define RFEXPANSION
#define FONT_8x16
#define NUMBERS_8x16
*/

#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 <RF.h>
#include <ReefAngel.h>
#include <avr/wdt.h>

//*********************************************************************************************************************************
//--------------------------------------------------- Start of Global Variables ---------------------------------------------------
// This is just how we are going to reference the PWM expansion ports within the code.
// You can change the labels if you would like, just as long as they are changed all throughout the code too.
#define LEDPWM0 0
#define LEDPWM1 1
#define LEDPWM2 2
#define LEDPWM3 3
#define LEDPWM4 4
#define LEDPWM5 5

// Initial values to all 6 PWM channels at startup. They will always be 0.
byte PWMChannel[]={
0,0,0,0,0,0};

// Globals Needed for Params on Custom Main
byte x,y;
char text[10];
int v;

// Globals Needed for RF Mode on Custom Main
byte vtechmode;
boolean bFeeding=false;
//------------------------------------------------------ End of Global Variables --------------------------------------------------
//*********************************************************************************************************************************
//---------------------------------------------Custom Main for PWM Expansion Module------------------------------------------------

void DrawCustomMain()
{
        //Top Banner
        ReefAngel.LCD.DrawText(COLOR_BLACK, COLOR_SKYBLUE, 9, 2, " George's 75G Reef "); 
        
        // Display T1 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,8,14,"Tank");
  
        // Display the T1 Temp Value
        char text[7];
        ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
        ReefAngel.LCD.Clear(255, 4, 21, 37, 37);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 4, 24, text, Num8x16);
        pingSerial();

        // Display the T2 Header Text
        ReefAngel.LCD.DrawText(COLOR_CRIMSON,255,52,14,"Canopy");
  
        // Display the T2 Temp Value
        ConvertNumToString(text, ReefAngel.Params.Temp[T2_PROBE], 10);
        ReefAngel.LCD.Clear(255, 52, 21, 75, 37);
        ReefAngel.LCD.DrawLargeText(COLOR_CRIMSON, 255, 52, 24, text, Num8x16);
        pingSerial();

        // Display pH Header Text
        ReefAngel.LCD.DrawText(COLOR_INDIGO,255,108,14,"pH");
  
        // Display pH Value
        ConvertNumToString(text, ReefAngel.Params.PH, 100);
        ReefAngel.LCD.Clear(255, 94, 21, 106, 37);
        ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 94, 24, text, Num8x16);
        pingSerial();
        
        // Display Vortech MP40wES Mode Header Text
        ReefAngel.LCD.Clear(DefaultFGColor,5,39,127,39);
        ReefAngel.LCD.DrawText(0,255,18,42,"EcoSmart Vortech");

        // Display EcoSmart Mode Value      
        ReefAngel.LCD.Clear(255, 1, 49, 128, 64);
        if (vtechmode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,35,50,"Constant");
        else if(vtechmode == 1) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,42,50,"Lagoon");
        else if (vtechmode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,25,50,"Reef Crest");
        else if (vtechmode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,22,50,"Short Pulse");
        else if (vtechmode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,25,50,"Long Pulse");
        else if (vtechmode == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,8,50,"Nutrient Trnsp.");
        else if (vtechmode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,23,50,"Tidal Swell");
        else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,45,50,"Night");

        // Display PMW Expansion Channel Headers and % Values
        ReefAngel.LCD.Clear(DefaultFGColor,5,65,127,65);
        ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,31,68,"LED Dimming");
        x=15;
        y=78;
        for (int a=0;a<4;a++)
        {
          if (a>1) x=75;
          if (a==2) y=78;
          ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :");
          ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a);
          v = int(ReefAngel.PWM.GetChannelValue(a));
          // v = int(ReefAngel.PWM.GetChannelValue(a)/2.55);
          ConvertNumToString(text, v, 1);
          strcat(text,"  ");
          ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,text);
          y+=10;
        }
        pingSerial();
        
        // Display Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox(13, 97, TempRelay);
        pingSerial();
 
        // Display Expansion Relay Box 1
        TempRelay = ReefAngel.Relay.RelayDataE[0];
        TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
        TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
        ReefAngel.LCD.DrawOutletBox(13, 109, TempRelay);
        pingSerial();
        
        //Draw Date & Time
        ReefAngel.LCD.DrawDate(6, 123);
        pingSerial();
}

void DrawCustomGraph()  // Not Used
{
}
//------------------------------------------------------ End Custom Main ----------------------------------------------------------
//*********************************************************************************************************************************
//-------------------------------------------------------- Begin Setup ------------------------------------------------------------
void setup()
{
    ReefAngel.Init();  //Initialize controller

    ReefAngel.FeedingModePorts = Port1Bit;
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port6Bit | Port7Bit |Port8Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port4Bit;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port4Bit;

    // Ports that are always on
    ReefAngel.Relay.On(Port1);
    ReefAngel.Relay.On(Port3);
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
    ReefAngel.Relay.On(Port7);
    ReefAngel.Relay.On(Port8);
    ReefAngel.Relay.On(Box1_Port7);
    ReefAngel.Relay.On(Box1_Port8);
//--------------------------------------------------------- RF Module Setup -------------------------------------------------------
// This section commented out because it prevented RF Module from syncing with Vortech
/*    ReefAngel.RF.SetMode(Slave_Start,0,0);
    
    If you get a compile error similar to this:
    'class ReefAngelClass' has no member named 'RF'
    Please make sure that you enabled RF Expansion on your features file.
  
    Open RAGen and make sure you have RF Expansion checked under the Features tab.

    Or, you can manually edit the file.
    The file is located at "Documents\Arduino\libraries\ReefAngel_Features.h" file and has to include this line in it:
    #define RFEXPANSION  
    
    InternalMemory.RFMode_write(0);
    InternalMemory.RFSpeed_write(128);
    InternalMemory.RFDuration_write(10);
*/    
//------------------------------------------------------ End RF Module Setup ------------------------------------------------------  
}
//---------------------------------------------------------- End Setup ------------------------------------------------------------
//*********************************************************************************************************************************
//--------------------------------------------------------- Begin Loop ------------------------------------------------------------
void loop()
{
    // Specific functions
    ReefAngel.Refresh();  //WDT check
    ReefAngel.StandardLights(Box1_Port1); //Left Blue LEDs
    ReefAngel.StandardLights(Box1_Port2); //Right Blue LEDs
    ReefAngel.MHLights(Box1_Port3); //Left White LEDs
    ReefAngel.MHLights(Box1_Port4); //Right White LEDs
 
    ReefAngel.StandardHeater(Port2);
    ReefAngel.MoonLights(Box1_Port5); //Left Moonlight
    ReefAngel.MoonLights(Box1_Port6); //Right Moonlight
    ReefAngel.MoonLights(Port4); //Fuge light on when main lights are out
    ReefAngel.Portal("tanksnstuff");
    
//------------------------------------------------ Start PWM Expansion Code for Slope ----------------------------------------------
    //  Temporarily using Memory Locations from PWM Slope Actinic (for LEDPWM0 and LEDPWM1) and 
    //  PWM Slope Daylight (for LEDPWM2 and LEDPWM3) for the start, end, durations.
    //  Will change the start%, end%, duration of each to new memory locations for each channel when Curt provides libraries update.
    PWMChannel[LEDPWM0]=PWMSlope(
      InternalMemory.StdLightsOnHour_read(),
      InternalMemory.StdLightsOnMinute_read(),
      InternalMemory.StdLightsOffHour_read(),
      InternalMemory.StdLightsOffMinute_read(),
      InternalMemory.read(852),  // start %
      InternalMemory.read(853),  // end %
      InternalMemory.read(854),  // duration
      PWMChannel[LEDPWM0]);
      
    PWMChannel[LEDPWM1]=PWMChannel[LEDPWM0];

    PWMChannel[LEDPWM2]=PWMSlope(
      InternalMemory.MHOnHour_read(),
      InternalMemory.MHOnMinute_read(),
      InternalMemory.MHOffHour_read(),
      InternalMemory.MHOffMinute_read(),
      InternalMemory.read(849),  // start %
      InternalMemory.read(850),  // end %
      InternalMemory.read(851),  // duration
      PWMChannel[LEDPWM2]);

    PWMChannel[LEDPWM3]=PWMChannel[LEDPWM2];

    // The lines above are what calculates the slope.
    // You can change the schedule by changing the parameter inside the parenthesis of the PWMSlope() function
    // The are as follow:
    // 1st parameter: hour to start slope
    // 2nd parameter: minute to start slope
    // 3rd parameter: hour to end slope
    // 4th parameter: minute to end slope
    // 5th parameter: % of the PWM signal to start slope
    // 6th parameter: % of the PWM signal to end slope
    // 7th parameter: duration of slope in minutes
    // 8th parameter: always the same as the variable before the PWMSlope() call

    //PWMChannel[LEDPWM1]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM1]);

    // In the example above, we are starting the slope at 3:00pm with 15% and going up to 45% within 90 minutes, which would be 4:30pm.
    // Then it would stay at 45% from 4:30 to 90 minutes prior to 9:30pm, which would be 8:00pm.
    // Then from 8:00pm, it would start sloping down from 45% all the way back to 15% within 90 minutes, which would be 9:30pm.
    //CheckCloud(); (May be used at a later date with cloud/storm effects)
    ReefAngel.PWM.Expansion(LEDPWM0,int(PWMChannel[LEDPWM0]));
    ReefAngel.PWM.Expansion(LEDPWM1,int(PWMChannel[LEDPWM1]));
    ReefAngel.PWM.Expansion(LEDPWM2,int(PWMChannel[LEDPWM2]));
    ReefAngel.PWM.Expansion(LEDPWM3,int(PWMChannel[LEDPWM3]));

//------------------------------------------------- End PWM Expansion Code for Slope ----------------------------------------------

//------------------------------------------------ Start Time-of-Day Based Functions ----------------------------------------------
//-------------------------------------------------------- Moonlight Schedule -----------------------------------------------------
    if ( NumMins(hour(),minute()) < 450 )  // Turn off Moonlights from Midnight to 7:30 MAM
    {
      ReefAngel.Relay.Off(Box1_Port5);
      ReefAngel.Relay.Off(Box1_Port6);
    }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These are the mode numbers for the RF Expansion Module for reference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //#define Constant      0
    //#define Random1       1 // Lagoonal
    //#define Random2       2 // Reef Crest
    //#define ShortWave     3
    //#define LongWave      4
    //#define Smart_NTM     5 // Nutrient Transport Mode
    //#define Smart_TSM     6 // Tidal Swell Mode
    //#define Feeding_Start 7
    //#define Feeding_Stop  8
    //#define Night         9
    //#define Slave_Start   97
    //#define Slave_Stop    98
    //#define None          99
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//------------------------------ Start Feeding Mode Schedule (Start 1st Feeding at 9:55 AM and 2nd at 1:55 PM)---------------------
    // if the hour is 9a or 1p, minute is 55 and seconds is 0
    // start the feeding mode
    if ( ((hour() == 9) || (hour() == 13)) && 
       (minute() == 55) && 
       (second() == 0) ) 
    {
      ReefAngel.FeedingModeStart();
      vtechmode = InternalMemory.RFMode_read();     
    }
//------------------------------------------------------ End of Feeding Mode Schedule ---------------------------------------------

//-------------------------------------------------------- Start RF Daytime Control -----------------------------------------------
  if (hour() >=8 && hour() <= 22)
  {  
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding )
    {
      bFeeding=false; 
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,155,5);
      ReefAngel.Timer[4].SetInterval(1800); // Timer for 30min
      ReefAngel.Timer[4].Start();
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[4].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }  
  }
//---------------------------------------------------------- End RF Daytime Control -----------------------------------------------   

//-------------------------------------------------------- Start RF Nightmode Control ---------------------------------------------    

  if (hour()>=23 || hour()<7) // Defining "Nightmode" hours for VorTech = between 11 PM and 7 AM
    {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
    }
  else
    {
      ReefAngel.RF.SetMode(Feeding_Stop,0,0); //Temp fix for coming out of Night mode
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    } 
    ReefAngel.ShowInterface();    
//---------------------------------------------------------- End RF Nightmode Control ---------------------------------------------
//------------------------------------------------------ End Time-of-Day Based Functions ------------------------------------------
}
//--------------------------------------------------------------- End Loop --------------------------------------------------------
//*********************************************************************************************************************************

// ToDo List Functions that still need to be added above:
// 1. Add Sunrise/Sunset/MoonPhase/Cloud Chance, etc. (PWM Slope data may be altered by these?)
// 2. *Option for later date* Relay box Ports 7 and 8 changed to "Off" normally, then add line in Loop to power them on if Overheat 
//    Shutoff is active (when I get fans to plug into those ports.)   
Any ideas why this is happening or how to fix it?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: LED Lights "Pulsing" with PWM Module / Slope

Post by rimai »

Change this:

Code: Select all

    ReefAngel.PWM.Expansion(LEDPWM0,int(PWMChannel[LEDPWM0]));
    ReefAngel.PWM.Expansion(LEDPWM1,int(PWMChannel[LEDPWM1]));
    ReefAngel.PWM.Expansion(LEDPWM2,int(PWMChannel[LEDPWM2]));
    ReefAngel.PWM.Expansion(LEDPWM3,int(PWMChannel[LEDPWM3]));
To this:

Code: Select all

    ReefAngel.PWM.SetChannel(LEDPWM0,int(PWMChannel[LEDPWM0]));
    ReefAngel.PWM.SetChannel(LEDPWM1,int(PWMChannel[LEDPWM1]));
    ReefAngel.PWM.SetChannel(LEDPWM2,int(PWMChannel[LEDPWM2]));
    ReefAngel.PWM.SetChannel(LEDPWM3,int(PWMChannel[LEDPWM3]));
Roberto.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: LED Lights "Pulsing" with PWM Module / Slope

Post by TanksNStuff »

OK, I changed the code but don't want to turn the lights back on to test it right now... fish have been scared enough today, lol.

I'll check it in the morning and let you know if that fixed it.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: LED Lights "Pulsing" with PWM Module / Slope

Post by TanksNStuff »

It's amazing what one small word change can make. That did the trick!

Thanks Roberto. You are a genious. :ugeek:
CortezLoetz
Posts: 1
Joined: Wed Sep 19, 2012 8:34 pm

Re: LED Lights "Pulsing" with PWM Module / Slope

Post by CortezLoetz »

I changed the code but don't want to turn the lights back on to test it right now...
CleoGerten
Posts: 1
Joined: Mon Nov 12, 2012 11:45 pm

Re: LED Lights "Pulsing" with PWM Module / Slope

Post by CleoGerten »

I now get this "pulsing" affect on all channels while the slope is either ramping up or ramping down.
Ademster
Posts: 144
Joined: Tue Aug 14, 2012 1:11 pm

Re: LED Lights "Pulsing" with PWM Module / Slope

Post by Ademster »

How Many LEDs do you have on each of the driver strings?

Mine did this at first. Discovered that the drivers don't like less than 10 leds per string.

You can do one of two things. add leds to each string or, turn the svr 1 down in the driver which is voltage output.
Adam
58 Gal
Image
Post Reply