Tutorial for Atmeag8 /AVR based Voltmeter
It measures the Ac voltage and shows readings in RMS value.
Basics Of AC signal
The AC signal ,its amplitude varying in accordance with time. In india AC frequency is 50Hz.
Then the Time period one full cycle ,
T = 1/frequency
T = 1/50Hz = .002second
= 20milli Second
= 10 Milli second for Half Cycle
There are a lot of methods for measuring AC volt digitally
we could find the RMS value by multipliying the Peak Voltage with 0.707.
Vrms = Peak Voltage * 0.707 .
Approximatly Indian Line AC Peak volatge is 325v.
Example :
325v *0.707 = 229.775Volt .(appro = 230Vrms).
But Microcontroller could only sense up to 5 volt as well as it couldnt sense negative values
so we cannot give 230 volt directly to It .
It can be rectify by using a Stepdown transformer ,which has an advantage of safety.
Ac voltage can be reduce by using transformer to comfortable range . (ie 0 to 5volt DC)
make the calculation as ,
The voltage Divider would give a 5 volt when the Vrms 230v. [will be more give details on the way ].
The full wave rectifier output will give to ADC of micro controller . Then do corresponding coding.
Microcontroller Section
we need to mesure only one half cycles repeatedly because the waves same are repeating
Basics
I selected , the F_cpu frequency is the internal RC Oscillator 8MHz.
Atmega8 ADC uses Prescalar [frequency reducer or divider by 2th,4th etc]
Atmega ADC Prescale Frequency is in between 50Khz to 200Kz
ADC conversion time is in between 13 to 260 micro second.
ADC frequency = F_cpu / Prescaler
= 800,000HZ / 8
= 62.5KHz
At high frequency ADC conversion would be fast while at lower frequency the conversion will be more accuracy.
ADC conversion time Calculation
Conversion Time = 1/ADC frequency
= 1/62500
= 0.000016 Second
= 0.016 Milli Second
= 16 Micro Second. [At 62.500KHz]
So 16 mirco second would taken for one cycle of conversion.with 62,5KHz.
13 ADC cycles required for one conversion
ie,
13 * 16Micro Second = 230 Micro Second [approximately]
= 230us.
The Half wave has 10milli second time duration.[100000microsecond].
There the available conversion times is
= Total time period for a half cycle /one ADC conversion time
= 10000 micro second / 230 micro second
= 43.4 samples [ for one half cycleie 10 milli second]
Image Shows only 7 Samples per half cycles .in our case it is 43
And again reduced the sampling to 40 .
calculation of Vpeak
Takes the largest Vpeak from the 40 samples.
Vrms = Vpeak * .707
*****************************************************************************
Atmega8 ADC StepSize Calculation
Atmega8 uses successive approximation adc ,
The Atmega8 ADC is a 10 Bit /[ie the Maximum high value is 1023 =1111111111] at which the ADC will give fullscale Value .
The ADC require a clock as well as a reference voltage .
The resolution of ADC output decide the Step size.
ADC o/p = Vin * 1024 / Vref
Examples;
Vin =5volt , Vref =5volt
ADC o/p = 5 * 1023 /5 = 1023 [ADC highest Value]
Step Size voltage = Vref / 1023 = 0.004887 volt =4.88millivolt
One binary digit changes when 4.88volt changes takes place