It's possible to measure the incoming AC voltage, by proxy. Connect the output of a low voltage AC transformer to a (single diode) rectifier. Depending on the output of the transformer, reduce this with a voltage divider. This half wave signal can then be sampled by an ADC input a number of times with the peak reading being multiplied by a factor to give the AC supply.
Transformer secondary supply = 9V
Voltage divider = 3.18
AC Supply = 240V
9V / 3.18 = 2.83V
2.83V * 1.414 (RMS to Peak) = 4.00V (this means that you WILL need to protect the PicAxe input from the voltage possibly rising above 5V)
240V / 4.00V = 60
The ReadADC10 command gave me a value of ~800 (for an input of 4.00V) so my VoltsFactor was 30. The adjusted ADC value will be 240000, ideal for displaying with a decimal point, with a resolution of 300mV. The reason I don't simply multiply by 3 is that I wanted to cater for voltages of 240V, 220V and 120V, by multiplying the ADC value by 30, 28 or 15 allows this. Assuming a suitably rated transformer primary is connected, with a nominal AC secondary of 9V applied, the ADC value will remain at ~800 (for an input of 4.00V) multiplying this by 28=224V, by 15=120V. With the variable resistor in the divider, the 220V value can easily be adjusted. If I'd used 3 as my VoltsFactor, I'd have had to use more complex maths to compensate for being unable to use 2.8 and 1.5.
In practice, the voltage divider is made adjustable, so that the VoltsFactor is an exactly round figure. Something like a 10k (10 turn variable) in series with a 1k5 to ground, with the wiper of the 10k connected (through a 1k series resistor and diode to the 5V supply as protection) to the PicAxe ADC input. Starting with the wiper in the middle position and then fine tuned to suit. Naturally, I adjusted my units while measuring the supply with a voltmeter, you could always feed the voltage divider with a regulated 5V DC supply. This would give an input to the ADC of 1.57V (5V / 3.18 [No RMS - Peak conversion required for DC]) 1.57V * 30 = 47.1V.
I read the voltage like this:
Code:
For Temp=1 to 40
readadc10 voltspin,VoltsIn
Pause 4
;At 32Mhz, this should sample the volts once per mS,
;with 40 samples taken, that should give two full
;cycles of 50Hz (1/50Hz=20mS), slightly more at 60Hz
If VoltsIn > VoltsPk Then
Let VoltsPk = VoltsIn
EndIf
Next
The VoltsIn value can then be multiplied by the VoltsFactor (and the ADC reference) to calculate the AC supply voltage. For my unit, with an AC secondary of 9V and a supply voltage of 240V the VoltsFactor and ADC reference compensation meant that multiplying the 'raw' ADC value by 30 allowed me to display the voltage to within 300mV.
Once you have the supply voltage this way, you can do as you wish with it, all from within the PicAxe.