ELGIP-2 adding IP to EL-GENERIC-IP: enc_pd_emul, pulse_generator

This commit is contained in:
Simon Southwell 2018-10-09 13:17:15 +01:00
commit f26b08e101
14 changed files with 3484 additions and 1 deletions

View file

@ -0,0 +1,364 @@
[{
"ip_name": "emul_1",
"bus": "csr",
"description": "Encoder/PD emulator",
"sub_blocks": {
"local": {
"instance": "",
"process": "cpp, htm",
"offset": "0x0"
},
"generic_sequencer_15": {
"instance": "seq",
"process": "cpp, htm",
"offset": "0x20"
}
},
"registers": {
"ip_id" : {
"address" : "0",
"width" : "32",
"description" : "Unique ID for this IP block",
"fields": {
"ip_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x12",
"description" : "IP identifier number"
},
"mfr_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0xFF",
"description" : "Manufacturer number"
},
"reserved" : {
"type" : "rsv",
"bit_len" : "16",
"description" : "Reserved bits"
}
}
},
"ip_ver" : {
"address" : "1",
"width" : "32",
"description" : "IP Version",
"fields": {
"minor_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x01",
"description" : "Minor number"
},
"major_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x00",
"description" : "Major number"
},
"reserved" : {
"type" : "rsv",
"bit_len" : "16",
"description" : "Reserved bits"
}
}
},
"out_enable": {
"address": "2",
"width": "16",
"description": "TTL/RS422 Output Enable/Force output",
"fields": {
"ttl_pd_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL PD output enable"
},
"ttl_ph1_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL enc-phase-1 output enable"
},
"ttl_ph2_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL enc-phase-2 output enable"
},
"ttl_zp_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL enc-zero-phase output enable"
},
"rs422_pd_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 PD output enable"
},
"rs422_ph1_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 enc-phase-1 output enable"
},
"rs422_ph2_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 enc-phase-2 output enable"
},
"rs422_zp_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 enc-zero-phase output enable"
},
"ttl_pd_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL PD output force high"
},
"ttl_ph1_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL enc-phase-1 output force high"
},
"ttl_ph2_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL enc-phase-2 output force high"
},
"ttl_zp_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "TTL enc-zero-phase output force high"
},
"rs422_pd_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 PD output force high"
},
"rs422_ph1_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 enc-phase-1 output force high"
},
"rs422_ph2_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 enc-phase-2 output force high"
},
"rs422_zp_fh": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "RS422 enc-zero-phase output force high"
}
}
},
"out_status": {
"address": "3",
"width": "8",
"description": "Reports the status of TTL and RS422 outputs",
"fields": {
"ttl_pd": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "TTL PD status"
},
"ttl_ph1": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "TTL enc-phase-1 status"
},
"ttl_ph2": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "TTL enc-phase-2 status"
},
"ttl_zp": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "TTL enc-zp status"
},
"rs422_pd": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "RS422 PD status"
},
"rs422_ph1": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "RS422 enc-phase-1 status"
},
"rs422_ph2": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "RS422 enc-phase-2 status"
},
"rs422_zp": {
"type": "r",
"bit_len": "1",
"reset": "U",
"description": "RS422 enc-zp status"
}
}
},
"enc_ctrl": {
"address": "4",
"width": "7",
"description": "Control the emulation of encoder signals",
"fields": {
"nco_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "enable the NCO increment"
},
"nco_init": {
"type": "w0",
"bit_len": "1",
"reset": "0x0",
"description": "force the NCO to the initial value"
},
"enc_dir": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "encoder/absolute position direction: 0 => positive, 1 => negative"
},
"set_abs_pos": {
"type": "w0",
"bit_len": "1",
"reset": "0x0",
"description": "force the absolute position to the (programmable) initial value"
},
"max_pulses_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "0 => NCO free running, 1 => the NCO automatically stops after a specified number of absolute position increments"
},
"max_pulses_start": {
"type": "w0",
"bit_len": "1",
"reset": "0x0",
"description": "start the generation of a fixed number of absolute position increments "
},
"max_pulses_done": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "signals the completion of the encoder/absolute position increments"
}
}
},
"enc_nco_inc": {
"type": "w",
"address": "5",
"reset": "0x0",
"width": "32",
"description": "Encoder NCO increment"
},
"enc_pulse_num": {
"type": "w",
"address": "6",
"reset": "0x0",
"width": "32",
"description": "number of encoder/absolute position increments to be generated"
},
"enc_zp_ppr": {
"type": "w",
"address": "7",
"reset": "0x0",
"width": "16",
"description": "Zero-Phase PPR (Pulse-Per-Revolution)"
},
"pos_init_lsb": {
"type": "w",
"address": "8",
"reset": "0x0",
"width": "32",
"description": "Absolute Position Initial value, bits 31:0"
},
"pos_init_msb": {
"type": "w",
"address": "9",
"reset": "0x0",
"width": "8",
"description": "Absolute Position Initial value, bits 39:32"
},
"pos_stat_lsb": {
"type": "r",
"address": "10",
"reset": "0x0",
"width": "32",
"description": "Absolute Position value, bits 31:0"
},
"pos_stat_msb": {
"type": "r",
"address": "11",
"reset": "0x0",
"width": "8",
"description": "Absolute Position value, bits 39:32"
},
"pd_ctrl": {
"address": "12",
"description": "Control the emulation of PD",
"width": "3",
"fields": {
"pd_en": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "enable the generation of PD events"
},
"pd_gen": {
"type": "w0",
"bit_len": "1",
"reset": "0x0",
"description": "issue a PD pulse"
},
"clr_pd_cnt": {
"type": "w0",
"bit_len": "1",
"reset": "0x0",
"description": "clear the value of the PD counter register"
}
}
},
"pd_pulse_width": {
"type": "w",
"address": "13",
"reset": "0x14",
"width": "16",
"description": "PD pulse-width [clock-cycles at 100 MHz]. The minimum value is 1."
},
"pd_cnt": {
"type": "r",
"address": "14",
"reset": "0x0",
"width": "24",
"description": "PD pulse counter"
}
}
}]

View file

@ -0,0 +1,49 @@
# Simulation macro
#.main clear
set OSVVM_PATH ../../common/0/src/test/OSVVM
set COMMON_PATH ../../common/0/src
set WORKLIB work
vlib ./work
vmap work ./work
# Compile the UUT
do com_smb.do
# Compile the constrained random related packages
vlib OSVVM
vcom -2008 -work OSVVM \
$OSVVM_PATH/RandomBasePkg.vhd \
$OSVVM_PATH/SortListPkg_int.vhd \
$OSVVM_PATH/RandomPkg.vhd \
$OSVVM_PATH/NamePkg.vhd \
$OSVVM_PATH/MessagePkg.vhd \
$OSVVM_PATH/CoveragePkg.vhd
# Compile support files
vcom -2008 -work $WORKLIB $COMMON_PATH/test/common_test_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/test/log_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH//test/avalon_verify_pkg.vhd
# Compile the testbench
vcom -2008 -work $WORKLIB ./../src/test/enc_pd_emul_1_tb.vhd
vsim -t ps work.enc_pd_emul_1_tb
#add wave /enc_pd_emul_1_tb/*
#add wave /enc_pd_emul_1_tb/iUUT/*
# remove warnings from standard numeric/arithmetic packages (speed-up simulation)
set StdArithNoWarnings 1
set NumericStdNoWarnings 1
do wave_enc_pd_emul_1.do
when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;}
run -all
#run 100 us;

View file

@ -0,0 +1,153 @@
onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate /enc_pd_emul_1_tb/reset_n
add wave -noupdate /enc_pd_emul_1_tb/clk
add wave -noupdate /enc_pd_emul_1_tb/ttl_pd
add wave -noupdate /enc_pd_emul_1_tb/ttl_enc_p1
add wave -noupdate /enc_pd_emul_1_tb/ttl_enc_p2
add wave -noupdate /enc_pd_emul_1_tb/ttl_enc_zp
add wave -noupdate /enc_pd_emul_1_tb/rs422_pd
add wave -noupdate /enc_pd_emul_1_tb/rs422_enc_p1
add wave -noupdate /enc_pd_emul_1_tb/rs422_enc_p2
add wave -noupdate /enc_pd_emul_1_tb/rs422_enc_zp
add wave -noupdate /enc_pd_emul_1_tb/avs_address
add wave -noupdate /enc_pd_emul_1_tb/avs_write
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/avs_writedata
add wave -noupdate /enc_pd_emul_1_tb/avs_read
add wave -noupdate /enc_pd_emul_1_tb/avs_readdatavalid
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/avs_readdata
add wave -noupdate /enc_pd_emul_1_tb/setup
add wave -noupdate /enc_pd_emul_1_tb/running
add wave -noupdate /enc_pd_emul_1_tb/passed
add wave -noupdate /enc_pd_emul_1_tb/failed
add wave -noupdate /enc_pd_emul_1_tb/test_timeout
add wave -noupdate /enc_pd_emul_1_tb/test_completed
add wave -noupdate /enc_pd_emul_1_tb/error_flag
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/avs_mm_s_rec
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/avs_mm_m_rec
add wave -noupdate -divider UUT
add wave -noupdate /enc_pd_emul_1_tb/iUUT/clk
add wave -noupdate /enc_pd_emul_1_tb/iUUT/reset_n
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_pd
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_p1
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_p2
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_zp
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_pd
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_p1
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_p2
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_zp
add wave -noupdate -radix decimal /enc_pd_emul_1_tb/iUUT/abs_pos_out
add wave -noupdate /enc_pd_emul_1_tb/iUUT/set_pos_out
add wave -noupdate /enc_pd_emul_1_tb/iUUT/inc_pos_out
add wave -noupdate /enc_pd_emul_1_tb/iUUT/dec_pos_out
add wave -noupdate /enc_pd_emul_1_tb/iUUT/avs_address
add wave -noupdate /enc_pd_emul_1_tb/iUUT/avs_write
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/avs_writedata
add wave -noupdate /enc_pd_emul_1_tb/iUUT/avs_read
add wave -noupdate /enc_pd_emul_1_tb/iUUT/avs_readdatavalid
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/avs_readdata
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_init
add wave -noupdate /enc_pd_emul_1_tb/iUUT/nco_inc_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_dir
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_p1
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_p2
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_p1_d
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_p2_d
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pulse_cnt_inc
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pulse_cnt_inc_d
add wave -noupdate /enc_pd_emul_1_tb/iUUT/max_pulses_start
add wave -noupdate /enc_pd_emul_1_tb/iUUT/max_pulses_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pulse_cnt_start
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pulse_cnt_stop
add wave -noupdate /enc_pd_emul_1_tb/iUUT/max_pulses_done
add wave -noupdate /enc_pd_emul_1_tb/iUUT/zero_phase
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pulse_cnt_running
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_pd_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_p1_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_p2_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_zp_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_pd_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_zp
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_p1_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_p2_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_zp_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/enc_emul_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_pd_fh
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_p1_fh
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_p2_fh
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ttl_enc_zp_fh
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_pd_fh
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_p1_fh
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_p2_fh
add wave -noupdate /enc_pd_emul_1_tb/iUUT/rs422_enc_zp_fh
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/zero_phase_ppr
add wave -noupdate /enc_pd_emul_1_tb/iUUT/inc_pos
add wave -noupdate /enc_pd_emul_1_tb/iUUT/dec_pos
add wave -noupdate /enc_pd_emul_1_tb/iUUT/set_abs_pos
add wave -noupdate -radix decimal /enc_pd_emul_1_tb/iUUT/abs_pos
add wave -noupdate -radix decimal /enc_pd_emul_1_tb/iUUT/abs_pos_init
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/zero_phase_cnt
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/enc_nco_1
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/enc_nco_2
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/nco_inc
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_pulses_start
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/seq_pulses
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/max_pulses
add wave -noupdate /enc_pd_emul_1_tb/iUUT/max_pulses_start_i
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/max_pulses_i
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/pulse_cnt
add wave -noupdate /enc_pd_emul_1_tb/iUUT/avs_write_i
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_ram_write
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_csr_write
add wave -noupdate /enc_pd_emul_1_tb/iUUT/avs_read_i
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_ram_read
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_csr_read
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_start_req
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_busy
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ext_trigger
add wave -noupdate /enc_pd_emul_1_tb/iUUT/us_pulse
add wave -noupdate /enc_pd_emul_1_tb/iUUT/ms_pulse
add wave -noupdate /enc_pd_emul_1_tb/iUUT/sec_pulse
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pd
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pd_d
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pd_pulse
add wave -noupdate /enc_pd_emul_1_tb/iUUT/clr_pd_cnt
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pd_gen
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pd_seq
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pd_emul_en
add wave -noupdate /enc_pd_emul_1_tb/iUUT/pd_i
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/pd_pulse_width
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/pd_pulse_cnt
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/pd_cnt
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_csr_addr
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_trigger_in
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/clk_cnt
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_ram_addr
add wave -noupdate /enc_pd_emul_1_tb/iUUT/seq_start_addr
add wave -noupdate /enc_pd_emul_1_tb/iUUT/avs_addr_i
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/us_cnt
add wave -noupdate -radix unsigned /enc_pd_emul_1_tb/iUUT/ms_cnt
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/seq_vec_out
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/avs_readdata_i
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/seq_ram_writedata
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/seq_csr_writedata
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/seq_ram_readdata
add wave -noupdate -radix hexadecimal /enc_pd_emul_1_tb/iUUT/seq_csr_readdata
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {772234424 ps} 0} {{Cursor 2} {255555000 ps} 1}
quietly wave cursor active 1
configure wave -namecolwidth 303
configure wave -valuecolwidth 134
configure wave -justifyvalue left
configure wave -signalnamewidth 0
configure wave -snapdistance 10
configure wave -datasetprefix 0
configure wave -rowmargin 4
configure wave -childrowmargin 2
configure wave -gridoffset 0
configure wave -gridperiod 1
configure wave -griddelta 40
configure wave -timeline 0
configure wave -timelineunits ps
update
WaveRestoreZoom {715822479 ps} {777214607 ps}

View file

@ -0,0 +1,563 @@
-------------------------------------------------------------------------------
-- Title : enc_pd_emul_1
-- Project : SMB/Encoder Simulation board
-------------------------------------------------------------------------------
-- File : enc_pd_emul_1.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2018-05-30
-- Last update: 2018-08-28
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Generate synthetic encoder and product detect signals
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.enc_pd_emul_1_pkg.all;
entity enc_pd_emul_1 is
generic(
SEQ_ENABLE : boolean := true); -- enable the instantiation of
-- the sequencer
port(
clk : in std_logic;
reset_n : in std_logic := '1';
-- Encoder/PD outputs:
-- TTL
ttl_pd : out std_logic;
ttl_enc_p1 : out std_logic;
ttl_enc_p2 : out std_logic;
ttl_enc_zp : out std_logic;
-- RS422
rs422_pd : out std_logic;
rs422_enc_p1 : out std_logic;
rs422_enc_p2 : out std_logic;
rs422_enc_zp : out std_logic;
-- Absolute Position
abs_pos_out : out std_logic_vector(39 downto 0);
set_pos_out : out std_logic;
inc_pos_out : out std_logic;
dec_pos_out : out std_logic;
-----------------------------------------------------------------------
-- Avalon MM Interface
-----------------------------------------------------------------------
avs_address : in std_logic_vector( 9 downto 0);
avs_write : in std_logic;
avs_writedata : in std_logic_vector(31 downto 0);
avs_read : in std_logic;
avs_readdatavalid : out std_logic;
avs_readdata : out std_logic_vector(31 downto 0));
end entity enc_pd_emul_1;
architecture rtl of enc_pd_emul_1 is
constant CSR_IP_ID : std_logic_vector(31 downto 0) := x"0000FF12";
constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"00000001";
constant ENC_NCO_INIT_1 : std_logic_vector(31 downto 0) := X"48000000";
constant ENC_NCO_INIT_2 : std_logic_vector(31 downto 0) := X"08000000";
-- signals
signal enc_init, nco_inc_en, enc_dir : std_logic;
signal enc_p1, enc_p2, enc_p1_d, enc_p2_d : std_logic;
signal pulse_cnt_inc, pulse_cnt_inc_d : std_logic;
signal max_pulses_start, avs_read_d : std_logic;
signal max_pulses_en, pulse_cnt_start : std_logic;
signal pulse_cnt_stop, max_pulses_done : std_logic;
signal zero_phase, pulse_cnt_running : std_logic;
signal ttl_pd_en, ttl_enc_p1_en, ttl_enc_p2_en : std_logic;
signal ttl_enc_zp_en, rs422_pd_en, enc_zp : std_logic;
signal ttl_pd_fh, ttl_enc_p1_fh, ttl_enc_p2_fh : std_logic;
signal ttl_enc_zp_fh, rs422_pd_fh : std_logic;
signal rs422_enc_p1_fh, rs422_enc_p2_fh : std_logic;
signal rs422_enc_zp_fh : std_logic;
signal rs422_enc_p1_en, rs422_enc_p2_en : std_logic;
signal rs422_enc_zp_en, enc_emul_en : std_logic;
signal inc_pos, dec_pos, set_abs_pos : std_logic;
signal avs_write_i, seq_ram_write, seq_csr_write : std_logic;
signal avs_read_i, seq_ram_read, seq_csr_read : std_logic;
signal seq_start_req, seq_busy, ext_trigger : std_logic;
signal us_pulse, ms_pulse, sec_pulse : std_logic;
signal pd, pd_d, pd_pulse, clr_pd_cnt : std_logic;
signal pd_gen, pd_seq, pd_emul_en, pd_i : std_logic;
signal max_pulses_start_i, seq_pulses_start : std_logic;
signal enc_dir_i, pulse_dir, seq_present : std_logic;
--
signal seq_vec_out : std_logic_vector( 1 downto 0);
signal seq_csr_addr : std_logic_vector( 3 downto 0);
signal clk_cnt : std_logic_vector( 6 downto 0);
signal seq_trigger_in : std_logic_vector( 7 downto 0);
signal seq_ram_addr, seq_start_addr : std_logic_vector( 8 downto 0);
signal avs_addr_i, us_cnt, ms_cnt : std_logic_vector( 9 downto 0);
signal zero_phase_ppr, zero_phase_cnt : std_logic_vector(15 downto 0);
signal pd_pulse_width, pd_pulse_cnt : std_logic_vector(15 downto 0);
signal pd_cnt : std_logic_vector(23 downto 0);
signal enc_nco_1 : std_logic_vector(31 downto 0) := ENC_NCO_INIT_1;
signal enc_nco_2 : std_logic_vector(31 downto 0) := ENC_NCO_INIT_2;
signal nco_inc, avs_readdata_i, seq_pulses : std_logic_vector(31 downto 0);
signal seq_ram_writedata, seq_csr_writedata : std_logic_vector(31 downto 0);
signal seq_ram_readdata, seq_csr_readdata : std_logic_vector(31 downto 0);
signal max_pulses, max_pulses_i, pulse_cnt : std_logic_vector(31 downto 0);
signal abs_pos, abs_pos_init : std_logic_vector(39 downto 0);
begin
-----------------------------------------------------------------------------
-- Synthetic encoder generation
-----------------------------------------------------------------------------
pEMUL_ENC : process(clk)
begin
if(clk = '1' and clk'event) then
if(enc_init = '1') then
enc_nco_1 <= ENC_NCO_INIT_1;
enc_nco_2 <= ENC_NCO_INIT_2;
elsif(nco_inc_en = '1' and enc_dir_i = '0') then
enc_nco_1 <= std_logic_vector(signed(enc_nco_1) + signed(nco_inc));
enc_nco_2 <= std_logic_vector(signed(enc_nco_2) + signed(nco_inc));
elsif(nco_inc_en = '1' and enc_dir_i = '1') then
enc_nco_1 <= std_logic_vector(signed(enc_nco_1) - signed(nco_inc));
enc_nco_2 <= std_logic_vector(signed(enc_nco_2) - signed(nco_inc));
end if;
enc_p1 <= enc_nco_1(enc_nco_1'left);
enc_p2 <= enc_nco_2(enc_nco_2'left);
-- Pulse count mechanism
enc_p1_d <= enc_p1;
enc_p2_d <= enc_p2;
pulse_cnt_inc_d <= pulse_cnt_inc;
if(max_pulses_en = '0' or pulse_cnt_stop = '1') then
pulse_cnt_running <= '0';
elsif(pulse_cnt_start = '1') then
pulse_cnt_running <= '1';
end if;
if(max_pulses_en = '0' or (max_pulses_en = '1' and pulse_cnt_start = '1')) then
max_pulses_done <= '0';
elsif(max_pulses_en = '1' and pulse_cnt_stop = '1') then
max_pulses_done <= '1';
end if;
if(pulse_cnt_start = '1') then
pulse_cnt <= (others => '0');
elsif(pulse_cnt_running = '1' and pulse_cnt_inc = '1') then
pulse_cnt <= std_logic_vector(unsigned(pulse_cnt)+1);
end if;
max_pulses_start_i <= max_pulses_start or seq_pulses_start;
if(max_pulses_start = '1' and pulse_cnt_running = '0') then
max_pulses_i <= max_pulses;
elsif(seq_pulses_start = '1' and pulse_cnt_running = '0') then
max_pulses_i <= seq_pulses;
end if;
if(max_pulses_en = '1') then
if(max_pulses_start = '1' and pulse_cnt_running = '0') then
enc_dir_i <= enc_dir;
elsif(seq_pulses_start = '1' and pulse_cnt_running = '0') then
enc_dir_i <= pulse_dir;
end if;
else
enc_dir_i <= enc_dir;
end if;
if(enc_init = '1' or zero_phase = '1') then
if(enc_dir_i = '0') then
zero_phase_cnt <= (0 => '1', others => '0');
else
zero_phase_cnt <= zero_phase_ppr;
end if;
elsif(enc_dir_i = '0' and enc_p1 = '1' and enc_p1_d = '0') then
zero_phase_cnt <= std_logic_vector(unsigned(zero_phase_cnt)+1);
elsif(enc_dir_i = '1' and enc_p1 = '1' and enc_p1_d = '0') then
zero_phase_cnt <= std_logic_vector(unsigned(zero_phase_cnt)-1);
end if;
if(set_abs_pos = '1') then
abs_pos <= abs_pos_init;
elsif(inc_pos = '1') then
abs_pos <= std_logic_vector(signed(abs_pos)+1);
elsif(dec_pos = '1') then
abs_pos <= std_logic_vector(signed(abs_pos)-1);
end if;
set_pos_out <= set_abs_pos;
inc_pos_out <= inc_pos;
dec_pos_out <= dec_pos;
abs_pos_out <= abs_pos;
end if;
end process pEMUL_ENC;
zero_phase <= '1' when enc_p1 = '1' and enc_p1_d = '0' and ((enc_dir_i = '0' and unsigned(zero_phase_cnt) = unsigned(zero_phase_ppr)) or ((enc_dir_i = '1' and unsigned(zero_phase_cnt) = 0))) else '0';
enc_zp <= zero_phase;
nco_inc_en <= enc_emul_en and (not max_pulses_en or (max_pulses_en and pulse_cnt_running));
pulse_cnt_start <= max_pulses_en and max_pulses_start_i;
pulse_cnt_stop <= '1' when pulse_cnt_running = '1' and (unsigned(pulse_cnt) = unsigned(max_pulses_i)) and pulse_cnt_inc_d = '1' else '0';
pulse_cnt_inc <= (enc_p1 xor enc_p1_d) or (enc_p2 xor enc_p2_d);
inc_pos <= pulse_cnt_inc and not enc_dir_i;
dec_pos <= pulse_cnt_inc and enc_dir_i;
-----------------------------------------------------------------------------
-- Sequencer
-----------------------------------------------------------------------------
-- The sequencer can be use to generate complex sequences of PD and encoder events
gGEN_SEQ: if SEQ_ENABLE = true generate
seq_present <= '1';
iSEQ: entity work.generic_seq_core_15
generic map (
TRIGGER_WIDTH => 8,
VECTOR_WIDTH => 2,
BUS_WIDTH => 32,
POS_WIDTH => 24,
SEQ_DEPTH => 512,
ADD_VEC_PIPE => false,
VECT_RAMP_EN => false,
BUS_BURST_EN => true,
POS_BUS_EN => true,
ALU_EN => true)
port map (
clk => clk,
reset_n => reset_n,
avs_csr_address => seq_csr_addr,
avs_csr_write => seq_csr_write,
avs_csr_writedata => seq_csr_writedata,
avs_csr_read => seq_csr_read,
avs_csr_readdata => seq_csr_readdata,
avs_seq_address => seq_ram_addr,
avs_seq_write => seq_ram_write,
avs_seq_writedata => seq_ram_writedata,
avs_seq_read => seq_ram_read,
avs_seq_readdata => seq_ram_readdata,
start_req => seq_start_req,
start_addr => seq_start_addr,
trigger_in => seq_trigger_in,
pos_in => abs_pos(23 downto 0),
busy => seq_busy,
vector_out => seq_vec_out,
bus_data => seq_pulses,
bus_valid => seq_pulses_start,
bus_ack => '1');
seq_trigger_in <= (0 => '1',
1 => us_pulse,
2 => ms_pulse,
3 => sec_pulse,
4 => ext_trigger,
5 => max_pulses_done,
6 => pulse_cnt_running,
7 => (not pulse_cnt_running));
pd_seq <= seq_vec_out(0);
pulse_dir <= seq_vec_out(1);
pSEQ_SUPPORT: process(reset_n, clk)
begin
if(reset_n = '0') then
clk_cnt <= (others => '0');
us_cnt <= (others => '0');
ms_cnt <= (others => '0');
elsif(clk = '1' and clk'event) then
if(unsigned(clk_cnt) = 99) then
clk_cnt <= (others => '0');
us_pulse <= '1';
else
clk_cnt <= std_logic_vector(unsigned(clk_cnt)+1);
us_pulse <= '0';
end if;
ms_pulse <= '0';
if(us_pulse = '1') then
if(unsigned(us_cnt) = 999) then
us_cnt <= (others => '0');
ms_pulse <= '1';
else
us_cnt <= std_logic_vector(unsigned(us_cnt)+1);
end if;
end if;
sec_pulse <= '0';
if(ms_pulse = '1') then
if(unsigned(ms_cnt) = 999) then
ms_cnt <= (others => '0');
sec_pulse <= '1';
else
ms_cnt <= std_logic_vector(unsigned(ms_cnt)+1);
end if;
end if;
end if;
end process pSEQ_SUPPORT;
end generate gGEN_SEQ;
gDO_NOT_GEN_SEQ: if SEQ_ENABLE = false generate
seq_present <= '0';
pd_seq <= '0';
pulse_dir <= '0';
seq_pulses_start <= '0';
seq_pulses <= (others => '0');
seq_csr_readdata <= x"BAD0BAD1";
seq_ram_readdata <= x"BAD1BAD0";
seq_busy <= '0';
end generate gDO_NOT_GEN_SEQ;
-----------------------------------------------------------------------------
-- PD management
-----------------------------------------------------------------------------
-- PD events are generated exclusively using a sequencer with the encoder
-- position and appropriate timing signals as input triggers.
pPD_GEN : process(reset_n, clk)
begin
if(reset_n = '0') then
pd_cnt <= (others => '0');
elsif(clk = '1' and clk'event) then
pd <= pd_emul_en and (pd_gen or pd_seq);
pd_d <= pd;
if(pd_i) then
pd_pulse_cnt <= pd_pulse_width;
elsif(pd_pulse = '1') then
pd_pulse_cnt <= std_logic_vector(unsigned(pd_pulse_cnt)-1);
end if;
if(pd_emul_en = '0' or unsigned(pd_pulse_cnt) = 1) then
pd_pulse <= '0';
elsif(pd = '1' and pd_d = '0') then
pd_pulse <= '1';
end if;
if(clr_pd_cnt = '1') then
pd_cnt <= (others => '0');
elsif(pd_i = '1') then
pd_cnt <= std_logic_vector(unsigned(pd_cnt)+1);
end if;
end if;
end process pPD_GEN;
pd_i <= pd and not pd_d and not pd_pulse;
-----------------------------------------------------------------------------
-- Output management
-----------------------------------------------------------------------------
-- TTL
ttl_pd <= ttl_pd_en and pd_pulse;
ttl_enc_p1 <= ttl_enc_p1_en and enc_p1;
ttl_enc_p2 <= ttl_enc_p2_en and enc_p2;
ttl_enc_zp <= ttl_enc_zp_en and enc_zp;
-- RS422
rs422_pd <= rs422_pd_en and pd_pulse;
rs422_enc_p1 <= rs422_enc_p1_en and enc_p1;
rs422_enc_p2 <= rs422_enc_p2_en and enc_p2;
rs422_enc_zp <= rs422_enc_zp_en and enc_zp;
-----------------------------------------------------------------------------
-- C&S registers (Avalon-MM I/F)
-----------------------------------------------------------------------------
avs_write_i <= '1' when avs_write = '1' and avs_address(9 downto 5) = "00000" else '0';
seq_ram_write <= '1' when avs_write = '1' and avs_address(9) = '1' else '0';
seq_csr_write <= '1' when avs_write = '1' and avs_address(9 downto 5) = "00001" else '0';
avs_read_i <= '1' when avs_read = '1' and avs_address(9) = '0' else '0';
seq_ram_read <= '1' when avs_read = '1' and avs_address(9) = '1' else '0';
seq_csr_read <= '1' when avs_read = '1' and avs_address(9 downto 5) = "00001" else '0';
seq_ram_addr <= avs_address(seq_ram_addr'range);
seq_csr_addr <= avs_address(seq_csr_addr'range);
seq_ram_writedata <= avs_writedata;
seq_csr_writedata <= avs_writedata;
pCTRL_STATUS : process(reset_n, clk)
begin
if(reset_n = '0') then
avs_read_d <= '0';
avs_readdatavalid <= '0';
avs_readdata_i <= (others => '0');
--
ttl_pd_en <= '0';
ttl_enc_p1_en <= '0';
ttl_enc_p2_en <= '0';
ttl_enc_zp_en <= '0';
rs422_pd_en <= '0';
rs422_enc_p1_en <= '0';
rs422_enc_p2_en <= '0';
rs422_enc_zp_en <= '0';
--
ttl_pd_fh <= '0';
ttl_enc_p1_fh <= '0';
ttl_enc_p2_fh <= '0';
ttl_enc_zp_fh <= '0';
rs422_pd_fh <= '0';
rs422_enc_p1_fh <= '0';
rs422_enc_p2_fh <= '0';
rs422_enc_zp_fh <= '0';
--
enc_emul_en <= '0';
enc_dir <= '0';
max_pulses_en <= '0';
zero_phase_ppr <= (others => '0');
nco_inc <= (others => '0');
abs_pos_init <= (others => '0');
--
pd_emul_en <= '0';
clr_pd_cnt <= '0';
pd_pulse_width <= std_logic_vector(to_unsigned(20, pd_pulse_width'length));
elsif(clk = '1' and clk'event) then
-- self-clearing registers
enc_init <= '0';
set_abs_pos <= '0';
max_pulses_start <= '0';
pd_gen <= '0';
clr_pd_cnt <= '0';
seq_start_req <= '0';
ext_trigger <= '0';
-- CTRL registers
if(avs_write_i = '1') then
case avs_address(3 downto 0) is
when CSR_OUT_ENABLE_ADDR =>
ttl_pd_en <= avs_writedata( 0);
ttl_enc_p1_en <= avs_writedata( 1);
ttl_enc_p2_en <= avs_writedata( 2);
ttl_enc_zp_en <= avs_writedata( 3);
rs422_pd_en <= avs_writedata( 4);
rs422_enc_p1_en <= avs_writedata( 5);
rs422_enc_p2_en <= avs_writedata( 6);
rs422_enc_zp_en <= avs_writedata( 7);
ttl_pd_fh <= avs_writedata( 8);
ttl_enc_p1_fh <= avs_writedata( 9);
ttl_enc_p2_fh <= avs_writedata(10);
ttl_enc_zp_fh <= avs_writedata(11);
rs422_pd_fh <= avs_writedata(12);
rs422_enc_p1_fh <= avs_writedata(13);
rs422_enc_p2_fh <= avs_writedata(14);
rs422_enc_zp_fh <= avs_writedata(15);
when CSR_ENC_CTRL_ADDR =>
enc_emul_en <= avs_writedata(0);
enc_init <= avs_writedata(1);
enc_dir <= avs_writedata(2);
set_abs_pos <= avs_writedata(3);
max_pulses_en <= avs_writedata(4);
max_pulses_start <= avs_writedata(5);
when CSR_ENC_NCO_INC_ADDR =>
nco_inc <= avs_writedata;
when CSR_PULSE_NUM_ADDR =>
max_pulses <= avs_writedata;
when CSR_ZP_PPR_ADDR =>
zero_phase_ppr <= avs_writedata(15 downto 0);
when CSR_POS_INIT_LSB_ADDR =>
abs_pos_init(31 downto 0) <= avs_writedata;
when CSR_POS_INIT_MSB_ADDR =>
abs_pos_init(39 downto 32) <= avs_writedata(7 downto 0);
when CSR_PD_CTRL_ADDR =>
pd_emul_en <= avs_writedata(0);
pd_gen <= avs_writedata(1);
clr_pd_cnt <= avs_writedata(2);
when CSR_PD_PULSE_W_ADDR =>
pd_pulse_width <= avs_writedata(pd_pulse_width'range);
when CSR_SEQ_CTRL_ADDR =>
seq_start_req <= avs_writedata(0);
ext_trigger <= avs_writedata(1);
seq_start_addr <= avs_writedata(24 downto 16);
when others => null;
end case;
end if;
-- Read Ctrl & Status registers
avs_read_d <= avs_read;
avs_readdatavalid <= avs_read_d;
if(avs_read_i = '1') then
-- default assignment
case avs_address(3 downto 0) is
when CSR_IP_ID_ADDR =>
avs_readdata_i <= CSR_IP_ID;
when CSR_IP_VER_ADDR =>
avs_readdata_i <= CSR_IP_VER;
when CSR_OUT_ENABLE_ADDR =>
avs_readdata_i <= (0 => ttl_pd_en,
1 => ttl_enc_p1_en,
2 => ttl_enc_p2_en,
3 => ttl_enc_zp_en,
4 => rs422_pd_en,
5 => rs422_enc_p1_en,
6 => rs422_enc_p2_en,
7 => rs422_enc_zp_en,
8 => ttl_pd_fh,
9 => ttl_enc_p1_fh,
10 => ttl_enc_p2_fh,
11 => ttl_enc_zp_fh,
12 => rs422_pd_fh,
13 => rs422_enc_p1_fh,
14 => rs422_enc_p2_fh,
15 => rs422_enc_zp_fh, others => '0');
when CSR_OUT_STATUS_ADDR =>
avs_readdata_i <= (0 => ttl_pd,
1 => ttl_enc_p1,
2 => ttl_enc_p2,
3 => ttl_enc_zp,
4 => rs422_pd,
5 => rs422_enc_p1,
6 => rs422_enc_p2,
7 => rs422_enc_zp, others => '0');
when CSR_ENC_CTRL_ADDR =>
avs_readdata_i <= (0 => enc_emul_en,
1 => enc_init,
2 => enc_dir,
3 => set_abs_pos,
4 => max_pulses_en,
5 => max_pulses_start,
6 => max_pulses_done,
31 => seq_present, others => '0');
when CSR_ENC_NCO_INC_ADDR =>
avs_readdata_i <= nco_inc;
when CSR_PULSE_NUM_ADDR =>
avs_readdata_i <= max_pulses;
when CSR_ZP_PPR_ADDR =>
avs_readdata_i <= X"0000" & zero_phase_ppr;
when CSR_POS_INIT_LSB_ADDR =>
avs_readdata_i <= abs_pos_init(31 downto 0);
when CSR_POS_INIT_MSB_ADDR =>
avs_readdata_i <= X"000000" & abs_pos_init(39 downto 32);
when CSR_POS_STAT_LSB_ADDR =>
avs_readdata_i <= abs_pos(31 downto 0);
when CSR_POS_STAT_MSB_ADDR =>
avs_readdata_i <= X"000000" & abs_pos(39 downto 32);
when CSR_PD_CTRL_ADDR =>
avs_readdata_i <= (0 => pd_emul_en, 2 => clr_pd_cnt, others => '0');
when CSR_PD_PULSE_W_ADDR =>
avs_readdata_i <= X"0000" & pd_pulse_width;
when CSR_PD_CNT_ADDR =>
avs_readdata_i <= X"00" & pd_cnt;
when CSR_SEQ_CTRL_ADDR =>
avs_readdata_i <= 7x"0" & seq_start_addr & 13x"0" & seq_busy & b"00";
when others =>
avs_readdata_i <= X"BAD1BAD0";
end case;
end if;
if(avs_read = '1') then
avs_addr_i <= avs_address;
end if;
-- output multiplexer
case? avs_addr_i( 9 downto 5) is
when "00000" =>
avs_readdata <= avs_readdata_i;
when "00001" =>
avs_readdata <= seq_csr_readdata;
when "1----" =>
avs_readdata <= seq_ram_readdata;
when others =>
avs_readdata <= X"BAD1BAD0";
end case?;
end if;
end process pCTRL_STATUS;
end architecture rtl;

View file

@ -0,0 +1,43 @@
-------------------------------------------------------------------------------
-- Title : enc_pd_emul_pkg
-- Project : SMB/Encoder Simulation board
-------------------------------------------------------------------------------
-- File : enc_pd_emul_pkg.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2018-05-31
-- Last update: 2018-08-22
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Package defining common constants for the encoder/pd emulator block
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package enc_pd_emul_1_pkg is
constant CSR_IP_ID_ADDR : std_logic_vector(3 downto 0) := 4x"0";
constant CSR_IP_VER_ADDR : std_logic_vector(3 downto 0) := 4x"1";
constant CSR_OUT_ENABLE_ADDR : std_logic_vector(3 downto 0) := 4x"2";
constant CSR_OUT_STATUS_ADDR : std_logic_vector(3 downto 0) := 4x"3";
constant CSR_ENC_CTRL_ADDR : std_logic_vector(3 downto 0) := 4x"4";
constant CSR_ENC_NCO_INC_ADDR : std_logic_vector(3 downto 0) := 4x"5";
constant CSR_PULSE_NUM_ADDR : std_logic_vector(3 downto 0) := 4x"6";
constant CSR_ZP_PPR_ADDR : std_logic_vector(3 downto 0) := 4x"7";
constant CSR_POS_INIT_LSB_ADDR : std_logic_vector(3 downto 0) := 4x"8";
constant CSR_POS_INIT_MSB_ADDR : std_logic_vector(3 downto 0) := 4x"9";
constant CSR_POS_STAT_LSB_ADDR : std_logic_vector(3 downto 0) := 4x"A";
constant CSR_POS_STAT_MSB_ADDR : std_logic_vector(3 downto 0) := 4x"B";
constant CSR_PD_CTRL_ADDR : std_logic_vector(3 downto 0) := 4x"C";
constant CSR_PD_PULSE_W_ADDR : std_logic_vector(3 downto 0) := 4x"D";
constant CSR_PD_CNT_ADDR : std_logic_vector(3 downto 0) := 4x"E";
constant CSR_SEQ_CTRL_ADDR : std_logic_vector(3 downto 0) := 4x"F";
constant SEQ_CSR_OFFSET : std_logic_vector(9 downto 0) := 10x"20";
constant SEQ_RAM_OFFSET : std_logic_vector(9 downto 0) := 10x"200";
end package enc_pd_emul_1_pkg;

View file

@ -0,0 +1,526 @@
-------------------------------------------------------------------------------
-- Title : enc_pd_emul_1_tb
-- Project : SMB
-------------------------------------------------------------------------------
-- File : enc_pd_emul_1_tb.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2018-05-31
-- Last update: 2018-06-15
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Testbench for the simple_frac_div.vhd
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
library work;
use work.log_pkg.all;
use work.avalon_verify_pkg.all;
use work.enc_pd_emul_1_pkg.all;
entity enc_pd_emul_1_tb is
-- ..
end entity enc_pd_emul_1_tb;
architecture behav of enc_pd_emul_1_tb is
constant CLK_PERIOD : time := 10 ns;
constant CLK_FREQ : real := 100.0e6; -- target clock frequency
-- Logging Verbosity Level
constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM;
constant MAX_SIM_TIME : time := 1 ms; -- Maximum simulation time
constant SEQ_ENABLE : boolean := true; -- false to not instantiate the sequencer
signal reset_n : std_logic := '0';
signal clk : std_logic := '0';
signal ttl_pd : std_logic;
signal ttl_enc_p1 : std_logic;
signal ttl_enc_p2 : std_logic;
signal ttl_enc_zp : std_logic;
signal rs422_pd : std_logic;
signal rs422_enc_p1 : std_logic;
signal rs422_enc_p2 : std_logic;
signal rs422_enc_zp : std_logic;
signal set_pos : std_logic;
signal inc_pos : std_logic;
signal dec_pos : std_logic;
signal abs_pos : std_logic_vector(39 downto 0);
signal avs_address : std_logic_vector( 9 downto 0);
signal avs_write : std_logic;
signal avs_writedata : std_logic_vector(31 downto 0);
signal avs_read : std_logic;
signal avs_readdatavalid : std_logic;
signal avs_readdata : std_logic_vector(31 downto 0);
-- TB specific signals
signal setup : boolean;
signal running : boolean;
signal passed : boolean := false;
signal failed : boolean := false;
signal test_timeout : boolean := false;
signal test_completed : boolean := false;
signal error_flag : boolean;
signal avs_mm_s_rec : mm_s_rec_t;
signal avs_mm_m_rec : mm_m_rec_t;
-----------------------------------------------------------------------------
-- Subprograms
-----------------------------------------------------------------------------
procedure wait_clk_cycles(cycles : in natural) is
begin
for n in 0 to cycles-1 loop
wait until clk = '1' and clk'event;
end loop; -- n
end procedure wait_clk_cycles;
-- generate the NCO increment corresponding to a given output frequency
function freq2NCO_inc(
f_out : real; f_clk : real) return std_logic_vector is
variable nco_inc : std_logic_vector(31 downto 0);
begin
nco_inc := std_logic_vector(to_unsigned(integer((f_out/f_clk)*(2.0**32)),32));
return nco_inc;
end function freq2NCO_inc;
begin -- architecture behav
clk <= not clk after 0.5*CLK_PERIOD;
clk_clk <= clk;
reset_reset_n <= reset_n;
-----------------------------------------------------------------------------
-- UUT
-----------------------------------------------------------------------------
iUUT : entity work.enc_pd_emul_1
generic map(
SEQ_ENABLE => SEQ_ENABLE)
port map (
clk => clk,
reset_n => reset_n,
ttl_pd => ttl_pd,
ttl_enc_p1 => ttl_enc_p1,
ttl_enc_p2 => ttl_enc_p2,
ttl_enc_zp => ttl_enc_zp,
rs422_pd => rs422_pd,
rs422_enc_p1 => rs422_enc_p1,
rs422_enc_p2 => rs422_enc_p2,
rs422_enc_zp => rs422_enc_zp,
abs_pos_out => abs_pos,
set_pos_out => set_pos,
inc_pos_out => inc_pos,
dec_pos_out => dec_pos,
avs_address => avs_address,
avs_write => avs_write,
avs_writedata => avs_writedata,
avs_read => avs_read,
avs_readdatavalid => avs_readdatavalid,
avs_readdata => avs_readdata);
-----------------------------------------------------------------------------
-- AVS Sequencer signal mapping
-----------------------------------------------------------------------------
avs_mm_s_rec.mm_readdata <= avs_readdata;
avs_mm_s_rec.mm_readdatavalid <= avs_readdatavalid;
avs_mm_s_rec.use_readvalid <= true;
avs_write <= avs_mm_m_rec.mm_write;
avs_writedata <= avs_mm_m_rec.mm_writedata;
avs_address <= avs_mm_m_rec.mm_address(avs_address'range);
avs_read <= avs_mm_m_rec.mm_read;
-----------------------------------------------------------------------------
-- Testbench Logic
-----------------------------------------------------------------------------
pTEST_PROC : process
procedure csr_read(addr : in std_logic_vector; data : out std_logic_vector(31 downto 0)) is
begin
mm_32b_read(std_logic_vector(resize(unsigned(addr),32)), data, avs_mm_s_rec, avs_mm_m_rec);
end procedure csr_read;
procedure csr_write(addr : in std_logic_vector; data : in std_logic_vector(31 downto 0)) is
begin
mm_32b_write(std_logic_vector(resize(unsigned(addr),32)), data, avs_mm_s_rec, avs_mm_m_rec);
end procedure csr_write;
procedure check_pos(exp_pos : in std_logic_vector(39 downto 0)) is
variable curr_pos : std_logic_vector(39 downto 0);
variable data : std_logic_vector(31 downto 0);
begin
csr_read(CSR_POS_STAT_LSB_ADDR, data);
curr_pos(31 downto 0) := data;
csr_read(CSR_POS_STAT_MSB_ADDR, data);
curr_pos(39 downto 32) := data(7 downto 0);
if(curr_pos /= exp_pos) then
log("ERROR: detected abs_pos = " & to_string(to_integer(signed(curr_pos))) & ", expected = " & to_string(to_integer(signed(exp_pos))) & ".", VLOW);
error_flag <= true;
end if;
end procedure check_pos;
procedure wait_pulses(timeout : in time := 0 ns) is
variable t0 : time;
variable done : boolean := false;
variable data : std_logic_vector(31 downto 0);
begin
t0 := now;
wait for 50 ns;
while done = false loop
-- check the done pulse
csr_read(CSR_ENC_CTRL_ADDR, data);
if(data(6) = '1') then
done := true;
elsif(timeout > 0 ns and now-t0 >= timeout) then
done := true;
log("ERROR: wait_pulses timeout.", VLOW);
error_flag <= true;
else
wait for 100 ns;
end if;
end loop;
end procedure wait_pulses;
procedure seq_ram_wr(addr : in std_logic_vector; data : in std_logic_vector(31 downto 0)) is
begin
csr_write(std_logic_vector(unsigned(SEQ_RAM_OFFSET)+unsigned(addr)), data);
end procedure seq_ram_wr;
-- Config the sequencer with various test procedures
procedure config_seq is
variable data : std_logic_vector(31 downto 0);
begin
-- issue a single PD, Offset 0x000
seq_ram_wr(10x"000", X"31000001"); -- VEC_SET, PD pulse
seq_ram_wr(10x"001", X"F0000000"); -- END
-- issue a PD after 10 encoder pulses, Offset 0x004
seq_ram_wr(10x"004", X"8100000A"); -- POS_WAIT (OP1+CURR_POS)
seq_ram_wr(10x"005", X"31000001"); -- VEC_SET, PD pulse
seq_ram_wr(10x"006", X"F0000000"); -- END
-- swathe-1
seq_ram_wr(10x"010", X"30000000"); -- VEC_SET, All zero
seq_ram_wr(10x"011", X"100000FF"); -- TRIG_MASK, all enabled
seq_ram_wr(10x"012", X"27000001"); -- TRIG_WAIT, (pulse_cnt_running = 0)
seq_ram_wr(10x"013", X"31000001"); -- VEC_SET, Issue a PD pulse, set the
-- enc_dir to 0
seq_ram_wr(10x"014", X"60000001"); -- BUS_BURST, 1 data
seq_ram_wr(10x"015", X"00000032"); -- seq_pulses = 50
seq_ram_wr(10x"016", X"26000001"); -- TRIG_WAIT, (pulse_cnt_running = 1)
seq_ram_wr(10x"017", X"25000001"); -- TRIG_WAIT, (max_pulses_done = 1)
seq_ram_wr(10x"018", X"21000005"); -- TRIG_WAIT, (5 us)
seq_ram_wr(10x"019", X"31000001"); -- VEC_SET, Issue a PD pulse
seq_ram_wr(10x"01A", X"30000002"); -- VEC_SET, set enc_dir to 1
seq_ram_wr(10x"01B", X"60000001"); -- BUS_BURST, 1 data
seq_ram_wr(10x"01C", X"0000002F"); -- seq_pulses = 50-3
seq_ram_wr(10x"01D", X"26000001"); -- TRIG_WAIT, (pulse_cnt_running = 1)
seq_ram_wr(10x"01E", X"25000001"); -- TRIG_WAIT, (max_pulses_done = 1)
seq_ram_wr(10x"01F", X"60000001"); -- BUS_BURST, 1 data
seq_ram_wr(10x"020", X"00000002"); -- seq_pulses = 2
seq_ram_wr(10x"021", X"26000001"); -- TRIG_WAIT, (pulse_cnt_running = 1)
seq_ram_wr(10x"022", X"25000001"); -- TRIG_WAIT, (max_pulses_done = 1)
seq_ram_wr(10x"023", X"60000001"); -- BUS_BURST, 1 data
seq_ram_wr(10x"024", X"00000001"); -- seq_pulses = 1
seq_ram_wr(10x"025", X"26000001"); -- TRIG_WAIT, (pulse_cnt_running = 1)
seq_ram_wr(10x"026", X"25000001"); -- TRIG_WAIT, (max_pulses_done = 1)
seq_ram_wr(10x"027", X"31000001"); -- VEC_SET, Issue a PD pulse
seq_ram_wr(10x"028", X"2000000A"); -- TRIG_WAIT, (100 ns)
seq_ram_wr(10x"029", X"F0000000"); -- END
log("Sequencer RAM configured.", VLOW);
end procedure config_seq;
-- start the sequencer at a given offset
procedure start_seq_proc(offset : in std_logic_vector) is
variable data : std_logic_vector(31 downto 0) := (others => '0');
begin
data(0) := '1'; -- start-request bit
data(24 downto 16) := offset; -- start-address
csr_write(CSR_SEQ_CTRL_ADDR, data);
end procedure start_seq_proc;
-- wait until the sequencer is not busy
procedure wait_seq_avail(timeout : in time := 0 ns) is
variable t0 : time;
variable done : boolean := false;
variable data : std_logic_vector(31 downto 0) := (others => '0');
begin
t0 := now;
wait for 50 ns;
while done = false loop
-- check the done pulse
csr_read(CSR_SEQ_CTRL_ADDR, data);
if(data(2) = '0') then
done := true;
elsif(timeout > 0 ns and now-t0 >= timeout) then
done := true;
log("ERROR: wait_seq_avail timeout.", VLOW);
error_flag <= true;
else
wait for 100 ns;
end if;
end loop;
end procedure wait_seq_avail;
begin
---------------------------------------------------------------------------
-- Initialize & Configure
---------------------------------------------------------------------------
reset_n <= '0';
mm_m_init(avs_mm_m_rec);
setup <= false;
running <= false;
error_flag <= false;
--Set the verbosity level for logging
set_log_verbosity(VERBOSITY_LEVEL);
--
wait for 100 ns;
reset_n <= '1';
-- Nothing really to do here
setup <= true;
---------------------------------------------------------------------------
-- Running
---------------------------------------------------------------------------
running <= true;
log_separator_line(VLOW);
log("Encoder/PD emulator verification:", VLOW);
log_separator_line(VLOW);
log("Manual Control testing ...", VLOW);
log_separator_line(VLOW);
log("Forcing the emulator outputs high ...", VMEDIUM);
-- Force high the outputs, on by one
csr_write(CSR_OUT_ENABLE_ADDR, X"00000100");
csr_write(CSR_OUT_ENABLE_ADDR, X"00000200");
csr_write(CSR_OUT_ENABLE_ADDR, X"00000400");
csr_write(CSR_OUT_ENABLE_ADDR, X"00000800");
csr_write(CSR_OUT_ENABLE_ADDR, X"00001000");
csr_write(CSR_OUT_ENABLE_ADDR, X"00002000");
csr_write(CSR_OUT_ENABLE_ADDR, X"00004000");
csr_write(CSR_OUT_ENABLE_ADDR, X"00008000");
csr_write(CSR_OUT_ENABLE_ADDR, X"0000AA00");
csr_write(CSR_OUT_ENABLE_ADDR, X"00005500");
csr_write(CSR_OUT_ENABLE_ADDR, X"0000FF00");
log("Done.", VMEDIUM);
-- Enable outputs
csr_write(CSR_OUT_ENABLE_ADDR, X"000000FF");
---------------------------------------------------------------------------
-- Manual Control
---------------------------------------------------------------------------
-- Configure Encoder NCO freq
csr_write(CSR_ENC_NCO_INC_ADDR, freq2NCO_inc(200.0e3, CLK_FREQ));
-- Init the encoder NCO - Preset Abs-Pos
csr_write(CSR_ENC_CTRL_ADDR, 32X"B");
-- Run the encoder in continuous mode, DIR-0
log("Running encoder in continuous mode, DIR-0 ...", VMEDIUM);
csr_write(CSR_ENC_CTRL_ADDR, 32X"1");
wait for 50 us;
-- Stop the encoder
csr_write(CSR_ENC_CTRL_ADDR, 32X"0");
log("Encoder stopped.", VMEDIUM);
wait for 10 us;
-- Switch to DIR-1
log("Running encoder in continuous mode, DIR-1 ...", VMEDIUM);
csr_write(CSR_ENC_CTRL_ADDR, 32X"5");
wait for 50 us;
-- Stop the encoder
csr_write(CSR_ENC_CTRL_ADDR, 32X"0");
log("Encoder stopped.", VMEDIUM);
wait for 20 us;
-- issue PD
csr_write(CSR_PD_CTRL_ADDR, 32X"3");
log("Running 100 steps in DIR-0 ...", VMEDIUM);
csr_write(CSR_PULSE_NUM_ADDR, 32X"64");
csr_write(CSR_ENC_CTRL_ADDR, 32X"18");
csr_write(CSR_ENC_CTRL_ADDR, 32X"31");
wait_pulses(0 us);
check_pos(std_logic_vector(to_signed(100, 40)));
-- issue PD
--csr_write(CSR_PD_PULSE_W_ADDR, 32X"1");
csr_write(CSR_PD_CTRL_ADDR, 32X"3");
log("Running 1 step in DIR-1 ...", VMEDIUM);
csr_write(CSR_PULSE_NUM_ADDR, 32X"1");
csr_write(CSR_ENC_CTRL_ADDR, 32X"35");
wait_pulses(10 us);
check_pos(std_logic_vector(to_signed(99, 40)));
log("Running 2 steps in DIR-0 ...", VMEDIUM);
csr_write(CSR_PULSE_NUM_ADDR, 32X"2");
csr_write(CSR_ENC_CTRL_ADDR, 32X"31");
wait_pulses(10 us);
check_pos(std_logic_vector(to_signed(101, 40)));
log("Running 51 steps in DIR-1 ...", VMEDIUM);
csr_write(CSR_PULSE_NUM_ADDR, 32X"33");
csr_write(CSR_ENC_CTRL_ADDR, 32X"35");
wait_pulses(0 us);
check_pos(std_logic_vector(to_signed(50, 40)));
wait for 25 us;
-- Preset the absolute position (-100)
csr_write(CSR_POS_INIT_MSB_ADDR, 32X"FF");
csr_write(CSR_POS_INIT_LSB_ADDR, 32X"FFFFFF9C");
csr_write(CSR_ENC_CTRL_ADDR, 32X"08");
log("Abs-Pos set to -100.", VMEDIUM);
log("Running 101 steps in DIR-0 ...", VMEDIUM);
csr_write(CSR_PULSE_NUM_ADDR, 32X"65");
csr_write(CSR_ENC_CTRL_ADDR, 32X"31");
wait_pulses(0 us);
check_pos(std_logic_vector(to_signed(1, 40)));
wait for 10 us;
log("Running 11 steps in DIR-1 ...", VMEDIUM);
csr_write(CSR_PULSE_NUM_ADDR, 32X"0B");
csr_write(CSR_ENC_CTRL_ADDR, 32X"35");
wait_pulses(0 us);
check_pos(std_logic_vector(to_signed(-10, 40)));
log("Manual Control testing completed.", VLOW);
---------------------------------------------------------------------------
-- Sequencer Control
---------------------------------------------------------------------------
if(SEQ_ENABLE = false) then
log("Skipping Sequencer testing...", VLOW);
else
log_separator_line(VLOW);
log("Sequencer Control testing ...", VLOW);
log_separator_line(VLOW);
config_seq;
-- enable the sequencer
csr_write(std_logic_vector(unsigned(SEQ_CSR_OFFSET)+3), 32x"1");
log("Sequencer Enabled.", VLOW);
wait for 50 us;
-- Issue a single PD:
start_seq_proc(9x"000");
wait_clk_cycles(5);
wait_seq_avail;
wait_clk_cycles(5);
-- Wait for an increment of 10 encoder steps, then issue a PD pulse
start_seq_proc(9x"004");
log("Running 10 steps in DIR-0 ...", VMEDIUM);
csr_write(CSR_PULSE_NUM_ADDR, 32X"0A");
csr_write(CSR_ENC_CTRL_ADDR, 32X"31");
wait for 50 us;
-- Wait for an increment of 10 encoder steps, then issue a PD pulse
start_seq_proc(9x"010");
log("Running a full swathe (50 steps forward, 50 steps backwards.", VMEDIUM);
wait_clk_cycles(5);
wait_seq_avail;
log("Completed.", VLOW);
end if; -- SEQ_ENABLE
wait_clk_cycles(10);
wait for 50 us;
---------------------------------------------------------------------------
-- End
---------------------------------------------------------------------------
passed <= true after 100 ns;
wait;
end process pTEST_PROC;
failed <= error_flag after 100 ns;
CHECK_SIM_TIMEOUT: process
begin -- process CHECK_SIM_TIMEOUT
while now < MAX_SIM_TIME loop
wait for 100 us;
end loop;
test_timeout <= true;
wait;
end process CHECK_SIM_TIMEOUT;
pREPORT_RESULT : process
begin
wait until failed = true or passed = true or test_timeout = true;
wait for 1 us;
log_separator_line(VLOW);
if(failed = true) then
log("FAILURE: test completed with errors.", VLOW);
elsif(passed = true) then
log("SUCCESS: test successfully completed.", VLOW);
elsif(test_timeout = true) then
log("FAILURE: test achieved max-sim-time without reaching ", VLOW);
log(" failed/passed condition.", VLOW);
end if;
log_separator_line(VLOW);
test_completed <= true;
end process pREPORT_RESULT;
end architecture behav;

View file

@ -0,0 +1,369 @@
[{
"ip_name": "pulse_gen_1",
"bus": "csr",
"description": "Generate Fire-Requests, based on the absolute position and PD inputs",
"sub_blocks": {
"local": {
"instance": "",
"process": "cpp, htm",
"offset": "0x0"
},
"generic_sequencer_15": {
"instance": "channel",
"process": "cpp, htm",
"offset": "0x20"
}
},
"registers": {
"ip_id" : {
"address" : "0",
"width" : "32",
"description" : "Unique ID for this IP block",
"fields": {
"ip_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x13",
"description" : "IP identifier number"
},
"mfr_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0xFF",
"description" : "Manufacturer number"
},
"reserved" : {
"type" : "rsv",
"bit_len" : "16",
"description" : "Reserved bits"
}
}
},
"ip_ver" : {
"address" : "1",
"width" : "32",
"description" : "IP Version",
"fields": {
"minor_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x01",
"description" : "Minor number"
},
"major_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x00",
"description" : "Major number"
},
"reserved" : {
"type" : "rsv",
"bit_len" : "16",
"description" : "Reserved bits"
}
}
},
"pulse_gen_control": {
"address": "2",
"width": "32",
"description": "",
"fields": {
"enable": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Pulse-Generator Enable"
},
"bypass_channel_controller": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "By-Pass Ch-Ctrl (=> Fractional Divider only)"
},
"reserved-0": {
"type": "rsv",
"bit_len": "1",
"description": ""
},
"bypass_delay_equalizer": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Bypass Delay Equalization"
},
"sw_control_dp_dir": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Dual-Phase Direction, when Ch-Ctrl is bypassed"
},
"pd_queue_error_flag": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "PD Queue Overflow Error"
},
"delay_equalizer_error_flag": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "Delay Equalizer Overflow Error"
},
"reserved-1": {
"type": "rsv",
"bit_len": "1",
"description": ""
},
"ch_mask_status": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "ch_mask status"
},
"fire_enable_status": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "fire enable status"
},
"dual_phase_directionality_select_status": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "Dual-Phase Direction status"
},
"reserved-2": {
"type": "rsv",
"bit_len": "5",
"description": ""
},
"enable_output": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Enable fire-request output"
},
"trigger_abort_fire": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Abort pending request of fire-request issued by Ch-Ctrl"
},
"reset_diag_regs" : {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Reset the local PD and Fire-Request counters"
},
"reserved-3" : {
"type": "rsv",
"bit_len": "13",
"description": ""
}
}
},
"pd_offset_dir_0": {
"type": "w",
"address": "3",
"reset": "0x00",
"width": "32",
"description": "PD Offset for DIR-0"
},
"pd_offset_dir_1": {
"type": "w",
"address": "4",
"reset": "0x00",
"width": "32",
"description": "PD Offset for DIR-1"
},
"channel_delay": {
"type": "w",
"address": "5",
"reset": "0x00",
"width": "32",
"description": "Channel Delay (Delay Equalization)"
},
"channel_controller_control": {
"address": "6",
"width": "16",
"description": "",
"fields": {
"start_seq_trigger": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Ch-Ctrl Sequencer Start-Request"
},
"busy": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "Ch-Ctrl Sequencer Busy"
},
"reserved0": {
"type": "rsv",
"bit_len": "6",
"description": ""
},
"sequencer_start_address": {
"type": "w",
"bit_len": "8",
"reset" : "0x0",
"description": "Ch-Ctrl Sequencer Start-Address"
}
}
},
"fractional_divider_control": {
"address": "7",
"width": "8",
"description": "Fractional Divider Control Register",
"fields": {
"enable": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Fractional Divider Enable"
},
"udp_max_pos": {
"type": "r",
"bit_len": "1",
"reset": "0x0",
"description": "Clear the encoder jitter for DIR-0"
},
"udp_min_pos": {
"type": "r",
"bit_len": "6",
"reset": "0x0",
"description": "Clear the encoder jitter for DIR-1"
}
}
},
"output_pulse_width": {
"address": "8",
"width": "24",
"description": "Output pulse control",
"fields": {
"pulse_width": {
"type": "w",
"bit_len": "8",
"reset": "0x14",
"description": "Default Pulse-Width"
},
"reserved0": {
"type": "rsv",
"bit_len": "8",
"description": ""
},
"extended_pulse_width": {
"type": "w",
"bit_len": "8",
"reset": "0x32",
"description": "Extended Pulse-Width"
}
}
},
"overdrive_control": {
"address": "9",
"width": "32",
"description": "Overdrive Control",
"fields": {
"reset": {
"type": "w",
"bit_len": "1",
"reset": "0x0",
"description": "Clear the Overdrive event counter"
},
"reserved0": {
"type": "rsv",
"bit_len": "15",
"description": ""
},
"threshold": {
"type": "w",
"bit_len": "16",
"reset" : "0x63",
"description": "Overdrive threshold"
}
}
},
"overdrive_counter": {
"type": "w",
"address": "10",
"reset": "0x00",
"width": "32",
"description": "Overdrive event counter"
},
"divider_ratio_int": {
"type": "w",
"address": "11",
"reset": "0x00",
"width": "10",
"description": "Integer part of the Division ratio"
},
"divider_ratio_fraction": {
"type": "w",
"address": "12",
"reset": "0x00",
"width": "24",
"description": "Fractional part of the Division ratio"
},
"subpixel_offset_int": {
"type": "w",
"address": "13",
"reset": "0x00",
"width": "32",
"description": "Integer part of the Sub-pixel Offset"
},
"subpixel_offset_fraction": {
"type": "w",
"address": "14",
"reset": "0x00",
"width": "24",
"description": "Fractional part of the Sub-pixel Offset"
},
"abs_position_max": {
"type": "r",
"address": "15",
"reset": "0x00",
"width": "32",
"description": "Absolute Position Maximum"
},
"abs_position_min": {
"type": "r",
"address": "16",
"reset": "0x00",
"width": "32",
"description": "Absolute Position Minimum"
},
"abs_position": {
"type": "r",
"address": "17",
"reset": "0x00",
"width": "32",
"description": "Current Absolute Position "
},
"pd_counter": {
"type": "r",
"address": "18",
"reset": "0x00",
"width": "32",
"description": "PD counter"
},
"fire_req_counter": {
"type": "r",
"address": "19",
"reset": "0x00",
"width": "32",
"description": "Fire-Request counter"
},
"channel_controller_seq": {
"type": "w",
"address": "512",
"reset": "0x00",
"width": "32",
"description": "Ch-Ctrl buffer offset (size=256)"
}
}
}]

View file

@ -0,0 +1,201 @@
-- megafunction wizard: %FIFO%
-- GENERATION: STANDARD
-- VERSION: WM1.0
-- MODULE: scfifo
-- ============================================================
-- File Name: sync_fifo_1.vhd
-- Megafunction Name(s):
-- scfifo
--
-- Simulation Library Files(s):
-- altera_mf
-- ============================================================
-- ************************************************************
-- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
--
-- 14.1.1 Build 190 01/19/2015 SJ Web Edition
-- ************************************************************
--Copyright (C) 1991-2015 Altera Corporation. All rights reserved.
--Your use of Altera Corporation's design tools, logic functions
--and other software and tools, and its AMPP partner logic
--functions, and any output files from any of the foregoing
--(including device programming or simulation files), and any
--associated documentation or information are expressly subject
--to the terms and conditions of the Altera Program License
--Subscription Agreement, the Altera Quartus II License Agreement,
--the Altera MegaCore Function License Agreement, or other
--applicable license agreement, including, without limitation,
--that your use is for the sole purpose of programming logic
--devices manufactured by Altera and sold by Altera or its
--authorized distributors. Please refer to the applicable
--agreement for further details.
LIBRARY ieee;
USE ieee.std_logic_1164.all;
LIBRARY altera_mf;
USE altera_mf.all;
use work.common_pkg.all;
entity sync_fifo_1 is
generic (
FIFO_WIDTH : natural range 1 to 32;
FIFO_DEPTH : natural range 1 to 8182);
port (
sclr : in std_logic;
clock : in std_logic;
data : in std_logic_vector (FIFO_WIDTH-1 downto 0);
rdreq : in std_logic;
wrreq : in std_logic;
empty : out std_logic;
full : out std_logic;
q : out std_logic_vector (FIFO_WIDTH-1 downto 0);
usedw : out std_logic_vector (log2(FIFO_DEPTH)-1 downto 0)
);
end sync_fifo_1;
ARCHITECTURE SYN OF sync_fifo_1 IS
SIGNAL sub_wire0 : STD_LOGIC ;
SIGNAL sub_wire1 : STD_LOGIC ;
SIGNAL sub_wire2 : STD_LOGIC_VECTOR (FIFO_WIDTH-1 DOWNTO 0);
SIGNAL sub_wire3 : STD_LOGIC_VECTOR (log2(FIFO_DEPTH)-1 DOWNTO 0);
COMPONENT scfifo
GENERIC (
add_ram_output_register : STRING;
intended_device_family : STRING;
lpm_numwords : NATURAL;
lpm_showahead : STRING;
lpm_type : STRING;
lpm_width : NATURAL;
lpm_widthu : NATURAL;
overflow_checking : STRING;
underflow_checking : STRING;
use_eab : STRING
);
PORT (
sclr : IN STD_LOGIC ;
clock : IN STD_LOGIC ;
data : IN STD_LOGIC_VECTOR (FIFO_WIDTH-1 DOWNTO 0);
rdreq : IN STD_LOGIC ;
wrreq : IN STD_LOGIC ;
empty : OUT STD_LOGIC ;
full : OUT STD_LOGIC ;
q : OUT STD_LOGIC_VECTOR (FIFO_WIDTH-1 DOWNTO 0);
usedw : OUT STD_LOGIC_VECTOR (log2(FIFO_DEPTH)-1 DOWNTO 0)
);
END COMPONENT;
BEGIN
empty <= sub_wire0;
full <= sub_wire1;
q <= sub_wire2(FIFO_WIDTH-1 DOWNTO 0);
usedw <= sub_wire3(log2(FIFO_DEPTH)-1 DOWNTO 0);
scfifo_component : scfifo
GENERIC MAP (
add_ram_output_register => "OFF",
intended_device_family => "Cyclone V",
lpm_numwords => FIFO_DEPTH,
lpm_showahead => "OFF",
lpm_type => "scfifo",
lpm_width => FIFO_WIDTH,
lpm_widthu => log2(FIFO_DEPTH-1),
overflow_checking => "ON",
underflow_checking => "ON",
use_eab => "ON"
)
PORT MAP (
sclr => sclr,
clock => clock,
data => data,
rdreq => rdreq,
wrreq => wrreq,
empty => sub_wire0,
full => sub_wire1,
q => sub_wire2,
usedw => sub_wire3
);
END SYN;
-- ============================================================
-- CNX file retrieval info
-- ============================================================
-- Retrieval info: PRIVATE: AlmostEmpty NUMERIC "0"
-- Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC "-1"
-- Retrieval info: PRIVATE: AlmostFull NUMERIC "0"
-- Retrieval info: PRIVATE: AlmostFullThr NUMERIC "-1"
-- Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC "0"
-- Retrieval info: PRIVATE: Clock NUMERIC "0"
-- Retrieval info: PRIVATE: Depth NUMERIC "256"
-- Retrieval info: PRIVATE: Empty NUMERIC "1"
-- Retrieval info: PRIVATE: Full NUMERIC "1"
-- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone V"
-- Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC "0"
-- Retrieval info: PRIVATE: LegacyRREQ NUMERIC "1"
-- Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC "0"
-- Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC "0"
-- Retrieval info: PRIVATE: Optimize NUMERIC "0"
-- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0"
-- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
-- Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC "0"
-- Retrieval info: PRIVATE: UsedW NUMERIC "1"
-- Retrieval info: PRIVATE: Width NUMERIC "32"
-- Retrieval info: PRIVATE: dc_aclr NUMERIC "0"
-- Retrieval info: PRIVATE: diff_widths NUMERIC "0"
-- Retrieval info: PRIVATE: msb_usedw NUMERIC "0"
-- Retrieval info: PRIVATE: output_width NUMERIC "32"
-- Retrieval info: PRIVATE: rsEmpty NUMERIC "1"
-- Retrieval info: PRIVATE: rsFull NUMERIC "0"
-- Retrieval info: PRIVATE: rsUsedW NUMERIC "0"
-- Retrieval info: PRIVATE: sc_aclr NUMERIC "0"
-- Retrieval info: PRIVATE: sc_sclr NUMERIC "1"
-- Retrieval info: PRIVATE: wsEmpty NUMERIC "0"
-- Retrieval info: PRIVATE: wsFull NUMERIC "1"
-- Retrieval info: PRIVATE: wsUsedW NUMERIC "0"
-- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
-- Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING "OFF"
-- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V"
-- Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC "256"
-- Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING "OFF"
-- Retrieval info: CONSTANT: LPM_TYPE STRING "scfifo"
-- Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "32"
-- Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC "8"
-- Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING "ON"
-- Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING "ON"
-- Retrieval info: CONSTANT: USE_EAB STRING "ON"
-- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT NODEFVAL "clock"
-- Retrieval info: USED_PORT: data 0 0 32 0 INPUT NODEFVAL "data[31..0]"
-- Retrieval info: USED_PORT: empty 0 0 0 0 OUTPUT NODEFVAL "empty"
-- Retrieval info: USED_PORT: full 0 0 0 0 OUTPUT NODEFVAL "full"
-- Retrieval info: USED_PORT: q 0 0 32 0 OUTPUT NODEFVAL "q[31..0]"
-- Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL "rdreq"
-- Retrieval info: USED_PORT: sclr 0 0 0 0 INPUT NODEFVAL "sclr"
-- Retrieval info: USED_PORT: usedw 0 0 8 0 OUTPUT NODEFVAL "usedw[7..0]"
-- Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL "wrreq"
-- Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0
-- Retrieval info: CONNECT: @data 0 0 32 0 data 0 0 32 0
-- Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
-- Retrieval info: CONNECT: @sclr 0 0 0 0 sclr 0 0 0 0
-- Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
-- Retrieval info: CONNECT: empty 0 0 0 0 @empty 0 0 0 0
-- Retrieval info: CONNECT: full 0 0 0 0 @full 0 0 0 0
-- Retrieval info: CONNECT: q 0 0 32 0 @q 0 0 32 0
-- Retrieval info: CONNECT: usedw 0 0 8 0 @usedw 0 0 8 0
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.vhd TRUE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.inc FALSE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.cmp FALSE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.bsf FALSE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_inst.vhd FALSE
-- Retrieval info: LIB_FILE: altera_mf

View file

@ -0,0 +1,83 @@
-------------------------------------------------------------------------------
-- Title : pulse_conditioning_1
-- Project : EMB
-------------------------------------------------------------------------------
-- File : pulse_conditioning_1.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2016-05-28
-- Last update: 2016-10-25
-- SVN ID : Git
-- Standard : VHDL'93
-------------------------------------------------------------------------------
-- Description:
-- merge input pulses and pd events into a single bit signal, extend the witdth
-- to make sure the signal is safely transmitted over the POF
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity pulse_conditioning_1 is
port (
reset_n : in std_logic;
clk : in std_logic;
enable : in std_logic;
pulse_in : in std_logic;
pd_in : in std_logic;
pulse_width : in std_logic_vector(7 downto 0);
pulse_width_ext : in std_logic_vector(7 downto 0);
pulse_out : out std_logic);
end pulse_conditioning_1;
architecture RTL of pulse_conditioning_1 is
signal pulse_in_d, pd_in_d, pd_detected, pulse_detected : std_logic;
signal mask_pulse_en, pulse_width_not_zero : std_logic;
signal pulse_width_cnt : std_logic_vector(7 downto 0);
begin -- RTL
-- Extend the pulse width of input pulse:
-- use 'ext_pulse_width' when there is a pending PD event, 'pulse_width' otherwise.
-- Time-align output pulses on the faaling edge, to prevent a variable
-- latency when decoding pulses at the receiving side of the transmission
-- medium (POF).
pPULSE_CONDITIONING : process(reset_n, clk)
begin
if(reset_n = '0') then
pd_in_d <= '0';
pd_detected <= '0';
pulse_out <= '0';
pulse_in_d <= '0';
mask_pulse_en <= '0';
pulse_width_cnt <= (others => '0');
elsif(clk = '1' and clk'event) then
pd_in_d <= pd_in;
if(pulse_detected = '1') then
pd_detected <= '0';
elsif(enable = '1' and pd_in = '1' and pd_in_d = '0') then
pd_detected <= '1';
end if;
pulse_in_d <= pulse_in;
if(pulse_detected = '1') then
pulse_width_cnt <= pulse_width_ext;
elsif(pulse_width_not_zero = '1') then
pulse_width_cnt <= std_logic_vector(unsigned(pulse_width_cnt)-1);
end if;
if(pulse_detected = '1' and pd_detected = '0') then
mask_pulse_en <= '1';
elsif(unsigned(pulse_width_cnt) = (unsigned(pulse_width)+1)) then
mask_pulse_en <= '0';
end if;
pulse_out <= pulse_width_not_zero and enable and not mask_pulse_en;
end if;
end process pPULSE_CONDITIONING;
pulse_detected <= pulse_in and not pulse_in_d;
pulse_width_not_zero <= '1' when unsigned(pulse_width_cnt) /= 0 else '0';
end RTL;

View file

@ -0,0 +1,679 @@
-------------------------------------------------------------------------------
-- Title : Pulse Generator
-- Project : EMB-1
-------------------------------------------------------------------------------
-- File : Pulse Generator.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2016-10-24
-- Last update: 2018-08-23
-- SVN ID : Git
-- Standard : VHDL'93
-------------------------------------------------------------------------------
-- Description:
-- The Pulse Generator implements the following functionalities:
-- PD queue, with channel specific offset (positional)
-- Pulse Scaling (Fractional Divider)
-- Delay Equalization: compensate for the difference in the channel latency
-- when daisy-chaining multiple EMBs.
-- Pulse-Width conditioning, for transmission over the POF (to be moved out
-- from the block in the future)
-- Channel control: Mask/Unmask pulse generation based on PD, image length,
-- directionality etc.
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.pulse_generator_1_pkg.all;
entity pulse_generator_1 is
generic(
pulse_delay_equal_en : boolean := true;
out_pulse_condition : boolean := true);
port(
clk : in std_logic;
reset_n : in std_logic := '1';
--
init : in std_logic;
-- Sequencer I/Os
pd_in : in std_logic;
abs_position : in std_logic_vector(31 downto 0);
dp_dir : out std_logic;
pulse_out : out std_logic;
-- diagnostic outputs
filtered_pd : out std_logic;
ch_pd : out std_logic;
ch_mask : out std_logic;
raw_pulse_out : out std_logic;
enc_pulse : out std_logic;
-----------------------------------------------------------------------
-- Avalon MM Interface
-----------------------------------------------------------------------
avs_address : in std_logic_vector( 9 downto 0);
avs_write : in std_logic;
avs_writedata : in std_logic_vector(31 downto 0);
avs_read : in std_logic;
avs_readdatavalid : out std_logic;
avs_readdata : out std_logic_vector(31 downto 0));
end entity pulse_generator_1;
architecture rtl of pulse_generator_1 is
-- constants
constant CSR_IP_ID : std_logic_vector(31 downto 0) := x"0000FF13";
constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"00000001";
signal init_de, init_qd, enable, loc_pd, pd_queue_error : std_logic;
signal ch_ctrl_start_req, pd_pulse, filt_pd, filt_pd_d : std_logic;
signal ch_ctrl_write, ch_ctrl_read, ch_ctrl_busy, enable_i : std_logic;
signal ch_mask_i, bypass_ch_ctrl, bypass_delay_equal : std_logic;
signal div_pulse, gated_pulse, retimed_pulse, pulse_out_i : std_logic;
signal avs_write_i, avs_read_d, avs_read_i, de_queue_error : std_logic;
signal cnt_dir, dp_dir_i, ch_mask_d, ch_ctrl_start_req_i : std_logic;
signal set_first_pd, pulse_out_ii : std_logic;
signal loc_pulse_out_d, loc_pulse, first_pulse, dp_dir_d : std_logic;
signal overdrive_rst, overdrv_event, pulse_scale_out : std_logic;
signal start_img_req, start_img_req_d, start_img, start_img_d : std_logic;
signal start_img_dd, fire_enable, img_completed : std_logic;
signal sw_ctrl_dp_dir, enable_out, ch_ctrl_start_req_d : std_logic;
signal add_img_size, add_img_size_d, abort_fire : std_logic;
signal ch_ctrl_csr_write, ch_ctrl_csr_read, frac_div_en_i : std_logic;
signal upd_max_pos, upd_min_pos, frac_div_en, gen_filt_pd : std_logic;
signal upd_max_pos_i, upd_min_pos_i, dir_change, first_pd : std_logic;
signal pd_in_d, filt_pd_i, abs_pos_lsb, ch_ctrl_start_req_ii : std_logic := '0';
signal prevent_div_restart, rst_jitter, rst_diag_regs : std_logic;
signal fire_req, fire_req_d, fire_req_p : std_logic;
--
signal ch_ctrl_csr_addr, ch_ctrl_trigger_in : std_logic_vector( 3 downto 0);
signal avs_addr : std_logic_vector( 4 downto 0);
signal pulse_width, pulse_width_ext, init_v : std_logic_vector( 7 downto 0);
signal ch_ctrl_start_addr : std_logic_vector( 7 downto 0);
signal ch_ctrl_address : std_logic_vector( 7 downto 0);
signal avs_address_i : std_logic_vector( 9 downto 0);
signal overdrive_events, overdrive_thres : std_logic_vector(15 downto 0);
signal pulse_interval : std_logic_vector(15 downto 0);
signal img_size, pixel_cnt : std_logic_vector(23 downto 0);
signal ch_ctrl_vector_out : std_logic_vector(23 downto 0);
signal ch_offset, ch_delay, avs_readdata_i : std_logic_vector(31 downto 0);
signal ch_ctrl_writedata, ch_ctrl_readdata : std_logic_vector(31 downto 0);
signal ch_ctrl_csr_writedata : std_logic_vector(31 downto 0);
signal ch_ctrl_csr_readdata : std_logic_vector(31 downto 0);
signal ch_offset_dir0, ch_offset_dir1 : std_logic_vector(31 downto 0);
signal abs_pos_max, abs_pos_min : std_logic_vector(31 downto 0);
signal last_pd_pos : std_logic_vector(31 downto 0);
signal pd_in_cnt, fire_req_cnt : std_logic_vector(31 downto 0);
signal div_offset, div_ratio : std_logic_vector(33 downto 0);
begin
-----------------------------------------------------------------------------
-- PD Jitter management
-----------------------------------------------------------------------------
-- Filter PD pulses in the following situations:
-- I. dp_dir = '0', no new max on abs_pos
-- II. dp_dir = '1', no new min on abs_pos
pd_pulse <= pd_in and not pd_in_d;
gen_filt_pd <= '1' when pd_pulse = '1' and (first_pd = '1' or (dp_dir_i = '0' and signed(abs_position) > signed(last_pd_pos)) or (dp_dir_i = '1' and signed(abs_position) < signed(last_pd_pos))) else '0';
set_first_pd <= '1' when init_qd = '1' or (dp_dir_i = '0' and upd_max_pos_i = '1') or (dp_dir_i = '1' and upd_min_pos_i = '1') or rst_jitter = '1' else '0';
pPD_JITTER_MNG : process(clk)
begin
if(clk = '1' and clk'event) then
pd_in_d <= pd_in;
if(set_first_pd = '1') then
first_pd <= '1';
elsif(filt_pd = '1') then
first_pd <= '0';
end if;
filt_pd <= gen_filt_pd;
filt_pd_d <= filt_pd;
if(set_first_pd = '1' or gen_filt_pd = '1') then
last_pd_pos <= abs_position;
end if;
end if;
end process pPD_JITTER_MNG;
filtered_pd <= filt_pd;
-----------------------------------------------------------------------------
-- PD Queue
-----------------------------------------------------------------------------
-- To implement the PD queuse a standard queue-and-delay block is used,
-- driven by the absolute position instead of a time counter. To prevent
-- confusing the queue-and-delay block, a PD pulse is de-asserted only on the
-- next increment of absolute position
pLOC_PD_IN : process(clk)
begin
if(clk = '1' and clk'event) then
abs_pos_lsb <= abs_position(0);
if(filt_pd = '1' and filt_pd_d = '0') then
filt_pd_i <= '1';
elsif(init = '1' or (filt_pd = '0' and filt_pd_i = '1' and abs_position(0) /= abs_pos_lsb)) then
filt_pd_i <= '0';
end if;
end if;
end process pLOC_PD_IN;
-- Note on the maximum size of queue: long PD queues must be taken care of at SW
-- level, here the size is limited to 128 (on the PMB it was 16)
iPD_queue: entity work.queue_and_delay_1
generic map (
use_ext_time => true,
queue_size => 128)
port map (
rstN => reset_n,
clk => clk,
init => init_qd,
cnt_dir => cnt_dir,
delay => ch_offset,
ext_time => abs_position,
wave_in => filt_pd_i,
wave_out => loc_pd,
ovf_error => pd_queue_error);
-- make sure the PD queue is always cleared whenever there is a change of direction
dir_change <= dp_dir_i xor dp_dir_d;
init_qd <= not enable or init or dir_change;
-- channel offset selection
pCH_OFF_SEL : process(clk)
begin
if(clk = '1' and clk'event) then
if(dp_dir_i = '0') then
ch_offset <= ch_offset_dir0;
else
ch_offset <= ch_offset_dir1;
end if;
end if;
end process pCH_OFF_SEL;
-- output to the monitoring point/event-logger
ch_pd <= loc_pd;
-- enable the queue_and_delay counter to count backward
cnt_dir <= ch_ctrl_vector_out(0);
pDIR_CHG : process(clk)
begin
if(clk = '1' and clk'event) then
if(bypass_ch_ctrl = '1') then
dp_dir_i <= sw_ctrl_dp_dir;
else
dp_dir_i <= ch_ctrl_vector_out(0);
end if;
dp_dir_d <= dp_dir_i;
end if;
end process pDIR_CHG;
dp_dir <= dp_dir_i;
-----------------------------------------------------------------------------
-- Channel control
-----------------------------------------------------------------------------
-- Generate a gating signal to apply to the divider output.
-- The gating signal is generated through a generic sequencer:
-- Sequencer triggers:
-- - Absolute position (bus)
-- - PD (from PD queue)
-- Sequencer outputs
-- - Gating signal (ch_mask)
--i_channel_control : entity work.emb_generic_seq_core
i_channel_control : entity work.generic_seq_core_15
generic map (
TRIGGER_WIDTH => 4,
VECTOR_WIDTH => 24,
BUS_WIDTH => 1,
POS_WIDTH => 24,
SEQ_DEPTH => 256,
ADD_VEC_PIPE => false,
VECT_RAMP_EN => false,
BUS_BURST_EN => false,
POS_BUS_EN => true,
ALU_EN => false)
port map (
clk => clk,
reset_n => reset_n,
avs_csr_address => ch_ctrl_csr_addr,
avs_csr_write => ch_ctrl_csr_write,
avs_csr_writedata => ch_ctrl_csr_writedata,
avs_csr_read => ch_ctrl_csr_read,
avs_csr_readdata => ch_ctrl_csr_readdata,
avs_seq_address => ch_ctrl_address,
avs_seq_write => ch_ctrl_write,
avs_seq_writedata => ch_ctrl_writedata,
avs_seq_read => ch_ctrl_read,
avs_seq_readdata => ch_ctrl_readdata,
start_req => ch_ctrl_start_req,
start_addr => ch_ctrl_start_addr,
trigger_in => ch_ctrl_trigger_in,
pos_in => abs_position(23 downto 0),
busy => ch_ctrl_busy,
vector_out => ch_ctrl_vector_out,
bus_data => open,
bus_valid => open,
bus_ack => '0');
ch_ctrl_trigger_in <= (0 => loc_pd, 1 => fire_enable, 2 => gated_pulse, 3 => (not fire_enable));
ch_mask_i <= fire_enable or ch_ctrl_vector_out(1) or bypass_ch_ctrl;
-- output to the monitoring point/event-logger
ch_mask <= ch_mask_i;
start_img_req <= ch_ctrl_vector_out(2);
add_img_size <= ch_ctrl_vector_out(3);
prevent_div_restart <= ch_ctrl_vector_out(4);
--rst_jitter <= ch_ctrl_vector_out(5); -- The actual assignment is
--latched exactly as dp_dir to make sure both of them change at the same
--clock cycle
ch_ctrl_start_req_i <= ch_ctrl_start_req_ii and enable and not init;
ch_ctrl_start_req <= ch_ctrl_start_req_i and not ch_ctrl_start_req_d;
pGEN_IMAGE: process(clk)
begin
if(clk = '1' and clk'event) then
ch_ctrl_start_req_d <= ch_ctrl_start_req_i;
start_img_req_d <= start_img_req;
start_img_d <= start_img;
start_img_dd <= start_img_d;
add_img_size_d <= add_img_size;
if(img_completed = '1' or enable = '0' or abort_fire = '1') then
fire_enable <= '0';
elsif(start_img_dd = '1' and fire_enable = '0') then
fire_enable <= '1';
end if;
if(start_img = '1' and fire_enable = '0') then
img_size <= X"00" & ch_ctrl_vector_out(23 downto 8);
elsif(add_img_size = '1' and add_img_size_d = '0') then
img_size <= std_logic_vector(unsigned(img_size)+unsigned(ch_ctrl_vector_out(23 downto 8)));
end if;
if(start_img = '1' and fire_enable = '0') then
pixel_cnt <= (others => '0');
elsif(fire_enable = '1' and div_pulse = '1') then
pixel_cnt <= std_logic_vector(unsigned(pixel_cnt)+1);
end if;
end if;
end process pGEN_IMAGE;
start_img <= start_img_req and not start_img_req_d;
img_completed <= '1' when fire_enable = '1' and unsigned(pixel_cnt) = unsigned(img_size) else '0';
-- DO NOT REMOVE: USED BY THE TESTBENCH!
-- synthesis translate_off
p_ch_mask_d : process(clk)
begin
if(clk = '1' and clk'event) then
ch_mask_d <= ch_mask_i;
end if;
end process p_ch_mask_d;
-- synthesis translate_on
-----------------------------------------------------------------------------
-- Fractional Divider
-----------------------------------------------------------------------------
iFracDiv : entity work.simple_frac_div_1
port map (
clk => clk,
enable => frac_div_en,
dir => dp_dir_i,
upd_max_pos => upd_max_pos,
upd_min_pos => upd_min_pos,
abs_pos_max => abs_pos_max,
abs_pos_min => abs_pos_min,
offset => div_offset,
ratio => div_ratio,
abs_pos => abs_position,
enc_pulse => enc_pulse,
fire => div_pulse,
fire_cnt => open);
-- In case upd_min_pos/upd_max_pos are asserted as a consequence of init, you
-- need to guarantee a sufficient delay to make sure abs_pos get reset before
-- updating min/max pos
p_pulse_div_switch : process(clk)
begin
if(clk = '1' and clk'event) then
rst_jitter <= ch_ctrl_vector_out(5);
upd_max_pos <= upd_max_pos_i or init_v(0) or dir_change or (rst_jitter and not dp_dir_i);
upd_min_pos <= upd_min_pos_i or init_v(0) or dir_change or (rst_jitter and dp_dir_i);
frac_div_en <= frac_div_en_i and enable and not init and not ((start_img and not prevent_div_restart and not bypass_ch_ctrl) or dir_change);
end if;
end process p_pulse_div_switch;
-- output to the monitoring point/event-logger
raw_pulse_out <= div_pulse;
-----------------------------------------------------------------------------
-- Pulse Gating
-----------------------------------------------------------------------------
gated_pulse <= div_pulse and ch_mask_i and enable_out;
-----------------------------------------------------------------------------
-- Delay Equalization
-----------------------------------------------------------------------------
-- compendate for variation in the channel delay when daisy-chaining multiple
-- EMBs/HMBs:
gPULSE_DELAY_EQUAL: if pulse_delay_equal_en = true generate
iDE: entity work.queue_and_delay_1
generic map (
use_ext_time => false,
queue_size => 256)
port map (
rstN => reset_n,
clk => clk,
init => init_de,
cnt_dir => '0',
delay => ch_delay,
ext_time => (others => '0'),
wave_in => gated_pulse,
wave_out => retimed_pulse,
ovf_error => de_queue_error);
init_de <= not enable;
end generate gPULSE_DELAY_EQUAL;
gNOT_PULSE_DELAY_EQUAL: if pulse_delay_equal_en = false generate
retimed_pulse <= gated_pulse;
end generate gNOT_PULSE_DELAY_EQUAL;
p_delay_equal_switch : process(clk)
begin
if(clk = '1' and clk'event) then
if(bypass_delay_equal = '1') then
pulse_out_i <= gated_pulse;
else
pulse_out_i <= retimed_pulse;
end if;
end if;
end process p_delay_equal_switch;
-----------------------------------------------------------------------------
-- Output pulse Overdrive check
-----------------------------------------------------------------------------
loc_pulse <= enable and (pulse_out_i and not loc_pulse_out_d);
pODRV_CHK : process(clk)
begin
if(clk = '1' and clk'event) then
loc_pulse_out_d <= pulse_out_i;
if(enable = '0' or overdrive_rst = '1' or unsigned(pulse_interval) = 2**16-1) then
first_pulse <= '1';
elsif(loc_pulse = '1') then
first_pulse <= '0';
end if;
if(loc_pulse = '1') then
pulse_interval <= (others => '0');
else
pulse_interval <= std_logic_vector(unsigned(pulse_interval)+1);
end if;
if(loc_pulse = '1' and first_pulse = '0' and unsigned(pulse_interval) < unsigned(overdrive_thres)) then
overdrv_event <= '1';
else
overdrv_event <= '0';
end if;
if(enable = '0' or overdrive_rst = '1') then
overdrive_events <= (others => '0');
elsif(overdrv_event = '1') then
overdrive_events <= std_logic_vector(unsigned(overdrive_events)+1);
end if;
end if;
end process pODRV_CHK;
-----------------------------------------------------------------------------
-- Pulse Width Conditioning
-----------------------------------------------------------------------------
gOUT_COND: if out_pulse_condition = true generate
iPC: entity work.pulse_conditioning_1
port map (
reset_n => reset_n,
clk => clk,
enable => enable,
pulse_in => pulse_out_i,
pd_in => loc_pd,
pulse_width => pulse_width,
pulse_width_ext => pulse_width_ext,
pulse_out => pulse_out_ii);
pulse_out <= pulse_out_ii;
fire_req <= pulse_out_ii;
end generate gOUT_COND;
gOUT_BYPASS : if out_pulse_condition = false generate
pulse_out <= pulse_out_i;
fire_req <= pulse_out_ii;
end generate gOUT_BYPASS;
-----------------------------------------------------------------------------
-- Local Diagnostic registers
-----------------------------------------------------------------------------
pEdgeDetect_Cnt : process(clk)
begin
if(clk = '1' and clk'event) then
fire_req_d <= fire_req;
if(init = '1' or enable = '0' or rst_diag_regs = '1') then
pd_in_cnt <= (others => '0');
elsif(pd_pulse = '1') then
pd_in_cnt <= std_logic_vector(unsigned(pd_in_cnt)+1);
end if;
if(init = '1' or enable = '0' or rst_diag_regs = '1') then
fire_req_cnt <= (others => '0');
elsif(fire_req_p = '1') then
fire_req_cnt <= std_logic_vector(unsigned(fire_req_cnt)+1);
end if;
end if;
end process pEdgeDetect_Cnt;
fire_req_p <= fire_req and not fire_req_d;
-----------------------------------------------------------------------------
-- C&S registers (Avalon-MM I/F)
-----------------------------------------------------------------------------
-- Memory partitioning:
-- Relative addresses between 0 and 511 => C&S regs
-- Relative addresses between 512 and 1023 => Sequencer RAM
avs_write_i <= '1' when avs_write = '1' and avs_address(9) = '0' else '0';
ch_ctrl_write <= '1' when avs_write = '1' and avs_address(9) = '1' else '0';
ch_ctrl_csr_write <= '1' when avs_write = '1' and avs_address(9 downto 5) = "00001" else '0';
avs_read_i <= '1' when avs_read = '1' and avs_address(9) = '0' else '0';
ch_ctrl_read <= '1' when avs_read = '1' and avs_address(9) = '1' else '0';
ch_ctrl_csr_read <= '1' when avs_read = '1' and avs_address(9 downto 5) = "00001" else '0';
avs_addr <= avs_address(4 downto 0);
ch_ctrl_address <= avs_address(ch_ctrl_address'range);
ch_ctrl_csr_addr <= avs_address(ch_ctrl_csr_addr'range);
ch_ctrl_writedata <= avs_writedata;
ch_ctrl_csr_writedata <= avs_writedata;
pINIT : process(clk)
begin
if(clk = '1' and clk'event) then
if(init = '1') then
init_v <= (others => '1');
else
init_v <= '0' & init_v(init_v'high downto 1);
end if;
end if;
end process pINIT;
enable <= enable_i and not init_v(4);
pCTRL_STATUS : process(reset_n, clk)
begin
if(reset_n = '0') then
avs_read_d <= '0';
avs_readdatavalid <= '0';
avs_readdata_i <= (others => '0');
--
enable_i <= '0';
bypass_ch_ctrl <= '0';
bypass_delay_equal <= '0';
sw_ctrl_dp_dir <= '0';
enable_out <= '0';
abort_fire <= '0';
--
ch_offset_dir0 <= (others => '0');
ch_offset_dir1 <= (others => '0');
ch_delay <= (others => '0');
--
ch_ctrl_start_req_ii <= '0';
ch_ctrl_start_addr <= (others => '0');
--
frac_div_en_i <= '0';
upd_max_pos_i <= '0';
upd_min_pos_i <= '0';
--
pulse_width <= std_logic_vector(to_unsigned(20,8)); -- 200 ns at clk=100MHz
pulse_width_ext <= std_logic_vector(to_unsigned(50,8)); -- 500 ns at clk=100MHz
--
overdrive_rst <= '0';
overdrive_thres <= std_logic_vector(to_unsigned(100-1,16));
--
div_offset <= (others => '0');
div_ratio <= (others => '0');
elsif(clk = '1' and clk'event) then
-- CTRL registers
if(avs_write_i = '1' and avs_address(9 downto 4) = "000000") then
case avs_addr is
when PULSE_GEN_CTRL_REG =>
enable_i <= avs_writedata(0);
bypass_ch_ctrl <= avs_writedata(1);
bypass_delay_equal <= avs_writedata(3);
sw_ctrl_dp_dir <= avs_writedata(4);
enable_out <= avs_writedata(16);
abort_fire <= avs_writedata(17);
rst_diag_regs <= avs_writedata(18);
when CH_OFFSET_D0_REG =>
ch_offset_dir0 <= avs_writedata;
when CH_DELAY_REG =>
ch_delay <= avs_writedata;
when CH_CTRL_CTRL_REG =>
ch_ctrl_start_req_ii <= avs_writedata(0);
ch_ctrl_start_addr <= avs_writedata(15 downto 8);
when FRAC_DIV_CTRL_REG =>
frac_div_en_i <= avs_writedata(0);
upd_max_pos_i <= avs_writedata(1);
upd_min_pos_i <= avs_writedata(2);
when PULSE_WIDTH_REG =>
pulse_width <= avs_writedata( 7 downto 0);
pulse_width_ext <= avs_writedata(23 downto 16);
when OVERDRV_THRES_REG =>
overdrive_rst <= avs_writedata(0);
overdrive_thres <= avs_writedata(31 downto 16);
when CH_OFFSET_D1_REG =>
ch_offset_dir1 <= avs_writedata;
when DIV_RATIO_INT =>
div_ratio(33 downto 24) <= avs_writedata( 9 downto 0);
when DIV_RATIO_FRAC =>
div_ratio(23 downto 0) <= avs_writedata(23 downto 0);
when SP_OFFSET_INT =>
div_offset(33 downto 24) <= avs_writedata( 9 downto 0);
when SP_OFFSET_FRAC =>
div_offset(23 downto 0) <= avs_writedata(23 downto 0);
when others => null;
end case;
end if;
-- Read Ctrl & Status registers
avs_read_d <= avs_read;
avs_readdatavalid <= avs_read_d;
if(avs_read_i = '1') then
case avs_addr is
when CSR_IP_ID_ADDR =>
avs_readdata_i <= CSR_IP_ID;
when CSR_IP_VER_ADDR =>
avs_readdata_i <= CSR_IP_VER;
when PULSE_GEN_CTRL_REG =>
avs_readdata_i(31 downto 8) <= (8 => ch_mask_i, 9 => fire_enable, 10 => dp_dir, 16 => enable_out, 17 => abort_fire, 18 => rst_diag_regs, others => '0');
avs_readdata_i( 7 downto 4) <= b"0" & de_queue_error & pd_queue_error & sw_ctrl_dp_dir;
avs_readdata_i( 3 downto 0) <= bypass_delay_equal & '0' & bypass_ch_ctrl & enable_i;
when CH_OFFSET_D0_REG =>
avs_readdata_i <= ch_offset_dir0;
when CH_OFFSET_D1_REG =>
avs_readdata_i <= ch_offset_dir1;
when CH_DELAY_REG =>
avs_readdata_i <= ch_delay;
when CH_CTRL_CTRL_REG =>
avs_readdata_i <= X"0000" & ch_ctrl_start_addr & X"0" & "00" & ch_ctrl_busy & ch_ctrl_start_req_ii;
when FRAC_DIV_CTRL_REG =>
avs_readdata_i <= (0 => frac_div_en_i, 1 => upd_max_pos_i, 2 => upd_min_pos_i, others => '0');
when PULSE_WIDTH_REG =>
avs_readdata_i <= X"00" & pulse_width_ext & X"00" & pulse_width;
when OVERDRV_THRES_REG =>
avs_readdata_i(15 downto 0) <= (0 => overdrive_rst, others => '0');
avs_readdata_i(31 downto 16) <= overdrive_thres;
when OVERDRV_EVENT_REG =>
avs_readdata_i <= X"0000" & overdrive_events;
when DIV_RATIO_INT =>
avs_readdata_i <= X"00000" & b"00" & div_ratio(33 downto 24);
when DIV_RATIO_FRAC =>
avs_readdata_i <= X"00" & div_ratio(23 downto 0);
when SP_OFFSET_INT =>
avs_readdata_i <= X"00000" & b"00" & div_offset(33 downto 24);
when SP_OFFSET_FRAC =>
avs_readdata_i <= X"00" & div_offset(23 downto 0);
when POS_MAX_REG =>
avs_readdata_i <= abs_pos_max;
when POS_MIN_REG =>
avs_readdata_i <= abs_pos_min;
when ABS_POS_STAT =>
avs_readdata_i <= abs_position;
when PD_IN_CNT_REG =>
avs_readdata_i <= pd_in_cnt;
when FIRE_REQ_CNT_REG =>
avs_readdata_i <= fire_req_cnt;
when others =>
avs_readdata_i <= X"BAD1BAD0";
end case;
else
avs_readdata_i <= X"BAD1BAD0";
end if;
if(avs_read = '1') then
avs_address_i <= avs_address;
end if;
-- output multiplexer
case? avs_address_i( 9 downto 5) is
when "00000" =>
avs_readdata <= avs_readdata_i;
when "00001" =>
avs_readdata <= ch_ctrl_csr_readdata;
when "1----" =>
avs_readdata <= ch_ctrl_readdata;
when others =>
avs_readdata <= X"BAD1BAD0";
end case?;
end if;
end process pCTRL_STATUS;
end architecture rtl;

View file

@ -0,0 +1,47 @@
-------------------------------------------------------------------------------
-- Title : pulse_generator_1_pkg
-- Project : SMB/Encoder Simulation board
-------------------------------------------------------------------------------
-- File : pulse_generator_1_pkg.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2018-08-22
-- Last update: 2018-08-23
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Package defining common constants for the pulse generator
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package pulse_generator_1_pkg is
constant CSR_IP_ID_ADDR : std_logic_vector( 4 downto 0) := 5x"00";
constant CSR_IP_VER_ADDR : std_logic_vector( 4 downto 0) := 5x"01";
constant PULSE_GEN_CTRL_REG : std_logic_vector( 4 downto 0) := 5x"02";
constant CH_OFFSET_D0_REG : std_logic_vector( 4 downto 0) := 5x"03";
constant CH_OFFSET_D1_REG : std_logic_vector( 4 downto 0) := 5x"04";
constant CH_DELAY_REG : std_logic_vector( 4 downto 0) := 5x"05";
constant CH_CTRL_CTRL_REG : std_logic_vector( 4 downto 0) := 5x"06";
constant FRAC_DIV_CTRL_REG : std_logic_vector( 4 downto 0) := 5x"07";
constant PULSE_WIDTH_REG : std_logic_vector( 4 downto 0) := 5x"08";
constant OVERDRV_THRES_REG : std_logic_vector( 4 downto 0) := 5x"09";
constant OVERDRV_EVENT_REG : std_logic_vector( 4 downto 0) := 5x"0A";
constant DIV_RATIO_INT : std_logic_vector( 4 downto 0) := 5x"0B";
constant DIV_RATIO_FRAC : std_logic_vector( 4 downto 0) := 5x"0C";
constant SP_OFFSET_INT : std_logic_vector( 4 downto 0) := 5x"0D";
constant SP_OFFSET_FRAC : std_logic_vector( 4 downto 0) := 5x"0E";
constant POS_MAX_REG : std_logic_vector( 4 downto 0) := 5x"0F";
constant POS_MIN_REG : std_logic_vector( 4 downto 0) := 5x"10";
constant ABS_POS_STAT : std_logic_vector( 4 downto 0) := 5x"11";
constant PD_IN_CNT_REG : std_logic_vector( 4 downto 0) := 5x"12";
constant FIRE_REQ_CNT_REG : std_logic_vector( 4 downto 0) := 5x"13";
constant SEQ_CSR_OFFSET : std_logic_vector(9 downto 0) := 10x"20";
constant SEQ_RAM_OFFSET : std_logic_vector(9 downto 0) := 10x"200";
end package pulse_generator_1_pkg;

View file

@ -0,0 +1,251 @@
-------------------------------------------------------------------------------
-- Title : queue_and_delay_1
-- Project : project independent
-------------------------------------------------------------------------------
-- File : queue_and_delay_1.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2016-05-28
-- Last update: 2018-06-28
-- SVN ID : Git
-- Standard : VHDL'93
-------------------------------------------------------------------------------
-- Description:
-- Generic component implementing a queue and delay functionality: Apply a
-- static programmable delay to the input signal. Since the block is FIFO based
-- (2048 words), the user must make sure that the number of transitions on the
-- input signal happening within the programmed delay is lower than the size of the FIFO.
-- E.g.: if the user program a delay of 2 ms, the input signal must have less
-- than 1024 pulses in 2 ms => max pulse rate = 512kHz. The block rises the
-- error bit when this condition is violated.
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.common_pkg.all;
entity queue_and_delay_1 is
generic(
use_ext_time : boolean := false;
queue_size : natural range 16 to 8192 := 1024);
port (
rstN : in std_logic;
clk : in std_logic;
init : in std_logic;
cnt_dir : in std_logic; -- specify the direction of the cnt (0 => up, 1
-- => down), when use_ext_time is set to ture
delay : in std_logic_vector(31 downto 0);
ext_time : in std_logic_vector(31 downto 0);
wave_in : in std_logic;
wave_out : out std_logic;
ovf_error : out std_logic);
end queue_and_delay_1;
architecture RTL of queue_and_delay_1 is
component sync_fifo_1
generic (
FIFO_WIDTH : natural range 1 to 32;
FIFO_DEPTH : natural range 1 to 8192);
port (
clock : in std_logic;
data : in std_logic_vector (FIFO_WIDTH-1 downto 0);
rdreq : in std_logic;
sclr : in std_logic;
wrreq : in std_logic;
empty : out std_logic;
full : out std_logic;
q : out std_logic_vector (FIFO_WIDTH-1 downto 0);
usedw : out std_logic_vector (log2(FIFO_DEPTH)-1 downto 0));
end component;
signal toggle_in, toggle_out,time_elapsed : std_logic;
signal wave_in_d, wave_out_i, pending_trans : std_logic;
signal fifo_rd_en, fifo_empty, fifo_full : std_logic;
signal cnt_dir_i, wave_out_i_d, new_event : std_logic;
signal wave_out_ii, shf_enable : std_logic;
signal delay_line : std_logic_vector( 7 downto 0);
signal local_time, local_time_d, event_time : std_logic_vector(31 downto 0);
begin -- RTL
-----------------------------------------------------------------------------
-- Detect transitions in the input signal and memorize those events in a
-- FIFO, together with a timetag. This process can be seen as a representation
-- of the input signal in a compressed format.
-----------------------------------------------------------------------------
toggle_in <= '1' when wave_in /= wave_in_d else '0';
pInputEdgeDetect : process(clk)
begin
if(clk = '1' and clk'event) then
wave_in_d <= wave_in;
end if;
end process pInputEdgeDetect;
iENTRY_QUEUE: sync_fifo_1
generic map(
FIFO_WIDTH => 32,
FIFO_DEPTH => queue_size)
port map (
clock => clk,
data => local_time,
rdreq => fifo_rd_en,
sclr => init,
wrreq => toggle_in,
empty => fifo_empty,
full => fifo_full,
q => event_time,
usedw => open);
-- Check Overflow error:
pCHECK_OVF : process(rstN, clk)
begin
if(rstN = '0') then
ovf_error <= '0';
elsif(clk = '1' and clk'event) then
if(init = '1') then
ovf_error <= '0';
elsif(toggle_in = '1' and fifo_full = '1') then
ovf_error <= '1';
end if;
end if;
end process pCHECK_OVF;
-- Time reference: either use the external one or generate it locally
gTIME_REF0: if use_ext_time = true generate
local_time <= ext_time;
shf_enable <= '1' when local_time /= local_time_d else '0';
--pTimeElapsed : process(cnt_dir, local_time, event_time, delay)
pTimeElapsed : process(clk)
begin
if(clk = '1' and clk'event) then
local_time_d <= local_time;
cnt_dir_i <= cnt_dir;
if(cnt_dir_i = '0') then
if(signed(local_time) >= signed(event_time) + signed(delay)) then
time_elapsed <= '1';
else
time_elapsed <= '0';
end if;
else
if(signed(local_time) <= signed(event_time) - signed(delay)) then
time_elapsed <= '1';
else
time_elapsed <= '0';
end if;
end if;
new_event <= fifo_rd_en;
end if;
end process pTimeElapsed;
end generate gTIME_REF0;
gTIME_REF1: if use_ext_time = false generate
pGEN_LOC_REF : process(rstN, clk)
begin
if(rstN = '0') then
local_time <= (others => '0');
elsif(clk = '1' and clk'event) then
if(init = '1') then
local_time <= (others => '0');
else
local_time <= std_logic_vector(unsigned(local_time)+1);
end if;
end if;
end process pGEN_LOC_REF;
new_event <= fifo_rd_en;
time_elapsed <= '1' when unsigned(local_time) >= unsigned(event_time) + unsigned(delay) else '0';
shf_enable <= '1';
end generate gTIME_REF1;
-----------------------------------------------------------------------------
-- Delay the input signal
-----------------------------------------------------------------------------
-- Read the signal transitions recorded in the FIFO, apply the static delay
pDELAY_WAVE_GEN : process(clk)
begin
if(clk = '1' and clk'event) then
if(init = '1' or (time_elapsed = '1' and new_event = '0')) then
pending_trans <= '0';
elsif(new_event = '1') then
pending_trans <= '1';
end if;
if(pending_trans = '0' and fifo_empty = '0' and fifo_rd_en = '0' and new_event = '0') then
fifo_rd_en <= '1';
else
fifo_rd_en <= '0';
end if;
end if;
end process pDELAY_WAVE_GEN;
pGEN_OUT : process(rstN, clk)
begin
if(rstN = '0') then
wave_out_i <= '0';
elsif(clk = '1' and clk'event) then
if(init = '1') then
wave_out_i <= wave_in_d;
elsif(toggle_out = '1') then
wave_out_i <= not wave_out_i;
end if;
end if;
end process pGEN_OUT;
-- Because of the intrinsic latency with the FIFO, a shift register is used
-- to achieve small delays (< 8).
pDELAY_THROUGH_SHF : process(clk)
begin
if(clk = '1' and clk'event) then
if(shf_enable = '1') then
delay_line <= delay_line(6 downto 0) & wave_in;
end if;
end if;
end process pDELAY_THROUGH_SHF;
toggle_out <= time_elapsed and pending_trans;
-- When using the external counter, the input signal might have multiple rising and
-- falling events whitout a change a value in the counter. When this happens,
-- the pulse width is not properly replicated in the output of the delay
-- block. To make the behaviour more predictable, when using the external
-- counter, a positive edge detector is inserted at the output.
gOUT_GEN0: if use_ext_time = false generate
wave_out_ii <= wave_out_i when unsigned(delay) >= 8 else delay_line(to_integer(unsigned(delay(2 downto 0))));
pOUT_GEN0: process(clk)
begin
if(clk = '1' and clk'event) then
wave_out <= wave_out_ii;
end if;
end process pOUT_GEN0;
end generate gOUT_GEN0;
gOUT_GEN1: if use_ext_time = true generate
pOUT_GEN1: process(clk)
begin
if(clk = '1' and clk'event) then
wave_out_i_d <= wave_out_i;
wave_out <= wave_out_i and not wave_out_i_d;
end if;
end process pOUT_GEN1;
end generate gOUT_GEN1;
end RTL;

View file

@ -0,0 +1,155 @@
-------------------------------------------------------------------------------
-- Title : simple_frac_div_1
-- Project : EMB-1
-------------------------------------------------------------------------------
-- File : simple_frac_div_1.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2017-12-04
-- Last update: 2018-08-21
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Simple Fractional Divider: this version of the fractional divider identifies
-- the optimal encoder position to generate a fire-pulse, but it does not
-- identy the optimal fire time. Therefore the resulting resolution is equal to
-- +/-1/2 encoder pulse.
-- The identification of the optimal absolute position for the fire request
-- employs an iterative algorithm which checks, for every increment of the
-- absolute position, in the intended direction, whether the position error at
-- the current position is lower than the error at the next position. If the
-- result of the check is positive, the fire request will be issued at the
-- current absolute position, otherwise the check is repeated at the next step.
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity simple_frac_div_1 is
port(
clk : in std_logic;
enable : in std_logic;
upd_max_pos : in std_logic;
upd_min_pos : in std_logic;
abs_pos_max : out std_logic_vector(31 downto 0);
abs_pos_min : out std_logic_vector(31 downto 0);
dir : in std_logic;
offset : in std_logic_vector(33 downto 0);
ratio : in std_logic_vector(33 downto 0);
abs_pos : in std_logic_vector(31 downto 0);
enc_pulse : out std_logic;
fire : out std_logic;
fire_cnt : out std_logic_vector(31 downto 0));
end entity simple_frac_div_1;
architecture rtl of simple_frac_div_1 is
signal enable_d, start : std_logic;
signal update, fire_gen : std_logic;
signal inc_pos, dec_pos : std_logic;
signal new_max, new_min : std_logic;
signal delta_wrap, start_d : std_logic;
--
signal zeros, delta_pos : std_logic_vector(15 downto 0);
signal fire_cnt_i : std_logic_vector(31 downto 0);
signal pos_diff : std_logic_vector(31 downto 0);
signal pos_max, pos_min : std_logic_vector(31 downto 0);
signal dist_pos, dist_neg : std_logic_vector(31 downto 0);
signal abs_pos_d : std_logic_vector(31 downto 0);
signal delta_pos_ext : std_logic_vector(39 downto 0);
signal ideal_fire : std_logic_vector(49 downto 0);
signal firing_error : std_logic_vector(49 downto 0);
begin
zeros <= (others => '0');
-----------------------------------------------------------------------------
-- Min/Max Absolute Position Tracking (and jitter rejection)
-----------------------------------------------------------------------------
pPOS_TRACK : process(clk)
begin
if(clk = '1' and clk'event) then
abs_pos_d <= abs_pos;
if(new_max = '1' or upd_max_pos = '1') then
pos_max <= abs_pos;
end if;
if(new_min = '1' or upd_min_pos = '1') then
pos_min <= abs_pos;
end if;
-- enc_pulse output replaces the enc_out from the EMS, because the EMS
-- does not support encoder jitter tracking anymore.
-- Note: because of the absolute position, enc_pulse is redundant and
-- used only for diagnostic purpose.
enc_pulse <= (new_max and not dir) or (new_min and dir);
end if;
end process pPOS_TRACK;
pos_diff <= std_logic_vector(signed(abs_pos) - signed(abs_pos_d));
dist_pos <= std_logic_vector(signed(abs_pos)-signed(pos_max));
dist_neg <= std_logic_vector(signed(pos_min)-signed(abs_pos));
inc_pos <= '1' when pos_diff(31) = '0' and pos_diff(2 downto 0) = "001" else '0';
dec_pos <= '1' when pos_diff(31) = '1' and pos_diff(2 downto 0) = "111" else '0';
new_max <= '1' when inc_pos = '1' and dir = '0' and dist_pos(31) = '0' and unsigned(dist_pos(3 downto 0)) /= 0 else '0';
new_min <= '1' when dec_pos = '1' and dir = '1' and dist_neg(31) = '0' and unsigned(dist_neg(3 downto 0)) /= 0 else '0';
abs_pos_min <= pos_min;
abs_pos_max <= pos_max;
-----------------------------------------------------------------------------
-- Fractional Divider Logic
-----------------------------------------------------------------------------
pFD_REGs : process(clk)
begin
if(clk = '1' and clk'event) then
enable_d <= enable;
start_d <= start;
if(enable = '0') then
delta_pos <= (others => '0');
elsif(delta_wrap = '1') then
-- Decrement delta_pos of 64
delta_pos <= (6 => '1', others => '0');
elsif(new_min = '1' or new_max = '1') then
delta_pos <= std_logic_vector(unsigned(delta_pos)+1);
end if;
if(unsigned(delta_pos) = 127 and update = '1') then
delta_wrap <= '1';
else
delta_wrap <= '0';
end if;
-- ideal_fire: represents the ideal fire position (normalized 2**RATIO_FRACT_W)
if(start = '1') then
ideal_fire <= zeros & offset;
elsif(fire_gen = '1') then
ideal_fire <= std_logic_vector(unsigned(ideal_fire)+unsigned(ratio));
elsif(delta_wrap = '1') then
-- Decrement delta_pos of 64 (normalized 2**RATIO_FRACT_W)
ideal_fire <= std_logic_vector(unsigned(ideal_fire)- X"3F000000");
end if;
firing_error <= std_logic_vector(unsigned(ideal_fire) - unsigned(delta_pos_ext));
update <= enable and (start_d or new_min or new_max);
fire <= fire_gen;
if(enable = '0') then
fire_cnt_i <= (others => '0');
elsif(fire_gen = '1') then
fire_cnt_i <= std_logic_vector(unsigned(fire_cnt_i)+1);
end if;
end if;
end process pFD_REGs;
fire_gen <= '1' when update = '1' and unsigned(firing_error(firing_error'left downto 24)) = 0 else '0';
start <= enable and not enable_d;
--
delta_pos_ext <= delta_pos & X"000000";
fire_cnt <= fire_cnt_i;
end architecture rtl;

View file

@ -463,7 +463,7 @@ begin
irq_status_next <= irq_status or irq_status_cpu or (irq_mask and log_trigger_vec);
iLOG_FIFO: entity work.sync_fifo
iLOG_FIFO: entity work.sync_fifo_1
generic map (
FIFO_WIDTH => 32,
FIFO_DEPTH => 256)