Note that there are some explanatory texts on larger screens.

plurals
  1. POVHDL: nth digit of decimal integer
    text
    copied!<p>I have an integer signal (range 0 to 9999). I’m trying to display it on set of 7-segment displays. I have implemented multiplexer (one digit is displayed at once). Now I need to split my integer into single digits. </p> <p>Theoretically it is very simple: just use mod (ex NUM / 100 mod 10 gives second digit). Problem is that when I’ve compiled solution with mod (used 4 times) my code used over 9000 cells just for mod. That is too much (but works). </p> <p>Then I tried casting to smaller integer, but it doesn’t work. Integer range 0 to 9 uses 4 bits so it is really range 0 to 15. </p> <p>I’m sure there is simpler on obvious solution but I wasn’t able to find it. Please note that I’m beginner :).</p> <p>EDIT: the code:</p> <p>This part sets proper output to display for given digit <pre><code></p> <pre><code>process (clk) begin if rising_edge(clk) then case number1 is -- od prawej: a b c d e f g when 0 =&gt; segment &lt;="1000000"; -- '0' when 1 =&gt; segment &lt;="1111001"; -- '1' when 2 =&gt; segment &lt;="0100100"; -- '2' when 3 =&gt; segment &lt;="0110000"; -- '3' when 4 =&gt; segment &lt;="0011001"; -- '4' when 5 =&gt; segment &lt;="0010010"; -- '5' when 6 =&gt; segment &lt;="0000010"; -- '6' when 7 =&gt; segment &lt;="1111000"; -- '7' when 8 =&gt; segment &lt;="0000000"; -- '8' when 9 =&gt; segment &lt;="0010000"; -- '9' when others=&gt; segment &lt;="1111111"; end case; end if; end process; </code></pre> <p></pre></code></p> <p>This part selects display (1 of 4) and sets digit value</p> <pre><code>process (clk) variable count: integer range 0 to 1000; begin if rising_edge(clk) then if count = 1000 - 1 then count := 0; case digit is when "1000" =&gt; digit &lt;="0001"; number1 &lt;= year/1000 mod 10; when "0001" =&gt; digit &lt;="0010"; number1 &lt;= year/100 mod 10; when "0010" =&gt; digit &lt;="0100"; number1 &lt;= year/10 mod 10; when "0100" =&gt; digit &lt;="1000"; number1 &lt;= year mod 10; when others =&gt; digit &lt;="0001"; end case; else count := count + 1; end if; end if; end process; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload