Michel
I found on google that the i2c speed for the atmega (at least the ones
running arduino) is around 4705 bytes per second. The INA219 requires
2 bytes to be read each time.
Unfortunately this is way less than 8192 Hz already.
If I understood the INA219 datasheet correctly, the A/D frequency for
10 bits is < 7 kHz, so even if one can implement a faster i2c it will
still be less then ~8 kHz.
If using the A/D pins on the atmega it gets even worse: less than 5
kHz.
So I decided to test speed first, before implementing a rectifier on
my circuit. I wrote a simple code to make 1000 readings and display
the time it took to make it. I am pasting the code at the end of the
message just in case someone finds this absurd and is willing to check
how I did it. Of course I used the nixies instead of a boring console
terminal to display the results:
http://tobiasmugge.files.wordpress.com/2012/06/dscn4055.jpg
1.125 ms to read the i2c, do the square sum and watch for the encoder.
1.114 ms to read the i2c and do the square sum.
0.554 ms to just read the i2c. Or 1,8 kHz. Not that far from the value
I found as max on the internet.
So less than 900 Hz. Or 14 points during the period of a 60 Hz signal.
Is that enough information for a 60 Hz signal?
The code:
case 3:
unit = 4;
scale = 6;
reading = millis();
for (int x = 0; x < 1000; x++){
//result = r.process(); //reads encoder
//if (result && (result == DIR_CW ? ++state : --state) > 3)
state = 0; //switches between the cases
//sum += sq(dmm.getBusVoltage());
result = dmm.getBusVoltage(); //reads the two bytes from the
INA219 and performs basic conversion to get value in mV.
}
reading = millis() - reading;
After that I just show the reading+scale+unit at the screen
Tobias
On 4 jun, 18:42, Cobra007 <
mic...@xiac.com> wrote:
> You should capture your measurements in an interrupt routine, maybe
> 8192 or 16384 times per second. Square them and add them to a
> summarizing register (choose 32 bits). Then once every second, divide
> the summarizing register by 8192 (or 16384) which is the same as
> shifting them right by 13 or 14 bits and then take the square root
> from this number.
>
> It would look like:
> sum += sqr(measurement)
>
> then once a second:
> result = sqrt(sum >> 13); sum = 0;
>
> Dependent on your A/D resolution, you may have to divide the
> measurement by 2 or 4 to avoid the sum to overflow (like sum +=
> sqr(measurement >> 1). You could also calculate the result twice per
> second to avoid overflow.
>
> That is pretty much it, I think.
>
> Michel
>
> On Jun 4, 10:11 pm, Tobias <
tobiasmu...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Thanks everyone.
>
> > jb-electronics: I draw my one, including the fuse and the shunt with
> > traces for up to 5A continuous, filter following datasheet
> > recommendation, i2c address smd jumpers and connectors for power and
> > i2c.
> > are you at Germany or the US? Take a look at the photo and let me know
> > if you are interested. We can work something out.
http://tobiasmugge.files.wordpress.com/2012/06/dscn4054.jpghttp://tob...