Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

voltage measure using pic mcu

Status
Not open for further replies.

srjth.m1

Full Member level 3
Joined
Aug 6, 2012
Messages
157
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Location
India
Activity points
2,126
am using pic18F4520,i want to measure A.C voltage max up to 20v am using a voltage sensor circuit(voltage divider by resistor) externally,it is giving to one of ADC pin,the thing i didn't understood is MCU can only accept 5v then how it is measuring the voltage ?Anybody explain?
 

Maybe the voltage sense circuit is scaling your 20v AC to 5v DC. Post your circuit.
 

I have already given you a link to a thread that has several solution to the problem so consider reading it first.
 

now i understood the concept,now how can i program this formula?

i mean "Vin * R2/(R1+R2) =Vin * 666/ (10000+666)= Vin * 0.0624
if Vin=40 then R2=40v * 0.0624 = 2.496v"
can you just give an example code?
 

To convert to DC put a diode at the output of your potential divider and zener circuit. It you are using 10bit adc then the max value will be 1024 i.e., 0-1023

your i/p will be 0-5v and adc value will be 0-1023.

So for 5v ---------- (1023 * 5) / 1023 = 5 will be the answer.
 

so if my input voltage to the divider circuit is 20v then it will show in LCD?
 

Your 0-20v will be scaled to 0-5v.

If 5v scaled = 20v ac = 1023 adc value.

5v = 20v = 1023

you can write like 1023 = 20

1023 * x = 20

x = 20 / 1023 = 0.01955034213098729227761485826002 = 0.1955

adc_value * 0.1955 = answer.
 

in this case what will show my LCD it will be up to 5V or up to 20V?
 

sorry to asking you again i understood that we can reduce the voltage by voltage divider then by vin(r2/r1+r2),and we get output as 5v but how this voltage again become my input voltage(20v)and showing in LCD? whats the calculation?
 

You scaled the voltage down in hardware and so, need to "scale it up" by software.

eg. Let's say the ADC result is stored in the register ADR, and that the scaling ratio is 4:1 (20V:5V).

Code:
unsigned lont temp;
temp = (ADR * 200) >> 10; //value of temp is between 0 and 200

Now temp stores a value indicative/representative of the input voltage: the input voltage * 10. If input voltage is 20V, temp stores 200. If input voltage is 10.5V, temp stores 105. If input voltage is 8.5V, temp stores 85. If input voltage is 0V, temp stores 0. And so on.

Now, you just need to manipulate temp as required to get the output to display.

Hope this helps.
Tahmid.
 

ok understood...can you explain the calculation in the coding?what is ADR?
 

the adc result is stored in two registers ADRESH and ADRESL. H in ADRESH is high byte and L in ADRESL is low byte. ADRES means A to D Result register.

You set ADFM bit to 1, so your ADRES register justification will be like the left one in the image i.e., right justified.
 

Attachments

  • a2d.jpg
    a2d.jpg
    101.9 KB · Views: 73
Last edited:

the adc result is stored in two registers ADRESH and ADRESL. H in ADRESH is high byte and L in ADRESL is low byte. ADRES means A to D Result register.

You set ADFM bit to 1, so your ADRES register justification will be like the left one in the image i.e., right justified.

all these things now i understood in detail,still my problem is how this calculating practically

for making 16 to 5v we are using some hardware based on Vref=vin(R2/(R1+R2)),like that some calculation will be there know to convert that am telling what is that?
 

From where did you get that formula Vref=vin(R2/(R1+R2))? Are you using Vref? If yes, what is your Vref voltage and what is the voltage range you want to measure?

Post your project files.
 
Last edited:

my problem is that how to converting this scaled voltage to original,many of you trying to help still i am in doubts...!!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top