Yeah, that seems a bit slow indeed. I would normally program that in assembler but maybe the 16x16 squaring is taking a bit of processing time. If you would do that interrupt based, it is most likely going to chew up a bit more capacity as well.
900 samples per second .... 15 samples of a 60Hz signal, doesn't sound like much. Maybe sample 2 seconds or 4 seconds to get a better average? Michel On Jun 5, 1:08 pm, Tobias <[email protected]> wrote: > 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 <[email protected]> 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 <[email protected]> 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... > > > > Cobra007: I can definitely try that out! I know how the math should > > > look like on the paper, but I have no idea how to implement this on > > > the controller. I would think it uses a time interrupt to capture the > > > measurements at at pre-defined rate, log some of the last readings.. > > > and then what? If you give me some hint regarding a C implementation > > > of the math I can start working on that! =) > > > I searched for an arduino implementation but I could not find one that > > > made me happy. > > > > Grahame: Nice, they even give you the source code! I'll have to login > > > and take a look =) > > > > On 4 jun, 06:11, Grahame Marsh <[email protected]> wrote: > > > > > On 04/06/2012 00:05, Tobias wrote: > > > > > > I am trying some R and C measuring designs on the breadboard but > > > > > nothing too promising so far. > > > > > Tobias, > > > > > For capacitance you might look at these Elektor projects: > > > > > Low > > > > rangehttp://www.elektor.com/magazines/2011/april/pico-c.1738839.lynkx?tab=1 > > > > > High > > > > Rangehttp://www.elektor.com/magazines/2003/february/autoranging-capacitanc... > > > > > In both cases they are not much more than a TLC555 timer (the design is > > > > a bit fussy on which manufacture's 555 is used) that the controller > > > > measures the period of and then calculates the capacitance. > > > > > Project is looking good... > > > > > Grahame -- You received this message because you are subscribed to the Google Groups "neonixie-l" group. To post to this group, send an email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/neonixie-l?hl=en-GB.
