As promised, the results for the ATtiny85 as AC current detector, i.e. measuring current over a 0.1 Ω shunt.
Yesterday’s setup showed the following values in the display:
30 71-101 68.
From right to left, that translates to:
- it took 68 ms to capture 500 samples, i.e. about 7 KHz
- the measured values were in the range 71 .. 101
- the spread was therefore 30
With a 75 W lamp connected, drawing about 100 mA, I get this:
With the 25 W lamp, the readout becomes:
And finally, with a 1 kΩ resistor drawing 20 mA, this is the result:
As soon as the load is removed, readings drop back to the first values listed above.
Now it seems to me that these readings will be fine for detection. Even a low 20 mA (i.e. 4.4 W @ 220V) load produces a reading with is 30 times higher than zero-load (with about 10% variation over time).
I’m measuring with 2.56V as reference voltage to remain independent of VCC (which is 3.8V on batteries). So each step is 2.5 mV with the built-in 10-bit ADC. With the 20x amplification, that becomes 0.125 mV per ADC step. Now let’s see… a 20 mA DC current across a 0.1 Ω shunt would generate a 2 mV differential. I’m using an order 31 moving average, but I didn’t divide the final result by 31, so that 1099 result is actually 35 on the ADC. Given that one ADC step is 0.125 mV, that’s about 4.4 mV peak-to-peak. Hey, that looks more or less right!
There is still a problem, though. Because half of the time I get this:
Total breakdown, completely ridiculous values. The other thing that doesn’t look right, is that none of the readings are negative. With a differential amplifier fed with AC, one expects the values and signs to constantly alternate. Maybe I damaged the ATtiny – I’ll get another one for comparison. And maybe I didn’t get the sign-extensions right for the ADC’s “bipolar differential” mode. There’s a lot of bit-fiddling to set all the right register bits.
But still… this looks promising!
Update – Problem solved: it was a signed / unsigned issue. The values are now completely stable with under 1 % variation between measurements. I’m not even filtering out high frequencies, although I know I should.