pic.programmer
Advanced Member level 3
- Joined
- Aug 19, 2015
- Messages
- 773
- Helped
- 141
- Reputation
- 284
- Reaction score
- 140
- Trophy points
- 43
- Activity points
- 7,531
Here is the latest code I made. The code inside the
condition is correct because if I substitute some known deltaT and find out the PF value then it gives correct result but as the timer value returned is incorrect I am getting incorrect value for PF.
This is the new project for PF Measurement. It uses betwixt's method but it is not working as expected.
I am displaying time between rising and falling edges of the XOR gate output signal o line 4 of the LCD. It is giving wrong timer value.
The working is like this.
Voltage and current ZCD sifnals are fed to XOR gate and also to INT1 and INT2 pins. INT1 is voltage ZC signal amd INT2 is current ZC signal.
Initially only INT1 and INT2 are enabled and INT0 is disabled.
The measurement is using 2 AC cycles.
In the 1st AC cycle the INT1 and INT2 is used to detect whether voltage appeared first or current. After this is done INT0 is enabled and INT1 and INT2 are disabled.
Now INT0 is used to detect rising edge and when detected the INTEDG0 bit is reversed to detect falling edge and Timer1 is started when falling edge is detected Timer is stopped and INT0 is disabled. and process flas is set.
In main loop it is tested if process flag is set and if it is set then PF value is calculated from the timer value and displayed and then again INT1 and INT2 are enabled for next cycle.
If you need more details regarding the project then please mention it.
I was not able to find the bug in the code. Maybe more experienced programmers can find the bug.
- - - Updated - - -
Edit:
I tried to implement betwixt's first method that is analog method of PF measurement but not getting precise
values.
The working is like this.
The output of the XOR gate is passed through a low pass filter which gives a voltage. It is fluctuating in
Proteus.
When there is a difference of 52.5 ms (45 degrees) between voltage and current the voltage at the ADC input is
1.17V (fluctuating between 1.16 and 1.17 V).
Lat's take it as 1.17V.
ADC Calculation is like this.
for 1.17V the deltaT should be 2.5 ms
For 5V adc input raw adc value is 1023.0. Therefore for 1.17V it will be 239.382
So, deltaT = 239.382 * 1.0504202e-2 / 1023.0
= 0.002457983268 = 2.4579 ms which is approx to 2.5 ms
Angle in decimal degrees is calculated using the formula
T = 20 ms (50 Hz)
so, answer is (2.4579 ms / 0.02) * 360.0
= 44.243698824 decimal degrees which is approx to 45 degrees.
This is converted to radians
1 degree = 1.74532925e-2 radians
so,
= 0.77219821685717802
powerFactor = cos(0.77219821685717802) = 0.71637868009896187076245547933012
I have to get 0.707
Where is the mistake ? Is my low pass filter correct ? If not, please provide the correct values for the low
pass filter resistor and capacitor.
Code:
if(process)
This is the new project for PF Measurement. It uses betwixt's method but it is not working as expected.
I am displaying time between rising and falling edges of the XOR gate output signal o line 4 of the LCD. It is giving wrong timer value.
The working is like this.
Voltage and current ZCD sifnals are fed to XOR gate and also to INT1 and INT2 pins. INT1 is voltage ZC signal amd INT2 is current ZC signal.
Initially only INT1 and INT2 are enabled and INT0 is disabled.
The measurement is using 2 AC cycles.
In the 1st AC cycle the INT1 and INT2 is used to detect whether voltage appeared first or current. After this is done INT0 is enabled and INT1 and INT2 are disabled.
Now INT0 is used to detect rising edge and when detected the INTEDG0 bit is reversed to detect falling edge and Timer1 is started when falling edge is detected Timer is stopped and INT0 is disabled. and process flas is set.
In main loop it is tested if process flag is set and if it is set then PF value is calculated from the timer value and displayed and then again INT1 and INT2 are enabled for next cycle.
If you need more details regarding the project then please mention it.
I was not able to find the bug in the code. Maybe more experienced programmers can find the bug.
- - - Updated - - -
Edit:
I tried to implement betwixt's first method that is analog method of PF measurement but not getting precise
values.
The working is like this.
The output of the XOR gate is passed through a low pass filter which gives a voltage. It is fluctuating in
Proteus.
When there is a difference of 52.5 ms (45 degrees) between voltage and current the voltage at the ADC input is
1.17V (fluctuating between 1.16 and 1.17 V).
Lat's take it as 1.17V.
ADC Calculation is like this.
for 1.17V the deltaT should be 2.5 ms
Code:
deltaT = (ADC_Read(2) * 1.0504202e-2 / 1023.0);
For 5V adc input raw adc value is 1023.0. Therefore for 1.17V it will be 239.382
So, deltaT = 239.382 * 1.0504202e-2 / 1023.0
= 0.002457983268 = 2.4579 ms which is approx to 2.5 ms
Angle in decimal degrees is calculated using the formula
Code:
angle_in_decimal_degrees = (deltaT / T) * 360.0;
T = 20 ms (50 Hz)
so, answer is (2.4579 ms / 0.02) * 360.0
= 44.243698824 decimal degrees which is approx to 45 degrees.
This is converted to radians
1 degree = 1.74532925e-2 radians
so,
Code:
angle_in_radians = angle_in_decimal_degrees * 1.74532925e-2;
= 0.77219821685717802
powerFactor = cos(0.77219821685717802) = 0.71637868009896187076245547933012
I have to get 0.707
Where is the mistake ? Is my low pass filter correct ? If not, please provide the correct values for the low
pass filter resistor and capacitor.