7 segment display flickering

Hi all, i'm new in forum. I have a problem with 7 segment display and arduino SevSeg library; infact i don't understand how to increase refresh rate of led to eliminate flashing.
Here my code.

#include "EmonLib.h"  // Include Emon Library
#include "SevSeg.h"

SevSeg sevseg;
EnergyMonitor emon1;  


void setup()
{  
  //Serial.begin(9600);
  byte numDigits = 2;   
  byte digitPins[] = {10, 11};
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};

  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
  sevseg.setBrightness(90);
  
  emon1.current(5, 29);             // Current: input pin, calibration.
}

void loop()
{
 
  double Irms = emon1.calcIrms(1480);  // Calculate Irms only

  int Pot = ((Irms*235)+50)/100;
 
    sevseg.setNumber(Pot, 1);

   
  
  //Serial.print(Pot);         // Apparent power
  //Serial.print(" ");
  //Serial.println(Irms);          // Irms
  
  sevseg.refreshDisplay();
   
 
}

P.s i'm using also emonLib to measure current with sct013 sensor; perhaps increase output speed from emonlib could be a solution, but i have no idea how to do it.
Someone could help me?

Thank you and sorry for my english

This floating point operation is going to be slow

double Irms = emon1.calcIrms(1480);  // Calculate Irms only

and then you convert it to an int.

Although it is probably not the whole problem, try eliminating the calcIrms call by putting in a dummy value and Irms and see if that speeds up your refresh. That will also tell you if the slowness is in the emon library.

The Irms calculation takes 244ms in this:-
(Not sure if that's really the problem though.)

#include "EmonLib.h"  // Include Emon Library

EnergyMonitor emon1;

void setup()
{
    Serial.begin(9600);
    emon1.current(5, 29);               // Current: input pin, calibration.
    unsigned long start = millis();
    double Irms = emon1.calcIrms(1480); // Calculate Irms only
    unsigned long end = millis();
    unsigned long elapsed = end - start;
    Serial.println(elapsed);            // Prints 244
}

void loop() {}

Perhaps looking at 'refreshDisplay()' in the "SevSeg.h" library might shed some light?

The problem, I believe, is the parameter of 1480 that is passed to calcIrms(). This causes it to loop nearly 1500 times, reading an analog input and performing floating point calculations in each iteration. This prevents refresh() from smoothly multiplexing the display.

So try half that value, 740, or perhaps one quarter, 320 or one eighth 160 and see at what point the display stops flickering. This will make the reading less smooth and it may display some noise.

If that happens, you have two options. One is to modify the library code to allow for more frequent display updates while a 1480 sample average is taken. The other option is to use a chip to drive the display multiplexing so that the Arduino can concentrate on calculating the reading. Max7219 would be a good option.

PaulRB:
The problem, I believe, is the parameter of 1480 that is passed to calcIrms(). This causes it to loop nearly 1500 times, reading an analog input and performing floating point calculations in each iteration.

I wonder why there is so much floating-point math in that function. What, if any, valid reason exists not to use fixed-point there?

odometer:
I wonder why there is so much floating-point math in that function. What, if any, valid reason exists not to use fixed-point there?

Younger programmers (for me, that's most of them these days) have grown up using fast CPU with built-in floating point hardware. They don't have an appreciation of the significant overheads of doing the same thing in software. And they would never have been taught how to do integer maths (”when I do the division the answer comes out as zero and it shouldn't be").

Eeeee, they don't know the're born today!

PaulRB:
Younger programmers (for me, that's most of them these days) have grown up using fast CPU with built-in floating point hardware. They don't have an appreciation of the significant overheads of doing the same thing in software. And they would never have been taught how to do integer maths (”when I do the division the answer comes out as zero and it shouldn't be").

Eeeee, they don't know the're born today!

Pfft. It's simple arithmetic.
Or maybe I'm old-fashioned because I still know how to (and occasionally do) divide numbers using pen and paper.

If volts give you floats, calculate in millivolts. Simple as that.

How many digits? How many pins on the display? How is it wired up?

Comment out the Serial business and see if you still get flicker, those interrupts take time.

I recall some code comment for my segment displays saying delays under a whopping 20ms would still be undetectable, so yeah something is wonky there.