2021-04-26から1日間の記事一覧

任意の数値をBCDに変換する / double dabbleアルゴリズムと少しインチキな方法と / Python

# 普通に10進数の1桁ずつを取り出す。 def bin2bcd(_bin): DIGITS_BCD = len(str(_bin)) bcd = [0] * DIGITS_BCD for i in range(DIGITS_BCD - 1): _bin, bcd[i] = divmod(_bin, 10) bcd[DIGITS_BCD - 1] = _bin return bcd # double_dabbleアルゴリズムでBC…

バイナリー→BCD変換函数を作る / double dabbleアルゴリズム / VHDL

pp.358-359 unsigned 12ビット値(0~4095)を4桁BCD値 (0,0,0,0~4,0,9,5)に変換する。 subprograms_pkg.vhd library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; package subprograms_pkg is function binary_to_bcd (bin: std_logic_vec…

std_logic_vectorからintegerへ型変換する函数を作る / process内に

std_logic_vectorからintegerへ型変換する函数をprocess内に記述する。 pp.357-358 library ieee; use ieee.std_logic_1164.all; entity test_circuit is generic( WIDTH: natural := 8 ); port( clk: in std_logic; inp: in std_logic_vector(WIDTH-1 downt…

ceil(log2())を求める函数を作る / architecture内に

p.357 前回と同じ函数を今度はarchitectureの宣言部に記述する。reusabilityの観点からすると好ましくない。 entity test_circuit is generic( BITS: natural := 8 ); port( inp : in positive range 1 to 2**BITS-1; outp: out natural range 0 to BITS ); …

ceil(log2())を求める函数を作る / パッケージ内に

pp.355-356 パッケージ内に函数を作る。 subprograms_pkg.vhd package subprograms_pkg is -- 函数を宣言する。 -- function 函数名 (引数: 型) return 型; function ceil_log2 (input: positive) return natural; end package; package body subprograms_pk…

平方根を求める / 回路全体を試す

pp.322-325 今度は回路全体を試す。 条件は下のとおりとする。 startパルスの入力時に計算を開始する。 startもxもクロックには非同期。 startパルスの長さは決まっていないので、シンクロナイザーを通したあとにワンショットパルス化する(p.55、figure 2.27…