
This is a transformer (You wouldn't have guessed)
Sorry, but I need to explain something. As you can see there is a ratio of 20:1 for the transformer to step the voltage down from 240VAC to 12VAC.
It does not matter if you use a ratio to step the mains down with a transformer or use a voltage devider directly from mains 240V which also has to have a ratio to finally get the voltage you require to be between 0 and 5V. The ratio any way you look at it is 240V, to within the measurable value for the pic.
Measuring mains directly requires that neutral be connected to the circuit common or 0V.
Using a step-down transformer however makes the circuit safe to use. A serious point to consider.
Iron core transformers are usually good for up to about 400Hz.

This circuit would enable you to measure the full 360 degrees of a mains cycle. The fact that the negative going mains signal is going to be a bit lower than the positive going mains cycle is going to go positive on the A/D input pin, doesn't matter, the pic can compensate for that very easy.
For Temp = 1 To 40 Step 1
Vin = ADIn 4 ' get value
If Vin > HiVal Then HiVal = Vin ' retain higest value
If Vin < LoVal Then LoVal = Vin ' retain lowest value
Next Temp
Vin = ADIn 4 ' get value
If Vin > HiVal Then HiVal = Vin ' retain higest value
If Vin < LoVal Then LoVal = Vin ' retain lowest value
Next Temp
To calculate the voltage
Vin = HiVal - LoVal

This is another circuit to measure the AC voltage with. Since the negative cycle is the same voltage as the positive cycle (around here anyway) you can just as well measure the positive going cycle and convert it to a DC signal using a diode pump amd smooth it with a cap. This is good for general measuring purposed if you're not going to worry when one or two peaks is a bit lower than the next when your neighbour started his electric lawn mower.
Vin = ADIn 0 ' Measure half the mains voltage

Another way to get a voltage ratio in AC is to use a capacitor devider. Note that capacitors work the other way round from resistors. The bigger value should be to ground and the smaller value on the input. You will read only the 50 positive going mains cycle since the transzorb shorts the negative going cycle to ground. And yes, you can replace the caps with resistors
To measure the negative going cycle also, disconnect the transformer from ground (see first picture) and connect a diode bridge to the AC output. Ground the diode bridge negative and the positive of the diode bridge goes to the circuit input. No smoothing caps on this diode bridge, and you will now get 100 positive going signals per second you can measure and play with. You have to replace the caps with resistors here, or they will become smoothing caps.

Yet another capacitor devider input. This time a diode pump which also makes a dc signal you can read with the A/D input. For mains, the schotkey diode can be a normal diode.
This circuit shows a schotkey diode which enable you to read high frequency AC volatges, like that from a function generator. Keep in mind that capacitors looks like a short circuit to high freqiency, so replace the two left capacitors with resistors instead. A normal si diode will only work up to a few kHz before it gives up.

Almost the same as the first circuit, but with a capacitor devider.
Compliments Fanie


Menu
Recent Articles


Using PDS with SPI GLCD based on ST7565R Controller
Graphic LCDs based on the ST7565 are cheaper then GLCDs with other controllers. SPI requires only four pins. If the circuit