Why Irms is ignored

UKHeliBob:
Check the syntax of the if statement

I know that problem is there but don't know how to fix it

I know that problem is there but don't know how to fix it

I was referring to this line of code whuch was in one version of your code

      if Irms (> 0.5)

It may not be in later versions but the syntax is/was wrong

AWOL:

  volt = analogRead(PA7); // A0

if (volt > 0.5)



analogRead returns a positive integer value.
Only one positive integer value (debatable) is less than 0.5.

float volt = analogRead(PA7);
volt = (volt * 3.3) / 4095.0; = this volt I want to be used, I thought I using

A Big Thanks all of you = I did it.

  // volt = analogRead(PA7);
  float volt = analogRead(PA7);
  volt = (volt * 3.3) / 4095.0;

  if (digitalRead(PB9) == HIGH)
  {
    if (volt > 0.5)
      //if (volt > 5)

      // if (volt < 0.5)
      //if (i < 35)
    {
      i++;
      // delay (300);
    }
    else
    {
      i--;
      //delay (300);
    }
  }

  ///////////////////

  // float volt = analogRead(PA7);
  // volt = (volt * 3.3) / 4095.0;

  lcd.setCursor(0, 0);
  lcd.print("V=");
  lcd.print(volt);
  lcd.setCursor(0, 1);
  lcd.print("I=");
  lcd.print( i);
  //delay (100);

read again #2

AWOL
Now can be marked SOLVED
Thanks

Now I am back to original code with AC Voltmeter, it is working Ok for designated voltage.
I want the program to tune to minimum of Irms. I think this line's need work.
I will try any suggestion.

 previousIrms = currentIrms;  // store what was read last time
  // currentIrms = analogRead(PA7);  // get a new reading
  //currentIrms = ?? ??
  //currentIrms = float Irms = emon1.Irms; = not good

the program

HardwareTimer pwmtimer4(4);
#include "EmonLib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;

float  cur, acur[50], sumc;

int i = 0;
int ovfi = 0;
int (Irms) = 0 ;
int currentIrms = 0;
int previousIrms = 0;
int maxIrms = 0;
int minIrms = 4095.0;


void setup()
{
  pwmtimer4.pause();
  pwmtimer4.setPrescaleFactor(3);
  pwmtimer4.setOverflow(2000);
  //pwmtimer4.setCompare(TIMER_CH2, 2880);
  pwmtimer4.refresh();
  pwmtimer4.resume();

  pinMode(PB7, PWM); //duty regulated for balance
  pinMode(PB9, INPUT_PULLDOWN);
  pinMode(PA7, INPUT);    // Irms
  lcd.begin(16, 2);

  emon1.current(PA7, 2.8);
}

void loop()
{

  pwmtimer4.setCompare(TIMER_CH2, i);
  emon1.calcVI(20, 2);

  ///////////////////////////////////////
  float Irms = emon1.Irms;

  ////////////
  previousIrms = currentIrms;  // store what was read last time
  // currentIrms = analogRead(PA7);  // get a new reading
  //currentIrms = ?? ??
  //currentIrms = float Irms = emon1.Irms; = not good
  //////////
  if (digitalRead(PB9) == HIGH)
  {
    //if (Irms > 0.5)

      if (previousIrms < currentIrms)
      ///////////////////////////////////////////

    {
      i++;
    }
    else
    {
      i--;
    }
  }
  lcd.setCursor(0, 0);
  lcd.print("V=");
  lcd.print(Irms);
  lcd.setCursor(0, 1);
  lcd.print("I=");
  lcd.print( i);
  //delay (50);

}

int (Irms) = 0 ; Why still?

You've got a float called Irms.

Before was int (Irms) ; and voltmeter was working Ok, I will change that.

Vik321:
Before was int (Irms) ; and voltmeter was working Ok, I will change that.

Why? (There) (is) (not) (a) (reason) (on) (earth) (why) Irms, (whatever) (the) (type), (needs) (to) (be) (in) (parentheses).

Thanks for pointing that, the brackets are leftovers from another declarations = fixed

I did some testings on designated voltage of Irms, it is working Ok down to 0.01 V after that else part is not working, i should bounce around 65 (65 +/-1) but is missing this point and is rising as long as button is hold.
Any ideas how to improve reliability of else part ?

 if (Irms > 0.03)  //0.09=i=95=V 0.1_ 0.05=i=62 V=0.06, _0.03=i= missing 0.03V
     
 {
      i++;
    }
    else
    {
      i--;
    }
  }
//0.09=i=95=V 0.1_ 0.05=i=62 V=0.06, _0.03=i= missing 0.03V

Can we get a translation of that comment, please?

//0.09=i=95=V 0.1_ 0.05=i=62 V=0.06, _0.03=i= missing 0.03V
for designated voltage 0.09V i =95, for designated voltage 0.05V i = 62, for designated voltage 0.03 V i is missing designated voltage and is continue to rising. Reliable designated voltage is 0.01V, lower than that = else part is not working.

  else
    {
      i--;
    }

correction 0.1
typing error should be 0.01.

I wish I hadn't asked now.
I'm even more confused.

Can we see all of your code, please?

Post #46

Where do you set currentIrms in your code in #46?

christop:
Where do you set currentIrms in your code in #46?

That's the reason I wanted to see the current code

The second part = program
Here is again

HardwareTimer pwmtimer4(4);
#include "EmonLib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;

float  cur, acur[50], sumc;

int i ;
int ovfi;
//int (Irms) = 0 ;
int Irms ;
int currentIrms ;
int previousIrms ;
//int maxIrms ;

//int currentIrms = 0;
//int previousIrms = 0;
int maxIrms = 0;
int minIrms = 4095.0;


void setup()
{
  pwmtimer4.pause();
  pwmtimer4.setPrescaleFactor(3);
  pwmtimer4.setOverflow(2000);
  //pwmtimer4.setCompare(TIMER_CH2, 2880);
  pwmtimer4.refresh();
  pwmtimer4.resume();

  pinMode(PB7, PWM); //duty regulated for balance
  pinMode(PB9, INPUT_PULLDOWN);
  pinMode(PA7, INPUT);    // Irms
  lcd.begin(16, 2);

  emon1.current(PA7, 2.8);
}

void loop()
{
  ovfi = 100 - i;


  // if ( i > 0) {
  //  i++;
  // }
  pwmtimer4.setCompare(TIMER_CH2, i);
  emon1.calcVI(20, 2);

  ///////////////////////////////////////
  float Irms = emon1.Irms;

  ////////////
  //previousIrms = currentIrms;  // store what was read last time
  // currentIrms = analogRead(PA7);  // get a new reading
  // currentIrms = Irms;
  // minIrms = Irms;
  //currentIrms = float Irms = emon1.Irms; = not good
  //////////
  if (digitalRead(PB9) == HIGH)
  {
    if (Irms > 0.05)  //0.09=i=95=V 0.1_ 0.05=i=62 V=0.06, _0.03=i= missing 0.03V
      //0.08ok,
      //if (Irms <  minIrms)


      // if (previousIrms < currentIrms)
      // if (previousIrms > currentIrms)
      ///////////////////////////////////////////

    {
      i++;
      delay (100);
    }
    else
    {
      i--;
      delay (100);
    }
  }
  lcd.setCursor(0, 0);
  lcd.print("V=");
  lcd.print(Irms);
  lcd.setCursor(0, 1);
  lcd.print("I=");
  lcd.print( i);
  //delay (50);

}