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.

Problem with reading and processing ADC value for a voltmeter

Status
Not open for further replies.

Neveth

Newbie level 6
Newbie level 6
Joined
Aug 17, 2009
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Coimbatore, India
Activity points
1,372
hi,
i m a newbie. And i m having trouble on reading and processing adc value for a voltmeter.
i m building a simple digital voltmeter(0-5v) using PIC 16F887, i having trouble on reading the 10bit adc_result and processing the value into 7 segment.

Pls tell me, how can i read 10bit(ADRESH:ADRESL), what is the data type should i use ? float, integer ? how to convert them into corresponding 7 segment value ?
i ve tried some sample code's available on net, but nothing worked well !

i m using Hi-Tech C complier.

Thanks in advance....
 

  • Like
Reactions: Neveth

    Neveth

    Points: 2
    Helpful Answer Positive Rating
Hi,

Code:
ADRES[H:L] = (Vin/Vref)*[(2^resolution)-1]

So, for 10-bit you have ADRES[H:L] = (Vin/Vref)*1023
That's a maximum of 1023. That's 10-bit, so obviously an 8-bit register won't hold it. You need a 16-bit register. You should use integer, although in some compilers int is an 8-bit data type. There you must use int16. Float is overkill and a huge wastage of memory, you won't even be dealing with anything near 32-bit floating point calculation, just simple 16-bit integer stuff. I don't know about Hi-Tech, so just check the manual, it's either int or int16.

Read the datasheet on the setup of ADCON0, ADCON1, ADRESH, ADRESL, ANSEL and ANSELH for setting them up. Once you've understood that read the value of ADRES[H:L]. This you have somewhere between 0-1023. You have a maximum voltage of 5v, that acts as Vref, so 1023 corresponds to 5v.
So, the display on 7-seg will be V-Vdp1-Vdp2, where V=anything between 0 to 5 and Vdp1 and Vdp2 the decimal points following. Ignoring the decimal point, it's somewhere between 0 to 500 (0 to 5.00 - ignore the DP).

So, 1023 corresponds to 500.
In mikroC, I would do something like:
Code:
 ADCR = ADC_Read(0); //Read off analog channel 0 and write to ADRES[H:L]
corr = (ADCR * 500) >> 10;
So, your output from 0 to 1023 is now scaled down to 0-500.
Convert 500 into 3 characters for sending to 7-seg.
Code:
a(0) = corr / 100; //Get hundreds
a(1) = (corr/ 10) % 10;//Get tens
a(2) = corr% 10;//Get units
Now you have the 3 chars in a(0...2).

Set up a routine to send values to 7-seg and refresh them at a particular frequency, maybe around 100Hz. Send a(0...2) consequently and adjust the power of the corresponding 7-segment through another 3-pins to see the value in the 7-segment. And light the DP pin as well.

Hope this helps.
Tahmid.
 
  • Like
Reactions: Neveth

    Neveth

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top