Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Counter with Radix 12

Hi ! Im an engineering student and new to VHDL and Quartus, i can get my way around to some extend but im having difficulty understanding this specific problem.

I would like to create a counter of RADIX 12 that counts up to 7B9. With my understanding 7B9 in Radix 12 means 1137 in Decimal and 10001110001 in binary. I would have no trouble using D-Flipflops to reach this number. What i would like to know How we can convert One Radix to another (Radix 12 module to Binary). I just need a little push so i can get going ! Any one with any suggestions !

Thanks !

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I suggest using multiple counters(one per digit):

    count1: 0 ~ 11 then at overflow increment count2: 0~11 and so on

    The rule as I see it is: decimal number * 10/12 => your new radix 12 value

    another way is to run a decimal counter from 0~120-1 as usual then interpret every 12 counts as 1 for your new radix thus use that to increment a new counter
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The rule as I see it is: decimal number * 10/12 => your new radix 12 value

    --- Quote End ---

    Not quite. In C:

    
    int decval = 1137 ;
    radix12 nr12 ;
    int i = 0 ;
    while ( decval /= 0) {
        nr12 = decval % 12 ;
        decval  -= nr12 ;
        decval /= 12 ;
        ++i ;
        }
    

    decval = 1137 will result in nr12[] = { 7 , A , 9 } (7 * 12**2 + A * 12**1 + 9 * 12**0 = 1137)

    where 1137 * 10 / 12 gives us 947.5

    If you translate the C-code in VHDL you will get confronted with the mod and the / operator generating quite a few dividers (and subtractors) if you keep the conversion combinatorial
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks JosyB. Indeed my initial guess assumed linear relation but it is not so. It is equal from 0~radix then gets sudden glitch.

    I assume the following algorithm will work:

    if your input is say 1137 then run a decimal counter from 0 till 1136 and stop.

    run also say 4 counters (for four digits) from 0~11 in cascade i.e. when first counter reaches 0 increment the second and so on.

    When counting finishes then read the 4 digits(output of four counters as 0~B