Forum Discussion

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

using multiple conversion statements

I'm trying to pass an integer through multiple conversions.

i placed an integer counter (mone) of 0 to 9

Which i control with a push button(that act as a clock_in).

i basically need every time that i get a new integer(0 to 9)

lets say 3 for example to multiply by 0.000305(same as 61/200000).

and then convert the result integer to std_logic_vector 16bit.

it eventually will go to an D/A the has a resolution of 2^15.

the code is fine if i run compilation.

but don't see the result in the simulation waveform.

or in the leds in my cyclone 2.

you can see the code and the simulation waveform in the photos attached .

hlap me please.

7 Replies

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

    when you say result <= temp2 * (61/200000): do you know what it settles to? or rather if you do it by hand what is 3 * 61/200000? is'nt it < 1

    so how to expect <1 to go on 15bit bus?

    in short you need to scale up the value 0.000305 to your 15 bit resolution.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    you you are right

    i originally wrote it like this

    3/0.000305 and the result is >0

    but quartus does not let me write it like this so i did it like this

    3/(61/200000).

    i think i forgot to place "/" between them/

    do you think that it might fix it?

    so do you have any other suggestions?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    61/200000 = 0.000305

    I think 3/0.000305 is not same as 3*.000305 so which way you want to go?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    ok then you have range 0~9 from counter (in fact your code is 0~8 for calculation logic)

    now 1/0.000305 = 3279

    so multiply each count value by 3279 and you will get 0~26232 or if 0~9 will need 0~29511

    so you are lucky now since 15 bits covers 0~32767
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If you want an alternative you can avoid the mult and now use:

    count <= count + 3279 then pass it to the DAC