How to convert 10bit ADC data to BCD?

How to convert a 10bit digitial signal to three groups of BCD?

For example, the value of 10bit digitial is 789 in decimal.

I would like to ask how to take 7, 8, 9 away and convert each digi to BCD?

p.s. BCD is needed to display a 7-segment display via "BCD to 7-segment display converter" 74LS48

I am going to use BASIC with Atmel AT90S8535 to do the task.

Thank you very much

Reply to
sommes
Loading thread data ...

2 ^ 10 = 1024 10x10x10 = 1000

You cant.

Reply to
Simon Scott

BCD?

...unless you work over 000 --> 999 and throw away the top 24 counts - which may be entirely acceptable in your application.

Go to

formatting link
and search for the algorithm you need then code it to suit your micro. Google usually helps.

Have you considered not using the 74LS48's and driving the displays directly with 3 pins to multiplex them? I'm not familiar with the micro you are using but it may be an option and save you some parts.

Reply to
Rob

Thanks rob and simon,

In case, I can ignore the bit which is over 999 and set the range as 000 to

999
Reply to
sommes

Best you ignore the bit over 1012, and under 12 :)

Reply to
Simon Scott

I dont know basic but you want to use the division and modoulus (remainder after division) operators.

units = adc value modulus 10 tens = (adc value / 10) modulus 10 hundreds = (adc value / 100) modulus 10

Reply to
DAC

Best you scale it to 1000 from 1024!

Reply to
DAC

in some versions of BASIC you can do this

ones=number mod 10 number=number \ 10 tens=number mod 10 number=number \ 10 hundereds=number Bye. Jasen

Reply to
Jasen Betts

Thank you DAC.

Could you tell me some more why "scale it to 1000 from 1024" is more suitable?

Thank you very much

Reply to
sommes

depends on the type of data really, but point taken :)

Reply to
Simon Scott

789/1000 = 0 r789 - thousands 789/100 = 7 r 89 - Hundreds 89/10 = 8 r9 - Tens r = 9 - Units

Discard the upper nibble in 00,07,08,09 and there you have it the BCD result ... Magic aint it - of course I am presuming the Basic you are using can do reasonably efficent division but either way most division routines will do this division in less than 10 loops per routine.

the BCD output could take 12 I/O lines from the micro so why not add a 7 segment look up table to your Code and drive the display directly from the - as this at worst will use 11 and save the cost of more chips .... although if you matrix the output properly I guess you get the output down to 8 lines using the 74LS48 - I just feel that if you have the I/O spare then doing the seven segment encoding in the micro is more elegant.

Regards Richard Freeman

Reply to
Richard Freeman

A technique use before the days of uproc was to have 2 counters, a binary countdown counter and a bcd countup counter. The binary value is loaded into the countdown counter and it was counted down to zero with the same count pulses counting up the bcd counter. When the countdown counter hits zero the bcd counter as the correct value.

The same concept can be used if you are programming in assembly code instead of a higher level language with math functions.

Dan

Reply to
Dan H

Thank you for all the kindly reply

Reply to
sommes

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.