help with pwmslope and pwm expansion module

Requests for new functions or software apps
Post Reply
NanoTrevor
Posts: 69
Joined: Thu Jun 02, 2011 1:58 pm

help with pwmslope and pwm expansion module

Post by NanoTrevor »

as title states, its not working either the slope or expansion module. code attached if you can help figure this out. lights just jump to specified % with no ramp.

Code: Select all

// Autogenerated file by RAGen (v1.0.4.92), (06/03/2011 21:13)
// RA_060311_2113.pde
//
// This version designed for v0.8.5 Beta 12 or later

/* The following features are enabled for this PDE File: 
#define DisplayImages
#define DateTimeSetup
#define VersionMenu
#define ATOSetup
#define DirectTempSensor
#define DisplayLEDPWM
#define SingleATOSetup
#define StandardLightSetup
*/

#include <ReefAngel_Colors.h>
#include <ReefAngel_CustomColors.h>
#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>

//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 LEDPWMAmber 0
#define LEDPWMRedOrange 1
#define LEDPWMBlue 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[]={
100,100,100,100,100,100};

//End of PWM Expansion Code Header
//*********************************************************************************************************************************


void setup()
{
    ReefAngel.Init();  //Initialize controller

    ReefAngel.FeedingModePorts = B00000001; //turns off return pump
    ReefAngel.WaterChangePorts = B01110001; //turns off return pump, heater, fan/chiller and ATO
    ReefAngel.OverheatShutoffPorts = B00101110; //turns off lights and heater
    ReefAngel.LightsOnPorts = B00001110; //turns on lights

    // Ports that are always on
    ReefAngel.Relay.On(Port1);
    ReefAngel.Relay.On(Port8);
}

void loop()
{
    ReefAngel.ShowInterface();
    ReefAngel.PWM.SetActinic(PWMSlope(7,30,19,0,100,50,60,ReefAngel.PWM.GetActinicValue())); //actinic leds ramp up from 0% at 7:30am to 60% at 8:30am and ramp down from 6:00pm to 7:00pm back to 0%
    ReefAngel.PWM.SetDaylight(PWMSlope(8,30,18,0,100,60,60,ReefAngel.PWM.GetDaylightValue())); //daylight leds ramp up from 0% at 8:30am to 50% at 9:30am and ramp down from 5:00pm to 6:0pm back to 0%
   
       // Specific functions
    ReefAngel.StandardLights(Port2); 
    ReefAngel.StandardLights(Port3);
    ReefAngel.StandardLights(Port4);
    ReefAngel.StandardFan(Port5);
    ReefAngel.StandardHeater(Port6);
    ReefAngel.SingleATOHigh(Port7);
    
  //Start of PWM Expansion Code for Slope
    PWMChannel[LEDPWMAmber]=PWMSlope(5,30,7,30,100,90,60,PWMChannel[LEDPWMAmber]);
    PWMChannel[LEDPWMRedOrange]=PWMSlope(6,00,8,00,100,90,60,PWMChannel[LEDPWMRedOrange]);
    PWMChannel[LEDPWMBlue]=PWMSlope(19,00,23,00,100,60,15,PWMChannel[LEDPWMBlue]);
    // The 2 line above is 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
    
       
    // 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.
    PWMExpansion(LEDPWMAmber,int(2.55*PWMChannel[LEDPWMAmber]));
    PWMExpansion(LEDPWMRedOrange,int(2.55*PWMChannel[LEDPWMRedOrange]));
    PWMExpansion(LEDPWMBlue,int(2.55*PWMChannel[LEDPWMBlue]));
    
//End of PWM Expansion Code for Slope
//*********************************************************************************************************************************
    
}

//*********************************************************************************************************************************
//Start of PWM slope function code designed for the PWM Expansion module
void PWMExpansion(byte cmd, byte data)
{ 
Wire.beginTransmission(8); // transmit to device #2
Wire.send('$'); // sends $ 
Wire.send('$'); // sends $ 
Wire.send('$'); // sends $ 
Wire.send(cmd); // sends a value 
Wire.send(data); // sends 255 
Wire.endTransmission(); // stop transmitting
}
//End of PWM slope function code designed for the PWM Expansion module


Code: Select all

// Autogenerated file by RAGen (v1.0.4.92), (06/06/2011 21:18)
// Memory_060611_2118.pde
//
// This file sets the default values to the Internal Memory
//


#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <Time.h>
#include <OneWire.h>
#include <Phillips6610LCDInv.h>
#include <avr/pgmspace.h>
#include <ReefAngel_EEPROM.h>


Phillips6610LCDInv e;

void setup()
{
    e.lcd_init();
    e.lcd_clear(COLOR_WHITE,0,0,132,132);
    e.lcd_BacklightOn();

    InternalMemory.MHOnHour_write(15);
    InternalMemory.MHOnMinute_write(0);
    InternalMemory.MHOffHour_write(15);
    InternalMemory.MHOffMinute_write(1);
    InternalMemory.MHDelay_write(5);
    InternalMemory.StdLightsOnHour_write(5);
    InternalMemory.StdLightsOnMinute_write(0);
    InternalMemory.StdLightsOffHour_write(23);
    InternalMemory.StdLightsOffMinute_write(0);
    InternalMemory.DP1OnHour_write(20);
    InternalMemory.DP1OnMinute_write(0);
    InternalMemory.DP2OnHour_write(22);
    InternalMemory.DP2OnMinute_write(30);
    InternalMemory.DP1Timer_write(0);
    InternalMemory.DP2Timer_write(0);
    InternalMemory.DP1RepeatInterval_write(60);
    InternalMemory.DP2RepeatInterval_write(60);
    InternalMemory.ATOTimeout_write(60);
    InternalMemory.ATOHighTimeout_write(15);
    InternalMemory.ATOHourInterval_write(0);
    InternalMemory.ATOHighHourInterval_write(0);
    InternalMemory.FeedingTimer_write(900);
    InternalMemory.LCDTimer_write(600);
    InternalMemory.LEDPWMActinic_write(100);
    InternalMemory.LEDPWMDaylight_write(100);
    InternalMemory.WM1Timer_write(200);
    InternalMemory.WM2Timer_write(354);
    InternalMemory.HeaterTempOn_write(785);
    InternalMemory.HeaterTempOff_write(795);
    InternalMemory.ChillerTempOn_write(800);
    InternalMemory.ChillerTempOff_write(790);
    InternalMemory.OverheatTemp_write(1250);
    InternalMemory.PHMax_write(840);
    InternalMemory.PHMin_write(550);
}

void loop()
{
    // display the values
    char buf[128];
    sprintf(buf, "MH %2d:%02d-%2d:%02d,%d", InternalMemory.MHOnHour_read(), InternalMemory.MHOnMinute_read(),
                                         InternalMemory.MHOffHour_read(), InternalMemory.MHOffMinute_read(),
                                         InternalMemory.MHDelay_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW, buf);
    sprintf(buf, "Std %2d:%02d-%2d:%02d", InternalMemory.StdLightsOnHour_read(), InternalMemory.StdLightsOnMinute_read(),
                                          InternalMemory.StdLightsOffHour_read(), InternalMemory.StdLightsOffMinute_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*2, buf);
    sprintf(buf, "LED A: %d%% D: %d%%", InternalMemory.LEDPWMActinic_read(), InternalMemory.LEDPWMDaylight_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*3, buf);
    sprintf(buf, "WM1: %ds", InternalMemory.WM1Timer_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*4, buf);
    sprintf(buf, "WM2: %ds", InternalMemory.WM2Timer_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*5, buf);
    sprintf(buf, "F: %ds", InternalMemory.FeedingTimer_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*6, buf);
    sprintf(buf, "S: %ds", InternalMemory.LCDTimer_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*7, buf);
    sprintf(buf, "H On: %d -> %d", InternalMemory.HeaterTempOn_read(), InternalMemory.HeaterTempOff_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*9, buf);
    sprintf(buf, "C On: %d -> %d", InternalMemory.ChillerTempOn_read(), InternalMemory.ChillerTempOff_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*10, buf);
    sprintf(buf, "PH %d - %d", InternalMemory.PHMax_read(), InternalMemory.PHMin_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*11, buf);

    delay(10000);
    e.lcd_clear(COLOR_WHITE,0,0,132,132);

    sprintf(buf, "OH: %dF", InternalMemory.OverheatTemp_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW, buf);
    sprintf(buf, "ATO L: %ds (%dh)", InternalMemory.ATOTimeout_read(), InternalMemory.ATOHourInterval_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*2, buf);
    sprintf(buf, "ATO H: %ds (%dh)", InternalMemory.ATOHighTimeout_read(), InternalMemory.ATOHighHourInterval_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*3, buf);

    sprintf(buf, "DP1: %2d:%02d", InternalMemory.DP1OnHour_read(), InternalMemory.DP1OnMinute_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*5, buf);
    sprintf(buf, "     %ds", InternalMemory.DP1Timer_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*6, buf);
    sprintf(buf, "DP2: %2d:%02d", InternalMemory.DP2OnHour_read(), InternalMemory.DP2OnMinute_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*7, buf);
    sprintf(buf, "     %ds", InternalMemory.DP2Timer_read());
    e.lcd_draw_text(COLOR_BLACK, COLOR_WHITE, MENU_START_COL, MENU_START_ROW*8, buf);

    delay(10000);
    e.lcd_clear(COLOR_WHITE,0,0,132,132);
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: help with pwmslope and pwm expansion module

Post by rimai »

The problem with the PWMSlope calculation in this case is that you cannot use inverted slope. You have to start with the lowest and end with the highest.
This will cause problems:

Code: Select all

    ReefAngel.PWM.SetActinic(PWMSlope(7,30,19,0,100,50,60,ReefAngel.PWM.GetActinicValue())); 
Use this instead:

Code: Select all

    ReefAngel.PWM.SetActinic(PWMSlope(7,30,19,0,50,100,60,ReefAngel.PWM.GetActinicValue())); 
Sorry, I revised after posting.
Roberto.
NanoTrevor
Posts: 69
Joined: Thu Jun 02, 2011 1:58 pm

Re: help with pwmslope and pwm expansion module

Post by NanoTrevor »

thanks roberto
Post Reply