Sigmoid wave form is generating a wrong value

Related to the development libraries, released by Curt Binder
Post Reply
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Sigmoid wave form is generating a wrong value

Post by rimai »

The sigmoid wave form is outputting the wrong value in the center of the peak.
This is what I used to generate the plot:

Code: Select all

PWMSigmoid(8,0,20,0,0,100,0)
Right in the middle, it output 50 instead of 100.
https://github.com/reefangel/Libraries/issues/194
Roberto.
AlanM
Posts: 263
Joined: Wed Jan 01, 2014 7:26 am

Re: Sigmoid wave form is generating a wrong value

Post by AlanM »

Weird. I use it every day and didn't see that. I'll check it out.
AlanM
Posts: 263
Joined: Wed Jan 01, 2014 7:26 am

Re: Sigmoid wave form is generating a wrong value

Post by AlanM »

Is it really exactly in the middle? The math is pretty simple, but I can maybe see a way that it would generate a different number in the center since it isn't totally continuous, when (current-start) = FWHM there doesn't seem to be a value set, since I just had done < and >, not <=, for instance. Also, FWHM is exactly in the center, so it would fit with happening at that spot.

Before I do a commit to change it, can you just add an equal sign, like this:

Code: Select all

    if ((current >= (start + FWHM)) && (current < (end - FWHM))) 
Since FWHM is at the exact halfway point, that if should be satisfied for either of them if you have an = sign in there, but it doesn't hurt to have them both. They should both give the same value.

It won't be exactly 100%, by the way, but something very close. Within 1% of 100%.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Sigmoid wave form is generating a wrong value

Post by rimai »

No. that did not fix it.
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Sigmoid wave form is generating a wrong value

Post by rimai »

This is the code I used for testing:

Code: Select all

#include <Salinity.h>
#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 <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

void setup()
{
  ReefAngel.Init();  
  setSyncInterval(SECS_PER_HOUR*6000);
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
}
//ReefAngel.PWM.
void loop()
{
  while(1)
  {
    wdt_reset();
    Serial.println(PWMSigmoid(8,0,20,0,0,100,0));
    adjustTime(60);
    delay(1);
  }
  ReefAngel.ShowInterface();
}
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Sigmoid wave form is generating a wrong value

Post by rimai »

I think this code could even be changed up a bit to allow us to run for 24hrs and allow us to see how the pattern looks in the tank within a short span of time.
Kind of like press preview and the controller adjusts the LEDs to show how the pattern would look like. What do you think?
The only caveat is that all other functions that use time would be affected too. :(
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Sigmoid wave form is generating a wrong value

Post by lnevo »

That sounds cool
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Sigmoid wave form is generating a wrong value

Post by lnevo »

rimai wrote:The only caveat is that all other functions that use time would be affected too. :(
The only thing I would worry about that is the dosing pumps, how quick do you run through the 24 hour window? I think a simple flag to not run the dosing pumps during the preview would suffice...
AlanM
Posts: 263
Joined: Wed Jan 01, 2014 7:26 am

Re: Sigmoid wave form is generating a wrong value

Post by AlanM »

That code is a great idea! I never thought about doing it that way.
Post Reply