最初に注意。この記事では水平ラインの最初を0ラインと記述しています。その他の記事では最初の水平ラインを1ラインと記述しているものがあるのでご注意ください。
-- 1クロック前のBRAMの出力と現在の値の1クロック前の値を保持
process(clk) begin
if clk'event and clk='1' then
if reset='1' then
bram_data_1d <= (others => '0');
y_data_1d <= (others => '0');
else
if r_w='1' then
y_data_1d <= cam_ydata_2d;
bram_data_1d <= bram_data;
end if;
end if;
end if;
end process;
-- 縦横斜めピクセルの引き算の絶対値
process(cam_ydata_2d, bram_data) begin -- 縦
if unsigned(cam_ydata_2d) >= unsigned(bram_data) then
vertical_comp_val <= unsigned(cam_ydata_2d) - unsigned(bram_data);
else
vertical_comp_val <= unsigned(bram_data) - unsigned(cam_ydata_2d);
end if;
end process;
process(cam_ydata_2d, y_data_1d) begin -- 横
if unsigned(cam_ydata_2d) >= unsigned(y_data_1d) then
horizontal_comp_val <= unsigned(cam_ydata_2d) - unsigned(y_data_1d);
else
horizontal_comp_val <= unsigned(y_data_1d) - unsigned(cam_ydata_2d);
end if;
end process;
process(cam_ydata_2d, bram_data_1d) begin
if unsigned(cam_ydata_2d) >= unsigned(bram_data_1d) then
skew_comp_val <= unsigned(cam_ydata_2d) - unsigned(bram_data_1d);
else
skew_comp_val <= unsigned(bram_data_1d) - unsigned(cam_ydata_2d);
end if;
end process;
-- 比較器 (縦横斜めのYデータを比較してエッジを検出する)
process(h_valid_flag, v_valid_flag, vertical_comp_val, horizontal_comp_val, skew_comp_val) begin
if h_valid_flag='0' and v_valid_flag='0' then -- hとvのvalid_flag が0の時は比較しない
ydata_out <= '0' & cam_ydata_2d(7 downto 1);
elsif h_valid_flag='1' and v_valid_flag='0' then -- 最初の水平ラインの時は水平方向だけ比較する
if horizontal_comp_val>=Edge_Threshold_Def then
ydata_out <= CONV_STD_LOGIC_VECTOR(Edge_Value_Def, 8) or ('0' & cam_ydata_2d(7 downto 1));
else
ydata_out <= '0' & cam_ydata_2d(7 downto 1);
end if;
elsif h_valid_flag='1' and v_valid_flag='1' then -- 比較
if vertical_comp_val>=Edge_Threshold_Def or horizontal_comp_val>=Edge_Threshold_Def or skew_comp_val>=Edge_Threshold_Def then -- 縦横斜めどれかがスレッショルドを超えていたらEdge_Value_Defをセット
ydata_out <= CONV_STD_LOGIC_VECTOR(Edge_Value_Def, 8) or ('0' & cam_ydata_2d(7 downto 1));
else
ydata_out <= '0' & cam_ydata_2d(7 downto 1);
end if;
else
ydata_out <= '0' & cam_ydata_2d(7 downto 1);
end if;
end process;
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |