The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Hello. I need a function that gets the digit from a number with only using *,^,+,- and the mod operator.

This function works, but it contains divide.

placement = to get the number from the end of the number to the right of the number

mod(floor(number/10^(placement-1)), 10)

This function works, but it contains divide.

placement = to get the number from the end of the number to the right of the number

mod(floor(number/10^(place

mod( 10^-1*(N - mod(N, 10))) will give you the second digit

mod( 10^-2*(N - mod(N, 100))) will give you the third digit

mod( 10^-1*(N - mod(N, 10)), 10) will give you the second digit

mod( 10^-2*(N - mod(N, 100)), 10) will give you the third digit

then the following formula should work for digits of any length.

mod( 10^(1-p)*(N - mod(N, 10^(p-1))), 10) will give you the p-th digit

Using the operators and functions you have specified, you can isolate any part of the number.

If N= 8754

mod( N, 10) = 4

mod( N, 100) = 54

mod( N, 1000) = 754

mod( N, 100) = 54

mod( N, 1000) - mod( N, 100) = 754 - 54 = 700

You need a division to extract the digit "7" from 700.

You can divide by 100, or multiply by 10^(-2), or take 10^(log(700)-2),

or shift the character string two places to the right.

But all of those operations are equivalent to division.

Where is this restriction against division coming from??

What are you trying to do?? Exactly.

It may be related to his Microchips question http://www.experts-exchange.com/Hardware/Microchips/Q_22042188.html, which you may know something about.

I have a thread about it here:

http://www.experts-exchange.com/Hardware/Microchips/Q_22042188.html

http://www.experts-exchange.com/Hardware/Microchips/Q_22042188.html

If you have four digits, you have to set up at least a 2-bit counter (0-3) to drive the common (anode or cathode) for each digit.

And you have to set up a logic function for each segment.

I have done this in a CPLD using CUPL. It is slightly hairy, but not really that hard. I copied each digit to a 4-bit buffer register to simplify the logic for each segment.

You should thing about the timing before you start writing code.

But this is digital logic/multiplexing problem, not a mathmatical problem.

The logic goes something like this:

If Count = 0 copy Digit_1 to BCD_Buffer

If Count = 1 copy Digit_2 to BCD_Buffer

If Count = 2 copy Digit_3 to BCD_Buffer

If Count = 3 copy Digit_4 to BCD_Buffer

Anode_1 = Count:{0}

Anode_2 = Count:{1}

Anode_3 = Count:{2}

Anode_4 = Count:{3}

Seg_A = BCD_Buffer: {0, 2, 3, 5, 7, 8, 9} /* Top Segment */

Seg_B = BCD_Buffer: {0, 1, 2, 3, 4, 7, 8, 9} /* Upper Right Segment */

:

:

:

Decimal A B C D E F G DP

0 1 1 1 1 1 1 0 1

1 0 1 1 0 0 0 0 1

2 1 1 0 1 1 0 1 1

3 1 1 1 1 0 0 1 1

4 0 1 1 0 0 1 1 1

5 1 0 1 1 0 1 1 1

6 1 0 1 1 1 1 1 1

7 1 1 1 0 0 0 0 1

8 1 1 1 1 1 1 1 1

9 1 0 0 1 1 1 1 1

In particular, where does your 12-bit vector come from?

If you are counting something, that you need to display on a 7-segment display,

it would definitely be worth your while to use a BCD counter rather than a binary one.

If you don't have control of the input, i.e. you get a 12-bit binary number from someone

or somewhere else, then you probably have to convert the 12-bit binary data to BDC.

Once again, this is tedious but not difficult. You need 15 or 16 equations for the BCD digits.

12-bit binary ==> 0-4095 so the MSB for the thousands digit is always 0.

Since you have asked about VHDL, I am assuming that this is a FPGA or CPLD project. Correct?

If you have the option, it might be easier to do binary to BCD conversion with a microprocessor than with logic.

And how fast do the digits have to change?

It's a FPGA project. The digits could change arround 50 hz.

You have a 4-digit seven-segment display.

Is it multiplexed, wth 7 segment lines and 4 common anode (or common cathode) lines?

Or does it have 28 (4x7) segment lines?

Another way to solve this problem is to use look-up tables.

You would need four 4095 x 8-bit tables, one for each digit.

1888 ==> 0000 0110 0111 1111 0111 1111 0111 1111

This might be the best way to program an FPGA. I don't know for sure.

Yes. It has 4 common cathode line and 7 segment lines and one extra segment line for a dot or point or something.

cathode, segments

0111 1011 1111

would give me zero on the first digit from left

Another way to convert 12-bit binary to 4-digit BCD is to count it.

You would load you input data into a binary down counter.

You would load 0000 into a BCD up counter.

Then you would clock both counters until the binary counter is all zeros.

This would take approximately 0.4 ms with a 10 MHz system clock.

The is negligible as far as the human eye is concerned.

Once you have the data converted to BCD, you would display it as I suggested in my earlier post. [ 01:26PM EST ]

This approach will probably result in the simplest and shortest code.

I won't be able to help much with the VHDL though.

One thing you might try to get you started is to try displaying the 12-bit vector

as three BCD characters.

I'm guessing that this project in on the order of 100 lines of code and several full days of work.

A^(-B) = 1/A^B

So what's number * 10^(-(placement - 1)) ? :)

Shifting the decimal point to the left, truncating the stuff to the right, and taking mod 10 seems like a way to get any digit to me.

There is no simple way to convert a binary number to decimal.

One kloodgy way would be to take your 12 bit input, store it into a count-downable register, and then count it down to zero while you count up a BCD register. Not very fast but doable with just a few chips, so I assume it's programmable in VDHL.

If you must do it really fast, and it's only 12 bits, you could use a 14-bit address by 8-bit wide EROM (16K bytes). Feed in 12 bits of the number and two bits of the digit you want and voila, out the data lines come your 7-segments (plus an exta bit for whatever else you want to do).

int placesize = 10^(placement-1) /* assumes placement=1 means ones digit */

n = n mod (placesize * 10); /* gets rid of digits above our desired digit. Don't care about smaller digits */

result = 0;

while (n >= placesize) {

n = n - placesize;

result = result + 1;

}

result is now the digit you're looking for.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

?