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.
If your 0-5 volts at mcu pin is scaled and the actual range = 0-20v then 5 = 20

so 1v scaled = actual 4v

Your adc will produce 1023 raw value for 5v i.e., 20v actual value.

5v scaled = 20v actual = 1023 raw adc value

you can write like 1023 * x = 5

x = 5 / 1023 = 0.0048875855327468

raw_adc_value * 0.0048875855327468 = scaled voltage

if raw_adc_value = 819 then 819 * 0.0048875855327468 = 4.002932551319629 = 4v scaled value

raw_adc_value * 0.0048875855327468 * 4 (in this case) = actual voltage

If that 4v scaled value is multiplied by 4 it becomes 16.01173020527852 = 16v because 20/5 = 4. So you multiply by 4.

eg: if raw_adc_value = 819 then 819 * 0.0048875855327468 * 4 = 16.01173020527852 actual voltage
 
Last edited:

For 0V input - 0bit
20v input - 1023bit
for 1V input - 1023/20 = 51bit
otherwise 1ADC bit = 19.5mV (Fix this as your constant)


For some time assume ADC reading is showing 500bit
To know the input voltage use this formula
Input voltage=ADC bit*Constant
IP Vt = 500 * 19.5mV = 9.75V
 

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

ADR is a 16-bit variable where the ADC result should be stored. I haven't shown the ADC routine here. The results from the conversion will be stored in the ADR register.

>> means bitshift to the right.

>> 10 means bitshift to the right ten times which means divide by 2^10, which means divide by 1024. So, I'm setting the maximum ADC result to be scaled to 200. So, temp will now store a value between 0 and 200:
Code:
temp = (ADR * 200) >> 10;
is equivalent to saying temp = (ADR/1024)*200 mathematically. However, an integer division of ADR/1024 will ruin the calculation in the PIC. So, the multiplication is done first and then the division. Bit shift is used as it's faster than division.

Hope this helps.
Tahmid.
 

Hello,

I am using pic18f4550 for measuring voltage, switching relays, counter etc. straight to the ad port, with reading (VB) on PC screen.
Before I feed AC in I add diode bride and calculate the loses (measure on my power supply) I can feed in up to 60 V dc without any problem.
PIC 18f4550 and PIC18f4520 AD port is same as per datasheet.

AD port.jpgPIC18f4550.jpg
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top