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.

Help with Dealing 10bit PIC-ADC output value

Status
Not open for further replies.

smartsarath2003

Member level 4
Member level 4
Joined
Feb 12, 2004
Messages
77
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Activity points
1,061
Hai,
I built a 0-30V Power Supply. I want to use a 7-segment display to show the voltage. For that I selected to use PIC-16F876 as it has a 10 bit ADC. The minimum resolution I required for the voltage is 0.05V. I converted 0-30V to 0-5V using a voltage devider network.
I am using assembler for ADC programming and confused with output conversion to 7-segment. I want to display upto 2 decimal places i.e 4x 7-segments

With 10 bit ADC the max value will be 1024, which is a 10 bit value
The actuval voltage o/p will be [(ADC_Output/1024)*5]*6.
How can I accomplish this using assembler :!: Any sujjestions/sample code....

Also I was confused I am a going to round off the value to 2 digits after decimal
My idea after that is clear, i.e storing 4 digits into 4 registers and pass them on to seven segment display
Can anyone help me to get out of this confusion plz...

Thanks
 

Help with PIC-ADC code and resolution

This is not a trivial programming exercise. You need to download or write some floating point routines and some float to string conversions.
This would be a piece of cake if you were to program it in C.
My suggestion, use HI-Tech compiler and write it in C.
 
Re: Help with PIC-ADC code and resolution

Thanks,
Could you please point out some places where I can downloaded that stuff.
Also can one plz post/attach any sample codes with c-compiler, because I used c-compiler just once and that too so simple
Thanks
 

Re: Help with PIC-ADC code and resolution

Hi !

Just to easy your calculations, instead of using a divider voltage network 0-30V to 0-5V, I suggest you to use a reduction 0-51.15V to 0-5V (divide by 10.23).
I explain: you need a resolution of 0.05V in your voltmeter. The ADC has 1023 steps (not 1024). Now, each step will have 0.05V. The maximum value that can measure is 1023 x 0.05 = 51.15V. When you set the output to 30V, the ADC will measure the value 600 (in the 2 registers ADRES). So you have a rounded step and facilitate your formulas (to find the real voltage, divide ADRES by 20).
You can use a trimpot to adjust the divider voltage network with an external voltmeter to help calibrate.

Scale will be:

0V = 0V in the input of ADC = 0 in the registers
0.05V = 0.05 / 10.23 = 0.0048876V in the ADC input = 1 in the registers
1V = 0.09775 V in the ADC input = 20 in the registers
3V = 0.293255V in the ADC input = 60 in the registers
10V = 0.9775V in the ADC input = 200 in the registers
30V = 2.93255V in the ADC input = 600 in the registers
 
Re: Help with PIC-ADC code and resolution

Hi

You can use CCS PIC C software to make your code like this:

Code:
long ADC_Output ;   // is ADC´s result
float c;   // c is result of voltage calculation

c=[(ADC_Output/1024)*5]*6

printf(%2.2f,c);  //print c float result with 2 int plus 2 decimal

Best regards
 

Re: Help with PIC-ADC code and resolution

hai rkodaira,

Thanks for your idea. I think this works in the same way I need.
But the actuval confusion lies in dealing with 10-bit result. i was able to design code upto 8-bit,but confused with 10-bit value :?:

Is there any algoritham/method that already exists for this type of problem

Thanks
 

Help with PIC-ADC code and resolution

You just treat the 10 bit value as an int, which is two bytes in most c compilers for the pic. So you have to use 16 bit routines for your multiply and divide. The pic stores its int's in little endian format,
 

Re: Help with PIC-ADC code and resolution

Hi,

Have a look at this app note from Microchip.
Hope it help.
Good luck.

Do not upload things available at internet.
Application note AN557 can be DL from MicroChip
Next time you get a warning.
Cl
 

Re: Help with PIC-ADC code and resolution

I was able to finish up for 8-bit output of the adc
Here is th place where i got the algorithm

https://www.convict.lu/Jeunes/Math/Fast_operations.htm
https://www.convict.lu/Jeunes/Math/Fast_operations2.htm

But i couldn't understand their code, so did in my own way

But still havn't got any clue regarding 10 bit value :roll:
As I learnt the 8-bit ADC I want to try it out using C-compiler as well. If any one have any good notes/docs regarding how to program using CCS c-compiler, can you plz post here.
And can I deal the 10-bit value with c-compiler atleast
Thanks 8)
 

The easiest way to go is to create a look-up table and read results from there. This way you don't need to use any mathematical operations and you can operate on as many bits as you like.
You can convert 10-bit to 16-bit (2 bytes) number with MSB = 000000XX ..
 

I have two 8-bit registers that had the output value.When the result is 0-255, the most siginificant register is 0x00. So I can do any operations upto there on the first register.As said by rkodaira, the Actuval Output voltage =ADRESHL(least sigificant byte)/20
The trouble is how to tackle it if the result is greater than 255, which spreads in two registers

For lookup table, I need a resolution of 0.05V from 0-30V. i.e 600steps. So I can't really fallow look up table.
Any more Ideas :!:
 

Hi Smartsarath ! Thanks for the points.

I usually use the ADRES with ADFM left justified:

ADRESH = 8 bits more significant and
ADRESL = 2 bits less significant (shifted 6 times left).

But in your case, I think it is better to use right justified (ADFM = 0):

ADRESH = 2 bits more significant
ADRESL = 8 bits less significant

Your end of scale will be 30.00V = 600 in the ADRES (2 bytes).

Just move the result to another 2 variables (8 bits each). let´s say:
MSB and LSB

So I said to divide by 20 to get the result in volts. But the result must hold the fractionay part (two positions after decimal point). So instead of divide by 20, multiply the result by 5 ( ( x/20) * 100 = x * 5, use 8 bit x 8 bit routine) . This way you have the fractionary part held in the 16 bits integer variable.

For example, 30V = 600 dec:
ADRESH = 0000 0010 = 2 dec move to MSB
ADRESL = 0101 1000 = 88 dec move to LSB

Multiplying LSB by 5 = 1 1011 1000 bin or carry = 1 and 184 dec in LSB
Multiplying MSB by 5 = 0000 1010 = 10 dec
Add carry to MSB: 10 + 1 = 11 dec (0000 1011 bin)

So you have: 11 * 256 + 184 = 3000 dec in MSB and LSB or 3000 centivolts

Just use a routine to separate decimal digits into 4 variables (8 bits each). Search for this routine) and shift the decimal point two positions (from left or right).

I hope this helps. Good luck.
 

I got that, but where does the carry goes when you perform operations that output more than 8 bits, i.e 5*88, 11*256 or (11*256)+184.
As far as my knowledge, I know only carry flag will be set. What about the actuval value of the carry. Does it actually stored in any spl registers! I didn't cared about this carry bcos I never worked with such a large numbers

Just use a routine to separate decimal digits into 4 variables (8 bits each). Search for this routine) and shift the decimal point two positions (from left or right).

Also does it mean there are pre-existed routines to do this job

Thanks
 

Hi ! It´s me again.

In the multiplication routine, you have to use some register to store the carry(ies) (even if greater than 1), every time the carry is set after one step in the multiplication routine, you must increase this temporary register (RAM). After, this must be added to the MSB (after the multiplication by 5). I think that the largest carry will be 4 dec (100 bin), because 5 * 255 = 1275 that divided by 256 = 4.98...

Yes, there are some routines to convert binary format to BCD format or something like this.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top