taking a percentage of 2 counters

Discussion in 'The Projects Forum' started by rafi21, Oct 9, 2011.

  1. rafi21

    Thread Starter New Member

    Sep 27, 2011
    5
    0
    Im designing a project and im a little stumped on one feature i want to implement.
    how can i take a percentage of 2 counter ICs? or even more elaborated, cascaded counters.
    im using 74LS192 BCD counters and 74LS85 i believe is the binary comparator.

    so how can i take counter#1 and check if it is 75% or higher out of counter#2?


    and another problem i had was that counter#2 would always be 3 or 4 counts or clocks ahead of counter#1 because the way my circuit was designed.
    i did think of taking NOR/AND gates to give a reset to counter#2 by checking if the inputs are 0000,0000,0011 (3 digit bcd) but just wondering if there was an easier way without all those zeros(so it doesnt reset on 13,103, etc..)

    also some side questions, is there a chip that combines BCD counter with 7447 display driver into one chip?

    thanks
     
  2. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    If you are interested in differences bigger than 50%, you could divide the larger counter with another counter and use its output.
    For example, if you want to know if counter A is more than twice as large as counter B, you can compare (counter A)/2 with counter B.
    The comparison can be done with magnitude comparison ICs.

    Another solution, is to convert both outputs to analog, via a DAConverter, and manipulate those signals to your hearts wish.

    If you know the exact number of delay cycles, you can intervene with a few D-Flip Flops. Otherwise, you could check only with the LSB of the first counter only to see when that changes for the first time. Use that to pulse a D-FF with an input that "un-resets" your second counter.

    It would be better if you posted a picture of your circuit, however, and explained a bit about its function.
     
  3. Maen

    Member

    Sep 16, 2011
    12
    4
    You could also include a wired multiplier, rounded down.

    L = floor(0.75*Q)

    I get the resulting vector L with input vector Q (C2's output) (All values above 10 where set to "Don't care" since you use BCD. It will behave erratically if you should happen to input a value >9)

    L0 (LSB)=Q2 \cdot \overline{Q1}+Q0 \cdot Q2 + \overline{Q2} \cdot Q1 \cdot \overline{Q0}
    L1=Q2 \cdot \overline{Q1}+Q3 \cdot \overline{Q1}+\overline{Q3} \cdot \overline{Q2} \cdot Q1 \cdot Q0
    L2=Q3 \cdot \overline{Q1}+Q2 \cdot  Q1
    L3 (MSB)=0

    L is the biggest value below 75% of the value Q from C2

    You then throw it at the 74LS85 : L on input B, Q from C1 on A and check for A>B.

    The big flaw of this is that if you want to change the factor (say to 0.5) you have to reevaluate and redesign the divider. It also require quite an amount of hardware ;)

    After some thinking I came up with a better solution, using "only" a 5 bit(or more, so probably an 8 bit) multiplier.

    The main idea is to transform 0.75 in an integer factor of 2^x.

     \frac{3}{4} -> 3 \cdot \frac{1}{4} -> 3 \cdot 2^{-2}
    This translates into multiply by 3 and shift the result 2 times to the right.

    I assume you'll be using a 8 bit multiplier. Q from C2 goes to the multiplier (first input of the multiplier is a concat of 0000 and Q). Second input of the multiplier is 00000011. if M is the result from the multiplier, the value for the comparator can be read on M(6:3) (bit 6, 5, 4 and 3).

    This method will save you a lot of hardware and by changing the factor of the multiplication from 1 to 3 you can select a range of percentages : 25%, 50% and 75%. If this resolution is not fine enough, you could switch 3 times to the right, and have a resolution of 1/8.
     
    Last edited: Oct 10, 2011
  4. crutschow

    Expert

    Mar 14, 2008
    13,009
    3,233
    A CD40110 is an Up/Dn counter with 7-segment LED outputs.

    But if you use that, there would be no easy way to compare the counts.

    Edit: The easiest way to do the comparison is probably with a microprocessor.
     
  5. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    @Maen

    Your first solution would be problematic. The OP mentions that his numbers will be 3-digit BCDs so a hardwired multiplier would be overwhelmingly large to formulate.

    Your second solution applies, but the result must be processed for some cycles, and thus the result will be delayed. Even worse, unless the process is pipelined, which is ultra-hard, the counters must wait on a slower clock for the multiplier to produce the result.

    @crutschow

    A uC would be nice, if the problem of the very large number of inputs can be solved.
     
    Last edited: Oct 10, 2011
  6. crutschow

    Expert

    Mar 14, 2008
    13,009
    3,233
    True. You likely would have to multiplex the count values into the microprocessor.
     
  7. Maen

    Member

    Sep 16, 2011
    12
    4
    He, you're right, blame the VHDL programmer^^ I though there would be plenty of hardwired multiplier ICs out there, but my expectations where let down by a quick goole search. Anyhow, a frequency divider would do the trick, but a uP (or even a FPGA^^) would probably be much simpler.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Solved:

    Start by tossing the discrete BCD counters.

    Get a micro with:
    2 inputs (the counter inputs)
    12 outputs (3x BCD digits)
    or
    21 outputs 3x 7-segment drivers

    So a max of 23 pins, you can get a micro with that.
     
  9. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    uC pins aren't fully customizable. I don't know many cheap uCs with 23 output pins.

    However, this is going towards the correct direction.

    The OP could use the uC to implement the counting. By using two interrupt pins (commonly found) the counts can be done internally. If the actual count isn't required, then the logic test can be simply displayed.
    If the counts are required, then two 10-bit outputs (or one 10-bit output if multiplexed) are required to communicate the counts.
    Transaction from binary to BCD is rather straight forward from then on.

    All that talk, however, has meaning if the BCD counter ICs are not mandatory.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    A quick search of Microchips 8 & 16 bit devices yielded 176 devices with 24 or greater I/O pins.

    This problem is bugging the $#@% out of me as I think I'm missing some simple way to do it.
     
  11. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    Okay, which namely and at what price? My googling techniques are a bit rusty.

    We need more input from the OP here. It's not productive to talk over unspecified projects.

    Specifications OP! Specifications!

    Have a nice day.
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    This is the page I search from. It can be hard to find, I have to re-find it most time I look. It is their "Parametric Search" page.

    The devices range from $0.78 to $6.08 (volume pricing) with more then half being under $3.

    And screw the OP (unless he comes back), this is a fun puzzle by itself.

    Note: it may be simpler to use extra counters, one holding BCD and another holding straight binary.

    If we say counter 1 = A and counter 2 = B, then we are looking for:

    A >= .75B = 3B/4

    or

    4A>=3B

    Now 4A is simple enough to generate (just re-weight the individual bit lines) but 3B is a tad harder. If the count pulses come in at some max rate you could make some sort of multiple trigger, so 1 pulse in gives 3 pulses out, count those for B, stick to a magnitude comparator (adder/subtracter set to subtract) and easily see if 4A >3B.

    But I'm not happy with that as you need 4-5 chips to do the comparison.
     
    Last edited: Oct 10, 2011
  13. rafi21

    Thread Starter New Member

    Sep 27, 2011
    5
    0
    thanks for all your input guys.
    ill have to re read them and think more about it.

    this is my circuit as it is right now and ive included most explanations.
    im doing this as a final project for class. making a DDR type of game.
    i dont know how to program micro controllers, but i do have a friend who does so i could ask if he can help me out with it. altho i am unsure about the costs and software or languages of these controllers

    the post ernie made right above was one of my ideas, some how using a comparator, is it possible to make a comparator compare 3 sets of data? A B and C? where C would be the %
    but either way to get a percentage you would have to divide the 2 numbers. im assuming it isnt easy to divide or if there is even a chip?

    i hope my additional descriptions with my circuit can help to figure this out.
    thanks again!
     
  14. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    That's nice. What (TF) is that?

    It's not doing division, it's doing subtraction. So the output C is

    C = 4A - 3B

    So when C>=0 the percentage has been achieved.
     
  15. rafi21

    Thread Starter New Member

    Sep 27, 2011
    5
    0
  16. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    I like your idea. One could use an adder circuit to perform the *3 function.
    We could take a clocked adder and feed it its input in one end and 3 on the other. Each time we get a clock the result will be increased by 3.
    In order to make the subtraction, you need to take the 2's complement of 3B. That is as simple as taking the inverted bit string and adding a '1' to it. Then it is ready to be used in a summing IC.
    Check here to see the math behind the method: http://forum.allaboutcircuits.com/showthread.php?t=60499
    You still need 3 extra ICs to do it though, and that's just for 4bit numbers.

    It's still much more economic, in time, space and money, to buy a uC along with its programmer, and program it to do what you want internally.
     
  17. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    The 74LS181 is a 4 bit ALU that does lots of functions (+ and - and more) but a bit pricey for $5 per 4 bits. A 4 bit added is only a buck or so, so it would be cheaper to use inverters to compute a 2's compliment and add instead of subtracting. (Use the carry-in to get the +1.)

    Given that this is a "dance machine" counter, the inputs will appear relatively slowly compared to digital logic. You could take advantage of that by using the "extra clock inputs" to a counter idea and an up down counter. Each "A" sends 4 count UP clocks, each B input sends 3 count DOWN clocks. When the counter output >0 (meaning the highest bit is off) you have the desired comparison.

    However, it's still lots of parts, and the "skill level" is built into hardware and unchangeable. It really wants a micro to do this (said by a guy who could do the complete hardware & software in a day or two).
     
  18. crutschow

    Expert

    Mar 14, 2008
    13,009
    3,233
    A binary rate multiplier, such as the CD4089, will multiply a clock frequency by 1/16 times a 4-bit binary input. So perhaps if you multiply one of the counts by 12/16 with the rate multiplier, and use that for the clock to one counter, you can use that to compare with the other counter that gets the count directly.
     
    Last edited: Oct 12, 2011
  19. rafi21

    Thread Starter New Member

    Sep 27, 2011
    5
    0
    ah it looks like something i can acomplish. my school can provide as many ic's as i need(that is if they have em) i might have to get a extra breadboard with all this extra wireing but isnt a problem to me.

    i just scanned over the CD4089 datasheet, looks pretty cool.
    but if im unable to obtain one of those, i saw something in my book where i could multiply a signal by putting it into a d latch if i remember correctly. so i could make extra clocks by maybe using a one shot 555 timer into a d latch to produce 4 clocks per trigger? and the trigger would come from the push button i would assume.
    am i correct in thinking like this or is there a better way to do it.


    now if i were to make a microcontroller (uC=micro controller =microcomputer=microchip=micro)(all these terms mean the same thing correct?)

    we went over breifly in class how to start to do a logic gate.
    it involves entity, archieture, port. and programing it like X<= (B or C) and D;
    is this what you guys use?
     
  20. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Free chips. Very cool!

    A clocking circuit needs to keep the clocks separate as you can't count up when you count down. While do-able, it would be a tricky piece to design.


    All the same thing. I'm a Microchip user so if you went that way I could help.

    Ugh, I tried em once, actually got an LCD to display "HELLO WORLD" and never touched em again. I never had any formal training on them and would really need to take a course to learn how to use em. They are incredibly powerful devices.
     
Loading...