0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

blocklyでverilog その5

Last updated at Posted at 2023-05-19

概要

blocklyでverilog、やってみた。
練習問題、やってみた。

練習問題

7segmentLEDのデコーダーを書いて、iverilogで検証せよ。

写真

image.png

image.png

生成したコード

module x (input [3:0] data, output [6:0] code);
reg [6:0] code;
wire [3:0] data;
always @ (data)
begin
  if (data == 0) 	begin
    code = (7'h7e);
   end  else 	begin
     if (data == 1) 	begin
      code = (6'h30);
     end  else 	begin
       if (data == 2) 	begin
        code = (7'h6b);
       end  else 	begin
         if (data == 3) 	begin
          code = (7'h79);
         end  else 	begin
           if (data == 4) 	begin
            code = (6'h33);
           end  else 	begin
             if (data == 5) 	begin
              code = (7'h5b);
             end  else 	begin
               if (data == 6) 	begin
                code = (7'h5f);
               end  else 	begin
                 if (data == 7) 	begin
                  code = (7'h72);
                 end  else 	begin
                   if (data == 8) 	begin
                    code = (7'h7f);
                   end  else 	begin
                     if (data == 9) 	begin
                      code = (7'h7b);
                     end  else 	begin
                      end
                   end
                 end
               end
             end
           end
         end
       end
     end
   end

end
endmodule


テストベンチを書く。


module testbench;
    reg [3:0] data;
    wire [6:0] code;
    x u(.data(data), .code(code));
    initial
    begin
        $display(" data code");
        $monitor( "%h  %h", data, code);
        data = 4'h0; #10;
        data = 4'h1; #10;
        data = 4'h2; #10;
        data = 4'h3; #10;
        data = 4'h4; #10;
        data = 4'h5; #10;
        data = 4'h6; #10;
        data = 4'h7; #10;
        data = 4'h8; #10;
        data = 4'h9; #10;
        $finish;
    end
endmodule





iverilogでコンパイル実行

>iverilog block3.v

>vvp a.out
 data code
0  7e
1  30
2  6b
3  79
4  33
5  5b
6  5f
7  72
8  7f
9  7b
block3.v:70: $finish called at 100 (1s)

生成したフローのxml

<xml xmlns="http://www.w3.org/1999/xhtml">
  <variables>
    <variable type="" id="US6mg:+!q~Nw!qA4u~S)">code</variable>
    <variable type="" id="3u#X/85:7dR8:}JhJkw~">data</variable>
  </variables>
  <block type="module_dec" id="4SExhY1)y(jwDTBa0Nj+" x="-167" y="36">
    <field name="modName">x</field>
    <field name="varNames">input data, input code</field>
    <next>
      <block type="reg_block" id="%%NZSxTnMV?80hd$I8S3">
        <field name="NAME">code</field>
        <value name="size">
          <block type="math_number" id="4%-cI7S*Y@7Wo^@w)hQ6">
            <field name="NUM">7</field>
          </block>
        </value>
        <next>
          <block type="wire_block" id="@M^qy`,A_Kt8!l88SLjC">
            <field name="NAME">data</field>
            <value name="size">
              <block type="math_number" id="3s+EQqGns=HTP7|?ID?V">
                <field name="NUM">4</field>
              </block>
            </value>
            <next>
              <block type="always_blk" id="X.%crG1aeb@/ku#rB(En">
                <value name="condition">
                  <block type="variables_get" id="9ye0;eqxhJ(yr`LZYRFp">
                    <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                  </block>
                </value>
                <statement name="body">
                  <block type="controls_ifelse" id="O_Ean88EKpn+2v|?fd0V">
                    <value name="IF0">
                      <block type="logic_compare" id="^n[2MWd,t`F~9d%_1/KB">
                        <field name="OP">EQ</field>
                        <value name="A">
                          <block type="variables_get" id="2x1~oBs/P0~-txb%*R7S">
                            <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                          </block>
                        </value>
                        <value name="B">
                          <block type="math_number" id="y4uQ[19|FU{}8w{E4U5(">
                            <field name="NUM">0</field>
                          </block>
                        </value>
                      </block>
                    </value>
                    <statement name="DO0">
                      <block type="variables_set" id="p;u#b8P$vjmye)kAhAT(">
                        <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                        <value name="VALUE">
                          <block type="decimal_hexa_return" id="O*tq=$hZj|jE01nQ0R%)">
                            <value name="number">
                              <block type="math_number" id="Xy2=:ys-0xPd//[+kh`I">
                                <field name="NUM">126</field>
                              </block>
                            </value>
                          </block>
                        </value>
                      </block>
                    </statement>
                    <statement name="ELSE">
                      <block type="controls_ifelse" id="#,|h|b%%V7hkWHjUxAAZ">
                        <value name="IF0">
                          <block type="logic_compare" id="r(!|HoyOGN|#7?$9j{;M">
                            <field name="OP">EQ</field>
                            <value name="A">
                              <block type="variables_get" id="b52e1yYFdtZQ~!mmabXv">
                                <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                              </block>
                            </value>
                            <value name="B">
                              <block type="math_number" id="t?3g2CH[P.doDH]/,Qk*">
                                <field name="NUM">1</field>
                              </block>
                            </value>
                          </block>
                        </value>
                        <statement name="DO0">
                          <block type="variables_set" id="*7#nDzQ+Ghf|I`:EYc7R">
                            <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                            <value name="VALUE">
                              <block type="decimal_hexa_return" id="?-:`KH]EHYp^GHOArBpL">
                                <value name="number">
                                  <block type="math_number" id=",S~fS]oumoK:5w:C4tNr">
                                    <field name="NUM">48</field>
                                  </block>
                                </value>
                              </block>
                            </value>
                          </block>
                        </statement>
                        <statement name="ELSE">
                          <block type="controls_ifelse" id="}YEb(fm(5.B7E?h:m958">
                            <value name="IF0">
                              <block type="logic_compare" id="*GT*pkw7U:hz.wWge0$N">
                                <field name="OP">EQ</field>
                                <value name="A">
                                  <block type="variables_get" id=")-`GF[ggTRW*coG!C5-e">
                                    <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                  </block>
                                </value>
                                <value name="B">
                                  <block type="math_number" id="9ReS06sc2SZs.-v{wL+u">
                                    <field name="NUM">2</field>
                                  </block>
                                </value>
                              </block>
                            </value>
                            <statement name="DO0">
                              <block type="variables_set" id="N,SOH)NB`4R9?$LDdf`^">
                                <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                <value name="VALUE">
                                  <block type="decimal_hexa_return" id="T|Q5f.k[:m8Y2+p8Ft2`">
                                    <value name="number">
                                      <block type="math_number" id="VZZ-[bp#t1$EK^7$xMS;">
                                        <field name="NUM">107</field>
                                      </block>
                                    </value>
                                  </block>
                                </value>
                              </block>
                            </statement>
                            <statement name="ELSE">
                              <block type="controls_ifelse" id="R?veq;.,WSLljI#`t0L$">
                                <value name="IF0">
                                  <block type="logic_compare" id="$0Y%3m0.GM#Ho!`+[v0*">
                                    <field name="OP">EQ</field>
                                    <value name="A">
                                      <block type="variables_get" id="k@N1RFNwI`k-Kc3gHD`5">
                                        <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                      </block>
                                    </value>
                                    <value name="B">
                                      <block type="math_number" id="?(_}~GHY$vYndkem14*[">
                                        <field name="NUM">3</field>
                                      </block>
                                    </value>
                                  </block>
                                </value>
                                <statement name="DO0">
                                  <block type="variables_set" id="J-,$UunS8G3t`-]i6q}k">
                                    <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                    <value name="VALUE">
                                      <block type="decimal_hexa_return" id="9zpD=k9-#JY+(h88d(-r">
                                        <value name="number">
                                          <block type="math_number" id="9|7H/CgX$02mf(uX4+9k">
                                            <field name="NUM">121</field>
                                          </block>
                                        </value>
                                      </block>
                                    </value>
                                  </block>
                                </statement>
                                <statement name="ELSE">
                                  <block type="controls_ifelse" id="qR$~7)Le_J*GQE/ZK$db">
                                    <value name="IF0">
                                      <block type="logic_compare" id=":l9V`gP/4isYKUm`FX6/">
                                        <field name="OP">EQ</field>
                                        <value name="A">
                                          <block type="variables_get" id="/g(nh:]v*LE|lI!p+Y,S">
                                            <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                          </block>
                                        </value>
                                        <value name="B">
                                          <block type="math_number" id="t#[9(|=2hGoM-PT3zmqx">
                                            <field name="NUM">4</field>
                                          </block>
                                        </value>
                                      </block>
                                    </value>
                                    <statement name="DO0">
                                      <block type="variables_set" id="DCNVo?OA(5eetz^N5F/_">
                                        <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                        <value name="VALUE">
                                          <block type="decimal_hexa_return" id="n*Gp#44rVOeP6{!-b#c3">
                                            <value name="number">
                                              <block type="math_number" id="UKM]BIbkB$%*Fik56s*g">
                                                <field name="NUM">51</field>
                                              </block>
                                            </value>
                                          </block>
                                        </value>
                                      </block>
                                    </statement>
                                    <statement name="ELSE">
                                      <block type="controls_ifelse" id="Hf(lg[2oSe;ArnOxIKzT">
                                        <value name="IF0">
                                          <block type="logic_compare" id="!$Dgel)bS66+af1~MA0/">
                                            <field name="OP">EQ</field>
                                            <value name="A">
                                              <block type="variables_get" id="Q!xQc*q%)+19:5K4sDGG">
                                                <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                              </block>
                                            </value>
                                            <value name="B">
                                              <block type="math_number" id="`GJj/j$i.+{H[K=$3}gZ">
                                                <field name="NUM">5</field>
                                              </block>
                                            </value>
                                          </block>
                                        </value>
                                        <statement name="DO0">
                                          <block type="variables_set" id="i;$bjQk8Ltbx%a26);qR">
                                            <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                            <value name="VALUE">
                                              <block type="decimal_hexa_return" id="Gx$}h~(L^iEi^D}9?AZ$">
                                                <value name="number">
                                                  <block type="math_number" id="qFKjuCyljIc=@]pUYs8K">
                                                    <field name="NUM">91</field>
                                                  </block>
                                                </value>
                                              </block>
                                            </value>
                                          </block>
                                        </statement>
                                        <statement name="ELSE">
                                          <block type="controls_ifelse" id="6EozhEPsz%cf.O]AYs#@">
                                            <value name="IF0">
                                              <block type="logic_compare" id="[Cv?:$z_q[ulNDMn2gqF">
                                                <field name="OP">EQ</field>
                                                <value name="A">
                                                  <block type="variables_get" id="0v/~pf)YljY.-d{3:7nG">
                                                    <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                                  </block>
                                                </value>
                                                <value name="B">
                                                  <block type="math_number" id="`D_@Bau8To,g]hv3||SH">
                                                    <field name="NUM">6</field>
                                                  </block>
                                                </value>
                                              </block>
                                            </value>
                                            <statement name="DO0">
                                              <block type="variables_set" id="r/c(}jK9]7ez%QVl%8X+">
                                                <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                                <value name="VALUE">
                                                  <block type="decimal_hexa_return" id="dHie_bV:8F{#}`QHcGnK">
                                                    <value name="number">
                                                      <block type="math_number" id="weebI[{m|Km:)b$#|cQE">
                                                        <field name="NUM">95</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                              </block>
                                            </statement>
                                            <statement name="ELSE">
                                              <block type="controls_ifelse" id="!+|=5v$o@9d-_lixiFms">
                                                <value name="IF0">
                                                  <block type="logic_compare" id="F1YK]r,%`MU(h}*Z!j7{">
                                                    <field name="OP">EQ</field>
                                                    <value name="A">
                                                      <block type="variables_get" id="Vua5JiL=9,915XQ1K)?/">
                                                        <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                                      </block>
                                                    </value>
                                                    <value name="B">
                                                      <block type="math_number" id="cu!H0=$5tNC323Cz~N(A">
                                                        <field name="NUM">7</field>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </value>
                                                <statement name="DO0">
                                                  <block type="variables_set" id="9+$)~9_P1DsiPlBHVW%t">
                                                    <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                                    <value name="VALUE">
                                                      <block type="decimal_hexa_return" id="?z#(nK[[=?qR4=;e~m?5">
                                                        <value name="number">
                                                          <block type="math_number" id="}VHzqtpi9ExSPj?o6({U">
                                                            <field name="NUM">114</field>
                                                          </block>
                                                        </value>
                                                      </block>
                                                    </value>
                                                  </block>
                                                </statement>
                                                <statement name="ELSE">
                                                  <block type="controls_ifelse" id="NIM2XxKMFNnW;V~PY%-B">
                                                    <value name="IF0">
                                                      <block type="logic_compare" id="R[/YAQgpkdfYo|!zG=,9">
                                                        <field name="OP">EQ</field>
                                                        <value name="A">
                                                          <block type="variables_get" id="!IRG?`QoXs5x@T*yjlOh">
                                                            <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                                          </block>
                                                        </value>
                                                        <value name="B">
                                                          <block type="math_number" id="WpL2=]{RlKjlgakgt~m=">
                                                            <field name="NUM">8</field>
                                                          </block>
                                                        </value>
                                                      </block>
                                                    </value>
                                                    <statement name="DO0">
                                                      <block type="variables_set" id="nFIA(VX/B6.oQN9978rh">
                                                        <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                                        <value name="VALUE">
                                                          <block type="decimal_hexa_return" id="phn`%fNH|;[#%i-F5po@">
                                                            <value name="number">
                                                              <block type="math_number" id="0SjTb8Y(3l_Nc1-qHREq">
                                                                <field name="NUM">127</field>
                                                              </block>
                                                            </value>
                                                          </block>
                                                        </value>
                                                      </block>
                                                    </statement>
                                                    <statement name="ELSE">
                                                      <block type="controls_ifelse" id="6)|DBg!hCTKewug(Jatr">
                                                        <value name="IF0">
                                                          <block type="logic_compare" id="ve~^fxOIb;zf61E0g]K.">
                                                            <field name="OP">EQ</field>
                                                            <value name="A">
                                                              <block type="variables_get" id="ilR0(nr=xZ`pezGpBr5x">
                                                                <field name="VAR" id="3u#X/85:7dR8:}JhJkw~" variabletype="">data</field>
                                                              </block>
                                                            </value>
                                                            <value name="B">
                                                              <block type="math_number" id="{I_InkI4YTGT*5=*{Z13">
                                                                <field name="NUM">9</field>
                                                              </block>
                                                            </value>
                                                          </block>
                                                        </value>
                                                        <statement name="DO0">
                                                          <block type="variables_set" id="p.bul![|xlD^y7X2ad?Y">
                                                            <field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">code</field>
                                                            <value name="VALUE">
                                                              <block type="decimal_hexa_return" id="uC;.8F{W:[eic!zU+Du+">
                                                                <value name="number">
                                                                  <block type="math_number" id="$%x*F!)+q(v^I%G.OVgB">
                                                                    <field name="NUM">123</field>
                                                                  </block>
                                                                </value>
                                                              </block>
                                                            </value>
                                                          </block>
                                                        </statement>
                                                      </block>
                                                    </statement>
                                                  </block>
                                                </statement>
                                              </block>
                                            </statement>
                                          </block>
                                        </statement>
                                      </block>
                                    </statement>
                                  </block>
                                </statement>
                              </block>
                            </statement>
                          </block>
                        </statement>
                      </block>
                    </statement>
                  </block>
                </statement>
                <next>
                  <block type="end_module" id="ODsu=)XrOwDd2b~P;iY-"></block>
                </next>
              </block>
            </next>
          </block>
        </next>
      </block>
    </next>
  </block>
</xml>

以上。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?