Proton BASIC Compiler - AC Input Circuits

• ### Amazon - Support this community resource

Help support the running costs of the Community Forum. Make your purchases from AMAZON via this Amazon search.

• # AC Input Circuits

It is often required to measure mains AC voltage. Mains voltage varies depending user demand at different times of the day, lower in peak times like when most people prepare food, higher when out of peak times when most people are asleep. It also depends how far you are from the distribution transformer and how many users share the same phase.

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
The '40' value is depending on the speed your pic is going to zip through these steps, you will want it to sample through at least one positive and one negative going mains cycle. The idea is to get the highest value the mains cycle is going to go into HiVal as well as the lowest value that the mains cycle is going to go into LoVal.

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
You don't have to double the A/D value since it is in proportion with the value that you are going to display.

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