Page 1 of 1

ato port to pwm

Posted: Sun Sep 11, 2011 7:51 pm
by jonegross
So I have read one can do this, but could not find any code. What I want to do is use one of the ATO ports to control my red led driver. I currently use single low ato. Will I be able to use one port for ato and the other for pwm driver control? I have read the port only does 0-5v, which I think should be fine as I only want to run the red channel at maybe 400mA at peak. What would the code look like? So is there some call to make the port a pwm channel?

some command that changes function of ato port?
then in the loop
ReefAngel.PWM.SetATO(PWMSlope(10,30,22,30,1,80,120,ReefAngel.PWM.GetATOValue()));

What are my options for more pwm ports? Does the relay expansion module have 2 more pwm ports? Think I will run need more relays soon anyway...

Oh does the wifi module include everything needed, or is there a cord or something I would need to order?

Thanks for any help

Re: ato port to pwm

Posted: Sun Sep 11, 2011 8:01 pm
by rimai
You can use Low ATO port as a third PWM output channel, which can only output 0-5V PWM.
Since you seem to be only willing to run at 400mA, you should be fine using the meanwell driver on this port.
Here is the code to use:

Code: Select all

  pinMode(lowATOPin,OUTPUT); 
  analogWrite(lowATOPin,PWMvalue); 
Alternatively, a PWM expansion module can give you 6 more channels.
The wifi attachment comes with the cable to connect to the RA head unit.

Re: ato port to pwm

Posted: Sun Sep 11, 2011 9:52 pm
by jonegross
Thanks for the quick reply.

Re: ato port to pwm

Posted: Sun Aug 26, 2012 10:02 pm
by hous0067
Hi,
Noob question: I'm trying to get pwm fans (not led) to dim using the ato low port as a 0-5v pwm driver. I wired up the fans with a separate 12v power supply, I just want a control signal from the ato + port.

I've read enough to think I need the codes below...can someone also help me with exactly where I'm supposed to put these commands in the code? :oops:

pinMode(lowATOPin,OUTPUT);
analogWrite(lowATOPin,PWMvalue);

BlowerSpeed=map(ReefAngel.Params.Temp[T3_PROBE],772,789,30,100); // Calculate Blower speed
BlowerSpeed=constrain(BlowerSpeed,0,100);

Thanks in advance!
hous0067

Re: ato port to pwm

Posted: Mon Aug 27, 2012 7:58 am
by rimai
Add to your loop() section.

Code: Select all

BlowerSpeed=map(ReefAngel.Params.Temp[T3_PROBE],772,789,30,100); // Calculate Blower speed
BlowerSpeed=constrain(BlowerSpeed,0,100);
pinMode(lowATOPin,OUTPUT); 
analogWrite(lowATOPin,BlowerSpeed);

Re: ato port to pwm

Posted: Mon Aug 27, 2012 8:40 pm
by hous0067
Thanks for the fast reply, Roberto!
Compiler crashed, I'm not sure what I'm doing wrong...

"Error: 'BlowerSpeed' was not declared in this scope" ?

I have Library version 1.0.1

Here's the code I tried to compile, Wizard code and added those lines to the custom loop.


#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 <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.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 toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port2Bit | Port3Bit | Port4Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T3_PROBE;
ReefAngel.OverheatProbe = T3_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 845 );


// Ports that are always on
ReefAngel.Relay.On( Port7 );

////// Place additional initialization code below here



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

void loop()
{
ReefAngel.StandardHeater( Port1,725,735 );
ReefAngel.StandardLights( Port2,9,0,21,45 );
ReefAngel.StandardLights( Port3,9,0,21,0 );
ReefAngel.StandardLights( Port4,9,0,21,0 );
ReefAngel.WavemakerRandom( Port5,180,300 );
ReefAngel.Relay.Set( Port6, !ReefAngel.Relay.Status( Port5 ) );
ReefAngel.Relay.DelayedOn( Port8,3 );
ReefAngel.PWM.SetDaylight( PWMParabola(9,0,21,0,10,100,10) );
ReefAngel.PWM.SetActinic( PWMParabola(9,0,21,0,10,100,10) );
////// Place your custom code below here

BlowerSpeed=map(ReefAngel.Params.Temp[T3_PROBE],772,789,30,100); // Calculate Blower speed
BlowerSpeed=constrain(BlowerSpeed,0,100);
pinMode(lowATOPin,OUTPUT);
analogWrite(lowATOPin,BlowerSpeed);

////// Place your custom code above here

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

void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();

// Salinity
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,66, "SAL:" );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,66, ReefAngel.Params.Salinity );
pingSerial();

// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 94, TempRelay );
pingSerial();

// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}

void DrawCustomGraph()
{
}

Re: ato port to pwm

Posted: Mon Aug 27, 2012 8:42 pm
by rimai
You must declare it at the top of the code.. Sorry.

Code: Select all

#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 <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <ReefAngel.h>

////// Place global variable code below here
int BlowerSpeed;

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


void setup()
{
 // This must be the first line
 ReefAngel.Init(); //Initialize controller
 // Ports toggled in Feeding Mode
 ReefAngel.FeedingModePorts = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
 // Ports toggled in Water Change Mode
 ReefAngel.WaterChangePorts = Port5Bit | Port6Bit | Port7Bit | Port8Bit;
 // Ports toggled when Lights On / Off menu entry selected
 ReefAngel.LightsOnPorts = Port2Bit | Port3Bit | Port4Bit;
 // Ports turned off when Overheat temperature exceeded
 ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit;
 // Use T1 probe as temperature and overheat functions
 ReefAngel.TempProbe = T3_PROBE;
 ReefAngel.OverheatProbe = T3_PROBE;
 // Set the Overheat temperature setting
 InternalMemory.OverheatTemp_write( 845 );


 // Ports that are always on
 ReefAngel.Relay.On( Port7 );

 ////// Place additional initialization code below here



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

void loop()
{
 ReefAngel.StandardHeater( Port1,725,735 );
 ReefAngel.StandardLights( Port2,9,0,21,45 );
 ReefAngel.StandardLights( Port3,9,0,21,0 );
 ReefAngel.StandardLights( Port4,9,0,21,0 );
 ReefAngel.WavemakerRandom( Port5,180,300 );
 ReefAngel.Relay.Set( Port6, !ReefAngel.Relay.Status( Port5 ) );
 ReefAngel.Relay.DelayedOn( Port8,3 );
 ReefAngel.PWM.SetDaylight( PWMParabola(9,0,21,0,10,100,10) );
 ReefAngel.PWM.SetActinic( PWMParabola(9,0,21,0,10,100,10) );
 ////// Place your custom code below here

 BlowerSpeed=map(ReefAngel.Params.Temp[T3_PROBE],772,789,30,100); // Calculate Blower speed
 BlowerSpeed=constrain(BlowerSpeed,0,100);
 pinMode(lowATOPin,OUTPUT); 
analogWrite(lowATOPin,BlowerSpeed); 

////// Place your custom code above here

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

void DrawCustomMain()
{
 int x,y;
 char text[10];
 // Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
 ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
 ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
 ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
 pingSerial();

 // Salinity
 ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,66, "SAL:" );
 ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,66, ReefAngel.Params.Salinity );
 pingSerial();

 // Main Relay Box
 byte TempRelay = ReefAngel.Relay.RelayData;
 TempRelay &= ReefAngel.Relay.RelayMaskOff;
 TempRelay |= ReefAngel.Relay.RelayMaskOn;
 ReefAngel.LCD.DrawOutletBox( 12, 94, TempRelay );
 pingSerial();

 // Date and Time
 ReefAngel.LCD.DrawDate( 6, 122 );
 pingSerial();
}

void DrawCustomGraph()
{
}

Re: ato port to pwm

Posted: Tue Aug 28, 2012 7:21 pm
by hous0067
Thanks, Roberto, that code compiled and loaded perfectly!

One more question; I have an analog dimming controller (apollo lights), will it make a pwm signal for the atolow port? ...just curious...my fans are still just idling like they aren't getting a signal, but it could be the fans...or my soldering...or both... :)

Thanks,
-Ken

Re: ato port to pwm

Posted: Tue Aug 28, 2012 7:34 pm
by rimai
Yes, the analog conversion happens on the relay box.
The ATO ports will output PWM signal.
If they are just idling and temp is between 77.2 and 78.9, there is something else wrong.
Do you have a meter?
Can you measure the voltage on the ATO port pins?

Re: ato port to pwm

Posted: Tue Aug 28, 2012 7:54 pm
by hous0067
I actually changed the code to always be at 100%, just to see if I could get the fans to respond (they didn't).

My meter says 2.5v AC across the atolow. (1.85+/-.01 DC)

Re: ato port to pwm

Posted: Tue Aug 28, 2012 8:42 pm
by rimai
Oh, you know what....
The mapping is wrong.
The raw value ranges from 0-255, where 100% is 255.
That's why you are getting around 1.85VDC. That's the equivalent to 100/255 when you apply to 5V.
So, your code needs to be like this:

Code: Select all

BlowerSpeed=map(ReefAngel.Params.Temp[T3_PROBE],772,789,76,255); // Calculate Blower speed
 BlowerSpeed=constrain(BlowerSpeed,0,255);
 pinMode(lowATOPin,OUTPUT); 
analogWrite(lowATOPin,BlowerSpeed); 
76 is 30% of 255
255 is 100% of 255