17 |
色変換回路 |
単なる組み合わせ回路による拾変換回路についてかなりトラブルが有ったので、備忘のために記します。
まず、設計したい色変換回路は以下のようなものです。入力はRI, GI, BIのそれぞれ1ビット、出力はRO[3:0]、GO[3:0]、BO[3:0]の3 * 4ビットの回路です。原色を中間色に変換する、2^12(=4096)色中の2^3(=8)色を表示する固定カラーパレットとも言えます。

最初に次のようなプログラムをChatGPTの助けを借りて作成しました。
typedef struct { Bit#(4) ro; Bit#(4) go; Bit#(4) bo; } ColorOutputs deriving (Bits); interface ColorConverter; (* result="OUT" *) (* prefix="" *) method ColorOutputs mapColor( (* port="RI" *) Bit#(1) r, (* port="GI" *) Bit#(1) g, (* port="BI" *) Bit#(1) b); endinterface (* synthesize, always_ready = "mapColor", no_default_clock, no_default_reset *) module mkColorConverter(ColorConverter); method ColorOutputs mapColor(Bit#(1) r, Bit#(1) g, Bit#(1) b); Bit#(4) ro = (case ({r, g, b}) 3'b000: 4'h9; 3'b001: 4'hD; 3'b010: 4'h5; 3'b100: 4'hC; default: ?; endcase); Bit#(4) go = (case ({r, g, b}) 3'b000: 4'h4; 3'b001: 4'h8; 3'b010: 4'hB; 3'b100: 4'hC; default: ?; endcase); Bit#(4) bo = (case ({r, g, b}) 3'b000: 4'h1; 3'b001: 4'h4; 3'b010: 4'h5; 3'b100: 4'hC; default: ?; endcase); return ColorOutputs {ro: ro, go: go, bo: bo}; endmethod endmodule
Leave a Comment