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.
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?
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 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").
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.