Page 1 of 5

Coding Pwm module.

Posted: Tue May 08, 2012 3:31 am
by abhi_123
Hello Everyone.

which code should i use to make my pwm module to work.

i will be using 4 led drivers & two fans with parabola instead of slope with random cloud & lightning effect + moonlight phase on actinic channel on relay box.

Re: Coding Pwm module.

Posted: Tue May 08, 2012 7:25 am
by rimai
I vote for one thing at a time.
1st step is getting the base code from RAGen. Do you have that?

Re: Coding Pwm module.

Posted: Tue May 08, 2012 7:57 am
by abhi_123
rimai wrote:I vote for one thing at a time.
1st step is getting the base code from RAGen. Do you have that?
here we go
// Autogenerated file by RAGen (v1.2.2.171), (05/04/2012 21:21)
// RA_050412_2121.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
#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 <ReefAngel.h>

////// Place global variable code below here


////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init(); //Initialize controller

    // Ports that are always on
    ReefAngel.Relay.On(Port4);
    ReefAngel.Relay.On(Port7);
    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
}

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.SingleATOLow(Port1);
    ReefAngel.StandardLights(Port2);
    ReefAngel.StandardLights(Port3);
    ReefAngel.Wavemaker1(Port5);
    ReefAngel.Wavemaker2(Port6);
    ReefAngel.StandardHeater(Port8);

    // PWMSlope based on Internal Memory values for Standard Lights
    ReefAngel.PWM.ActinicPWMSlope();
    ReefAngel.PWM.DaylightPWMSlope();
    ////// Place your custom code below here
    

    ////// Place your custom code above here
    // This sends all the data to the portal
    // Do not add any custom code that changes any relay status after this line
    // The only code after this line should be the ShowInterface function
    ReefAngel.Portal("abhi_123",);

    // This should always be the last line
    ReefAngel.ShowInterface();
}


Re: Coding Pwm module.

Posted: Tue May 08, 2012 8:09 am
by rimai
Ok, first thing we want to do is add the moonlight.
Replace this:

Code: Select all

    ReefAngel.PWM.ActinicPWMSlope();
With this:

Code: Select all

    ReefAngel.PWM.SetActinic(MoonPhase());

Re: Coding Pwm module.

Posted: Tue May 08, 2012 8:13 am
by abhi_123
Done. now.

Re: Coding Pwm module.

Posted: Tue May 08, 2012 8:15 am
by rimai
Then, remove the daylight channel you are not using:

Code: Select all

    ReefAngel.PWM.DaylightPWMSlope();

Re: Coding Pwm module.

Posted: Tue May 08, 2012 8:17 am
by rimai
And add the code for the parabolas. Make sure to add them in the designated area for your custom code:

Code: Select all

    ReefAngel.PWM.SetChannel(0,PWMParabola(9,0,20,0,0,100,0)); 
    ReefAngel.PWM.SetChannel(1,PWMParabola(9,0,20,0,0,100,0)); 
    ReefAngel.PWM.SetChannel(2,PWMParabola(9,0,20,0,0,100,0)); 
    ReefAngel.PWM.SetChannel(3,PWMParabola(9,0,20,0,0,100,0)); 

Re: Coding Pwm module.

Posted: Tue May 08, 2012 9:15 am
by abhi_123
updated.

now?

Re: Coding Pwm module.

Posted: Tue May 08, 2012 9:56 am
by rimai
Is it working?

Re: Coding Pwm module.

Posted: Tue May 08, 2012 10:07 am
by abhi_123
YES.

Re: Coding Pwm module.

Posted: Tue May 08, 2012 10:45 am
by abhi_123
// Autogenerated file by RAGen (v1.2.2.171), (05/04/2012 21:21)
// RA_050412_2121.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
#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 <ReefAngel.h>

////// Place global variable code below here


////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init(); //Initialize controller

    // Ports that are always on
    ReefAngel.Relay.On(Port4);
    ReefAngel.Relay.On(Port7);
    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
}

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.SingleATOLow(Port1);
    ReefAngel.StandardLights(Port2);
    ReefAngel.StandardLights(Port3);
    ReefAngel.Wavemaker1(Port5);
    ReefAngel.Wavemaker2(Port6);
    ReefAngel.StandardHeater(Port8);

    // PWMSlope based on Internal Memory values for Standard Lights
    ReefAngel.PWM.SetActinic(MoonPhase());
    ////// Place your custom code below here
    ReefAngel.PWM.SetChannel(0,PWMParabola(9,0,20,0,0,100,0));
    ReefAngel.PWM.SetChannel(1,PWMParabola(9,0,20,0,0,100,0));
    ReefAngel.PWM.SetChannel(2,PWMParabola(9,0,20,0,0,100,0));
    ReefAngel.PWM.SetChannel(3,PWMParabola(9,0,20,0,0,100,0));

    ////// Place your custom code above here
    // This sends all the data to the portal
    // Do not add any custom code that changes any relay status after this line
    // The only code after this line should be the ShowInterface function
    ReefAngel.Portal("abhi_123",);

    // This should always be the last line
    ReefAngel.ShowInterface();
}

Here is what i had uploaded. pwm expansion channel rating is still zero.

Re: Coding Pwm module.

Posted: Tue May 08, 2012 12:20 pm
by rimai
So, we don't know if it is working, right?
I guess you will need to wait until tomorrow to test?

Re: Coding Pwm module.

Posted: Tue May 08, 2012 1:48 pm
by rufessor
I hate waiting for the sun to rise! :lol:

Seems like that's all I do lately!

Have fun-

Re: Coding Pwm module.

Posted: Tue May 08, 2012 9:01 pm
by abhi_123
An update. Pwm expansion module is working fine but have some issue with actinic moonphase it is still on 59% although it is 9:30am here with sun shinning high.

Re: Coding Pwm module.

Posted: Tue May 08, 2012 9:04 pm
by rimai
Good.
From what time to what time do you want moonlights to be on?

Re: Coding Pwm module.

Posted: Tue May 08, 2012 10:00 pm
by abhi_123
Just opposite to my daylight schedule.j

Re: Coding Pwm module.

Posted: Tue May 08, 2012 10:02 pm
by rimai
Replace this:

Code: Select all

    ReefAngel.PWM.SetActinic(MoonPhase());
With this:

Code: Select all

    if (ReefAngel.Relay.Status(Port2)) ReefAngel.PWM.SetActinic(0); else ReefAngel.PWM.SetActinic(MoonPhase());

Re: Coding Pwm module.

Posted: Tue May 08, 2012 10:50 pm
by abhi_123
Alright. My standard light are assigned on relay 3 so i have to make it 3 instead of 2?

After that now comes the fan portion. I like to install pwm fans on channel 4& 5 to control the temp of my heat sink & tank respectively.

Re: Coding Pwm module.

Posted: Wed May 09, 2012 7:54 am
by rimai
For Fan, use this:

Code: Select all

  byte Fan1Speed;
  Fan1Speed=map(ReefAngel.Params.Temp[1],772,800,30,100); // Calculate Fan 1 speed
  Fan1Speed=constrain(Fan1Speed,0,100);
  ReefAngel.PWM.SetChannel(4,Fan1Speed);

  byte Fan2Speed;
  Fan2Speed=map(ReefAngel.Params.Temp[1],772,800,30,100); // Calculate Fan 2 speed
  Fan2Speed=constrain(Fan2Speed,0,100);
  ReefAngel.PWM.SetChannel(5,Fan2Speed);
You can change the temperatures and % on the map function.
I thought I had already posted this for you... :?:

Re: Coding Pwm module.

Posted: Fri May 11, 2012 11:07 am
by abhi_123
Sorry Roberto i missed that post that's why i asked again.

All my code is working great. Now i want to add lightning , cloud & thunderstorm effect to my lights.

Re: Coding Pwm module.

Posted: Fri May 11, 2012 11:53 am
by rimai
Cool.
How are you with memory space?

Re: Coding Pwm module.

Posted: Fri May 11, 2012 6:39 pm
by abhi_123
rimai wrote:Cool.
How are you with memory space?
Upto now no issue.

Re: Coding Pwm module.

Posted: Fri May 11, 2012 6:42 pm
by rimai
I mean, how much free space do you have?

Re: Coding Pwm module.

Posted: Fri May 11, 2012 9:02 pm
by abhi_123
How to check that?

Re: Coding Pwm module.

Posted: Fri May 11, 2012 9:06 pm
by rimai
Hit the checkmark icon to compile and it will show you.

Re: Coding Pwm module.

Posted: Fri May 11, 2012 9:29 pm
by abhi_123
31698 of 32256 bytes total.

Re: Coding Pwm module.

Posted: Fri May 11, 2012 9:34 pm
by rimai
That's getting pretty close to full.
I don't think we'll be able to fit.

Re: Coding Pwm module.

Posted: Sat May 12, 2012 10:23 am
by abhi_123
any modification in my existing code is possible to include the desired function?

Re: Coding Pwm module.

Posted: Sat May 12, 2012 11:28 am
by rimai
If we hard code some of the settings and use a custom screen and custom menu, we will be able to squeeze it.
This would mean that you will loose the pH calibration on the menu and the graph on the main screen.
The other alternative is to modify the code in your PWM module itself and shift all the code for your lights to the module.
Take a look at these threads:
http://forum.reefangel.com/viewtopic.php?f=11&t=535
http://forum.reefangel.com/viewtopic.php?f=11&t=1069
http://forum.reefangel.com/viewtopic.php?f=11&t=923

Re: Coding Pwm module.

Posted: Sat May 12, 2012 6:45 pm
by abhi_123
this is what i have to include in my code to shift light setting to my module?


//Start of PWM Expansion Code Header

// 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 channels at startup. They will always be 0.
byte PWMChannel[]={
0,0,0,0,0,0};
//End of PWM Expansion Code Header
//*********************************************************************************************************************************