I might just add a FPU chip to this project and call it done.......
No, No don't do that. Just a few modifications and you're there.
OK, let's start with the Amp routine.
The way is is now, it takes 10 samples, averages them by dividing the total by 10.
Then after multiplying by Quanta (convert to voltage) it multiplies the result by 10 again.
So the last digit (1mv) would always be zero.
Instead, let's let the accumulation of the 10 samples be the * 10. Then you don't need to divide and multiply later.
10 samples of 1023 would be 10230 max.
*1250 (quanta) / 256 = 54946 max (54.946 VDC). So it's still within the Word limit.
So now it looks like ...
Code:
Amp:
Average=0 ' Clear the Average variable befor use
For Samples=0 to 9 ' We will take 10 samples of the ADC
ADCIN 0,AD_Raw ' Place the conversion of channel0 into AD_RAW
Average=Average+AD_Raw ' Build up the Average result
Next ' Close the loop
; Average=Average/10 ' Calculate the average by dividing by the number of samples taken
AD_Result1=(Average) */ Quanta ' Quantasize the result
; AD_Result1=AD_Result1*10
amps= AD_Result1/1000 ' Calculate the Amps part of the result
Milliamps=AD_Result1//1000 ' Calculate the Milliamps part of the result
IF Milliamps < 60 THEN
Milliamps=Milliamps-Milliamps
ENDIF
RETURN
Now for the volts, it's a similar situation, except the multiplier is 11.
So if you take 11 samples, instead of 10, then again, it doesn't need to divide and multiply later.
Code:
Volt:
Average=0 ' Clear the Average variable befor use
For Samples=0 to 10 ' We will take 11 samples of the ADC
ADCIN 1,AD_Raw ' Place the conversion of channel0 into AD_RAW
Average=Average+AD_Raw ' Build up the Average result
Next ' Close the loop
; Average=Average/10 ' Calculate the average by dividing by the number of samples taken
AD_Result=(Average) */ Quanta ' Quantasize the result
; AD_Result=AD_Result*11
Volts= AD_Result/1000 ' Calculate the Volts part of the result
Millivolts=AD_Result//1000 ' Calculate the Millivolts part of the result
RETURN
And finally to get Watts, we need to drop one of the values down (/10), I chose amps, no particular reason.
At the maximum values, Amps will be 4995 (49.95 amps), and Volts will be 54946 (54.946 V).
Multiply those 2 together, then DIV32 by 10,000 and the maximum result is 27445 (2744.5 Watts).
Here's the last part.
Code:
Watt:
AD_Result1 = AD_Result1 / 10 ' Scale amps down to 2 decimals
AD_Raw=AD_Result*AD_Result1
AD_Raw = DIV32 10000
W = AD_Raw / 10 ' Calculate the watts part of the result
Milliwatts=AD_Raw//10 ' Calculate the Milliwatts part of the result
' resolution is 100 milliwatts (0.1W)
' max = 2744.5 Watts
Return
This time I tested it. 
HTH,
Bookmarks