I am constructing an electronic circuit that requires a power meter with a voltage signal output that represents the changes in power in a resistive load. It is crucial that the phase of this signal is correct, as the goal is to compare the phase of this signal with the phase of a reference signal further in the circuit (I will spare you the details, but this operation must remain unchanged).
The concept is as follows:
Obtain a voltage signal that represents the value of the current in the load (this part is relatively simple, see the implementation below), compare this signal with a triangular signal using an op-amp to obtain a square signal whose duty cycle represents the value of the current.
Use this square signal to control a switch, the input of which is a signal with a voltage that matches the voltage across the load.
Use a low-pass filter op-amp to calculate the average of the signal coming out of the switch, based on the fact that [value of the average = duty_cycle * amplitude of the input signal].
The basic principle cannot be changed; my question is about how to best implement this idea, not about using a different system.
For the comparison between the current signal and the triangular signal, the duty cycle (between 0 and 1) directly represents the value of the current only if the triangular signal itself oscillates between 0 and 1V (if smaller or larger, a multiplicative and dividing factor is involved). In my circuit, the currents are on the order of a few mA, and variations of this order are barely (if at all) perceived by the comparator. Therefore, I use a resistive divider to obtain a triangular signal with a lower amplitude.
My issue is the following: despite using a fairly responsive filter, I observe differences in behavior between the phase of the theoretical power signal and that of the signal generated by my circuit. Although the amplitude itself is not very important, I am concerned that it might also deteriorate the phase information (which is crucial).
As well as the main signals (current, voltage, theoretical power, power signal), the fluctuations in the current and voltage values come from the overall circuit (it is not important how, I simply provide the graphs to show the difference between theoretical and measured power):
As you can see, at some point the generated power signal decreases, and I don't know why. The phase is still accurate, but I worry that it might not always be the case (could it even induce phase errors in other cases?).
What are your thoughts on this? Do you have any suggestions on how to improve my circuit?