From what I read it seems that it is not meant to be used as wattage meter just to measure peak voltage and peak current. I want to make circuit that measure watts continuously while music is playing.
I probably shouldn't worry about accuracy that much but I still have to test that on real power to see how it perform.
Protection wise I would like to implement something that if overvoltage happen that it doesnt destroy the circuit.
You already know, or can measure the resistance of the speakers. When you measure the voltage peaks, you can compute the current using Ohm's law. Then compute the instantaneous power from the volts and amps.
Speaker impedance is all over the place. If you want the actual power, need to measure voltage and current and relative phase and calculate real and reactive power.
You are sampling a 32Hz signal at 13.3Hz rate and hoping that one of the samples will be at the sine wave max value and another at the min value. It may happen, it may happen once an hour, or it may never happen.
A true measurement of what though? An audio amp tries to approximate to a voltage source, so if you measure the voltage across a resistive load the power is just Vrms^2/R. But so what, isn't that what you expect? If you just measure the resistance of your speaker with an ohmmeter you see the DC winding resistance which is somewhat less than the actual "impedance". Any voltage across that just makes it hot without contributing any audio power. The actual impedance is higher, because of the motional resistance which does contribute to sound power, the coil inductance, and various resonances in the cone and enclosure.
This curve is the modulus of a measured speaker impedance so it doesn't say anything about the reactive and resistive parts - the site suggests that the nominal impedance of the speaker could be said to be 6 ohms but clearly if fed from a constant voltage the actual power input to the speaker will be a lot less at most frequencies, and the sound power out less still. The other thing is that the current may be up to 90 degrees out of phase with the voltage across the terminals, which can play havoc with the amp output stage.
I guess what I'm saying is that the peak output voltage into a resistive load or an actual speaker you should measure will be a bit less than the supply voltage, leaving enough headroom that the transistors don't saturate and distortion is within limits. What that translates to in terms of actual acoustic power depends entirely on the speaker.
Actually, a speaker is a motor with back EMF that has to be accounted for. That will be out of phase with the driving current. So measuring both will be very complicated!
@Wawa I added current measurement to the code and tried measuring wattage and it works pretty good! even with arduino nano ADC. Only thing that I would like to improve is response time of the code. I get every around 390ms new measurements. If we could lower that too around 200ms that would be great! Not sure if ads1115 will improve the speed or I should use esp32 with faster clock speed?
I tried again your link and it seems to work both for current and voltage but I can't calibrate voltage measurements to match my dmm.. It seems that after it reach 7v it barely goes up.. any idea?
Why don't you just measure supply voltage and current draw of the amplifier.
Class-AB (your amp) has a known efficiency curve, so output power can be calculated from that.
You should be able to look that up.
Leo..