From 368cb565eae3a4299a46f15634114ef1fb84ac4b Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 20 Sep 2022 16:41:57 +0100 Subject: [PATCH] CORE-798 Make EL GIP Library FPGA Vendor Independent. enc_pd_emul_3 V3 - FPGA Vendor Independent. Uses Generic Sequencer 19 (also FPGA Vendor Independent) --- .../enc_pd_emul/3/doc/enc_pd_emul_3.json | 439 +++++++++++++++ .../enc_pd_emul/3/sim/sim_enc_pd_emul_3.do | 63 +++ .../enc_pd_emul/3/sim/wave_enc_pd_emul_3.do | 153 +++++ .../enc_pd_emul/3/src/enc_pd_emul_3.vhd | 474 ++++++++++++++++ .../3/src/test/enc_pd_emul_2_tb.vhd | 527 ++++++++++++++++++ generic_ip/enc_pd_emul/versions.txt | 1 + 6 files changed, 1657 insertions(+) create mode 100644 generic_ip/enc_pd_emul/3/doc/enc_pd_emul_3.json create mode 100644 generic_ip/enc_pd_emul/3/sim/sim_enc_pd_emul_3.do create mode 100644 generic_ip/enc_pd_emul/3/sim/wave_enc_pd_emul_3.do create mode 100644 generic_ip/enc_pd_emul/3/src/enc_pd_emul_3.vhd create mode 100644 generic_ip/enc_pd_emul/3/src/test/enc_pd_emul_2_tb.vhd create mode 100644 generic_ip/enc_pd_emul/versions.txt diff --git a/generic_ip/enc_pd_emul/3/doc/enc_pd_emul_3.json b/generic_ip/enc_pd_emul/3/doc/enc_pd_emul_3.json new file mode 100644 index 0000000..76eca63 --- /dev/null +++ b/generic_ip/enc_pd_emul/3/doc/enc_pd_emul_3.json @@ -0,0 +1,439 @@ +[{ + "ip_name": "enc_pd_emul_3", + "bus": "csr", + "addr_width" : "5", + "description": "Encoder/PD emulator", + "addr_hi_bit" : "6", + "addr_lo_bit" : "5", + "sub_blocks": { + "local": { + "instance": "", + "process": "cpp, txt", + "offset": "0x0" + }, + "generic_sequencer_19": { + "instance": "", + "process": "enabled", + "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" : "0x00", + "description" : "Minor number" + }, + "major_number" : { + "type" : "c", + "bit_len" : "8", + "reset" : "0x03", + "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_w": { + "address": "4", + "width": "6", + "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 " + } + } + }, + "enc_ctrl_r": { + "address": "5", + "width": "32", + "description": "Status", + "fields": { + "reserved0": { + "type": "rsv", + "bit_len": "6", + "description": "Reserved" + }, + "max_pulses_done": { + "type": "r", + "bit_len": "1", + "reset": "0x0", + "description": "signals the completion of the encoder/absolute position increments" + }, + "reserved1": { + "type": "rsv", + "bit_len": "24", + "description": "Reserved" + }, + "seq_present": { + "type": "r", + "bit_len": "1", + "reset": "0x0", + "description": "Set to 1 when the Sequencer is instantiated, 0 otherwise" + } + } + }, + "enc_nco_inc": { + "type": "w", + "address": "6", + "reset": "0x0", + "width": "32", + "description": "Encoder NCO increment: values in range 0 to 2147483648. Enc period will be 10ns * (2^32)/enc_nco_inc - e.g. increment of d20000 gives period ~2.15ms. increment of x8000000 gives the min period of 20ns (too fast for usage)" + }, + "enc_pulse_num": { + "type": "w", + "address": "7", + "reset": "0x0", + "width": "32", + "description": "number of encoder/absolute position increments to be generated" + }, + "enc_zp_ppr": { + "type": "w", + "address": "8", + "reset": "0x0", + "width": "16", + "description": "Zero-Phase PPR (Pulse-Per-Revolution)" + }, + "pos_init_lsb": { + "type": "w", + "address": "9", + "reset": "0x0", + "width": "32", + "subtype": "signed", + "description": "Absolute Position Initial value, bits 31:0" + }, + "pos_init_msb": { + "type": "w", + "address": "10", + "reset": "0x0", + "width": "8", + "subtype": "signed", + "description": "Absolute Position Initial value, bits 39:32" + }, + "pos_stat_lsb": { + "type": "r", + "address": "11", + "reset": "0x0", + "width": "32", + "subtype": "signed", + "description": "Absolute Position value, bits 31:0" + }, + "pos_stat_msb": { + "type": "r", + "address": "12", + "reset": "0x0", + "width": "8", + "subtype": "signed", + "description": "Absolute Position value, bits 39:32" + }, + "pd_ctrl": { + "address": "13", + "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": "14", + "reset": "0x14", + "width": "16", + "description": "PD pulse-width [clock-cycles at 100 MHz]. The minimum value is 1." + }, + "pd_cnt": { + "type": "r", + "address": "15", + "reset": "0x0", + "width": "24", + "description": "PD pulse counter" + }, + "seq_ctrl": { + "address": "16", + "description": "sequencer control", + "width": "25", + "fields": { + "seq_start_req": { + "type": "w0", + "bit_len": "1", + "reset": "0x0", + "description": "sequencer start request" + }, + "seq_ext_trig": { + "type": "w0", + "bit_len": "1", + "reset": "0x0", + "description": "sequencer external trigger" + }, + "reserved" : { + "type" : "rsv", + "bit_len" : "14", + "description" : "Reserved bits" + }, + "seq_start_addr": { + "type": "w", + "bit_len": "9", + "reset": "0x0", + "description": "sequencer start address" + } + } + } + } +}, +{ + "ip_name" : "enc_pd_emul_3", + "bus" : "seq", + "addr_hi_bit" : "10", + "addr_lo_bit" : "9", + "description" : "Encoder/PD emulator sequencer ram", + "sub_blocks" : { + "generic_sequencer_19" : { + "instance" : "", + "process" : "cpp", + "offset" : "0x200" + } + } +} +] diff --git a/generic_ip/enc_pd_emul/3/sim/sim_enc_pd_emul_3.do b/generic_ip/enc_pd_emul/3/sim/sim_enc_pd_emul_3.do new file mode 100644 index 0000000..33873dc --- /dev/null +++ b/generic_ip/enc_pd_emul/3/sim/sim_enc_pd_emul_3.do @@ -0,0 +1,63 @@ +# Simulation macro + +#.main clear + +# Cleanup libraries +foreach lib [list work OSVVM] { + file delete -force -- $lib + vlib $lib +} + +set OSVVM_PATH ../../../common/0/src/test/OSVVM +set COMMON_PATH ../../../common/0/src +set SEQUENCER_PATH ../../../generic_sequencer/19/src + +set WORKLIB work + +vlib ./work +vmap work ./work + +# Compile the UUT +vcom -2008 -work $WORKLIB $COMMON_PATH/common_pkg.vhd +vcom -2008 -work $WORKLIB $SEQUENCER_PATH/generic_sequencer_19_cmd_pkg.vhd +vcom -2008 -work $WORKLIB $SEQUENCER_PATH/generic_sequencer_19_pkg_auto.vhd +vcom -2008 -work $WORKLIB $SEQUENCER_PATH/generic_sequencer_19_csr_regs_auto.vhd +vcom -2008 -work $WORKLIB $SEQUENCER_PATH/generic_sequencer_19.vhd +vcom -2008 -work $WORKLIB ./../src/enc_pd_emul_3_pkg_auto.vhd +vcom -2008 -work $WORKLIB ./../src/enc_pd_emul_3_csr_regs_auto.vhd +vcom -2008 -work $WORKLIB ./../src/enc_pd_emul_3.vhd + +# 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_3_tb.vhd + +vsim -t ps work.enc_pd_emul_3_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_3.do + +when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;} +run -all + +#run 100 us; diff --git a/generic_ip/enc_pd_emul/3/sim/wave_enc_pd_emul_3.do b/generic_ip/enc_pd_emul/3/sim/wave_enc_pd_emul_3.do new file mode 100644 index 0000000..ef12fcf --- /dev/null +++ b/generic_ip/enc_pd_emul/3/sim/wave_enc_pd_emul_3.do @@ -0,0 +1,153 @@ +onerror {resume} +quietly WaveActivateNextPane {} 0 +add wave -noupdate /enc_pd_emul_3_tb/reset_n +add wave -noupdate /enc_pd_emul_3_tb/clk +add wave -noupdate /enc_pd_emul_3_tb/ttl_pd +add wave -noupdate /enc_pd_emul_3_tb/ttl_enc_p1 +add wave -noupdate /enc_pd_emul_3_tb/ttl_enc_p2 +add wave -noupdate /enc_pd_emul_3_tb/ttl_enc_zp +add wave -noupdate /enc_pd_emul_3_tb/rs422_pd +add wave -noupdate /enc_pd_emul_3_tb/rs422_enc_p1 +add wave -noupdate /enc_pd_emul_3_tb/rs422_enc_p2 +add wave -noupdate /enc_pd_emul_3_tb/rs422_enc_zp +add wave -noupdate /enc_pd_emul_3_tb/avs_address +add wave -noupdate /enc_pd_emul_3_tb/avs_write +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/avs_writedata +add wave -noupdate /enc_pd_emul_3_tb/avs_read +add wave -noupdate /enc_pd_emul_3_tb/avs_readdatavalid +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/avs_readdata +add wave -noupdate /enc_pd_emul_3_tb/setup +add wave -noupdate /enc_pd_emul_3_tb/running +add wave -noupdate /enc_pd_emul_3_tb/passed +add wave -noupdate /enc_pd_emul_3_tb/failed +add wave -noupdate /enc_pd_emul_3_tb/test_timeout +add wave -noupdate /enc_pd_emul_3_tb/test_completed +add wave -noupdate /enc_pd_emul_3_tb/error_flag +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/avs_mm_s_rec +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/avs_mm_m_rec +add wave -noupdate -divider UUT +add wave -noupdate /enc_pd_emul_3_tb/iUUT/clk +add wave -noupdate /enc_pd_emul_3_tb/iUUT/reset_n +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_pd +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_p1 +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_p2 +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_zp +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_pd +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_p1 +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_p2 +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_zp +add wave -noupdate -radix decimal /enc_pd_emul_3_tb/iUUT/abs_pos_out +add wave -noupdate /enc_pd_emul_3_tb/iUUT/set_pos_out +add wave -noupdate /enc_pd_emul_3_tb/iUUT/inc_pos_out +add wave -noupdate /enc_pd_emul_3_tb/iUUT/dec_pos_out +add wave -noupdate /enc_pd_emul_3_tb/iUUT/avs_address +add wave -noupdate /enc_pd_emul_3_tb/iUUT/avs_write +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/avs_writedata +add wave -noupdate /enc_pd_emul_3_tb/iUUT/avs_read +add wave -noupdate /enc_pd_emul_3_tb/iUUT/avs_readdatavalid +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/avs_readdata +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_init +add wave -noupdate /enc_pd_emul_3_tb/iUUT/nco_inc_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_dir +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_p1 +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_p2 +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_p1_d +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_p2_d +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pulse_cnt_inc +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pulse_cnt_inc_d +add wave -noupdate /enc_pd_emul_3_tb/iUUT/max_pulses_start +add wave -noupdate /enc_pd_emul_3_tb/iUUT/max_pulses_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pulse_cnt_start +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pulse_cnt_stop +add wave -noupdate /enc_pd_emul_3_tb/iUUT/max_pulses_done +add wave -noupdate /enc_pd_emul_3_tb/iUUT/zero_phase +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pulse_cnt_running +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_pd_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_p1_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_p2_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_zp_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_pd_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_zp +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_p1_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_p2_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_zp_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/enc_emul_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_pd_fh +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_p1_fh +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_p2_fh +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ttl_enc_zp_fh +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_pd_fh +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_p1_fh +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_p2_fh +add wave -noupdate /enc_pd_emul_3_tb/iUUT/rs422_enc_zp_fh +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/zero_phase_ppr +add wave -noupdate /enc_pd_emul_3_tb/iUUT/inc_pos +add wave -noupdate /enc_pd_emul_3_tb/iUUT/dec_pos +add wave -noupdate /enc_pd_emul_3_tb/iUUT/set_abs_pos +add wave -noupdate -radix decimal /enc_pd_emul_3_tb/iUUT/abs_pos +add wave -noupdate -radix decimal /enc_pd_emul_3_tb/iUUT/abs_pos_init +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/zero_phase_cnt +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/enc_nco_1 +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/enc_nco_3 +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/nco_inc +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_pulses_start +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/seq_pulses +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/max_pulses +add wave -noupdate /enc_pd_emul_3_tb/iUUT/max_pulses_start_i +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/max_pulses_i +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/pulse_cnt +add wave -noupdate /enc_pd_emul_3_tb/iUUT/avs_write_i +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_ram_write +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_csr_write +add wave -noupdate /enc_pd_emul_3_tb/iUUT/avs_read_i +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_ram_read +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_csr_read +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_start_req +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_busy +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ext_trigger +add wave -noupdate /enc_pd_emul_3_tb/iUUT/us_pulse +add wave -noupdate /enc_pd_emul_3_tb/iUUT/ms_pulse +add wave -noupdate /enc_pd_emul_3_tb/iUUT/sec_pulse +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pd +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pd_d +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pd_pulse +add wave -noupdate /enc_pd_emul_3_tb/iUUT/clr_pd_cnt +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pd_gen +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pd_seq +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pd_emul_en +add wave -noupdate /enc_pd_emul_3_tb/iUUT/pd_i +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/pd_pulse_width +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/pd_pulse_cnt +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/pd_cnt +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_csr_addr +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_trigger_in +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/clk_cnt +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_ram_addr +add wave -noupdate /enc_pd_emul_3_tb/iUUT/seq_start_addr +add wave -noupdate /enc_pd_emul_3_tb/iUUT/avs_addr_i +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/us_cnt +add wave -noupdate -radix unsigned /enc_pd_emul_3_tb/iUUT/ms_cnt +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/seq_vec_out +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/avs_readdata_i +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/seq_ram_writedata +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/seq_csr_writedata +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_tb/iUUT/seq_ram_readdata +add wave -noupdate -radix hexadecimal /enc_pd_emul_3_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} diff --git a/generic_ip/enc_pd_emul/3/src/enc_pd_emul_3.vhd b/generic_ip/enc_pd_emul/3/src/enc_pd_emul_3.vhd new file mode 100644 index 0000000..b14d68b --- /dev/null +++ b/generic_ip/enc_pd_emul/3/src/enc_pd_emul_3.vhd @@ -0,0 +1,474 @@ +------------------------------------------------------------------------------- +-- Title : enc_pd_emul_3 +-- Project : SMB/Encoder Simulation board +------------------------------------------------------------------------------- +-- File : enc_pd_emul_3.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2018-05-30 +-- Last update: 2018-12-21 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Generate synthetic encoder and product detect signals +------------------------------------------------------------------------------- +-- altera vhdl_input_version vhdl_2008 + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library work; +use work.enc_pd_emul_3_pkg.all; + +entity enc_pd_emul_3 is + generic( + DEVICE_FAMILY : string := "Cyclone V"; -- "Cyclone 10 LP" + 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_readdata : out std_logic_vector(31 downto 0)); +end entity enc_pd_emul_3; + +architecture rtl of enc_pd_emul_3 is + + 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 : 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 ttl_pd_i, ttl_enc_p1_i, ttl_enc_p2_i : std_logic; + signal ttl_enc_zp_i, rs422_pd_i, rs422_enc_p1_i : std_logic; + signal rs422_enc_p2_i, rs422_enc_zp_i : 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 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_sequencer_19 + generic map ( + TRIGGER_WIDTH => 8, + VECTOR_WIDTH => 2, + RAMP_WIDTH => 1, + BUS_WIDTH => 32, + POS_WIDTH => 32, + SEQ_DEPTH => 512, + ADD_VEC_PIPE => false, + VECT_CPU_EN => false, + VECT_RAMP_EN => false, + BUS_BURST_EN => true, + POS_BUS_EN => true, + ALU_EN => true, + QUEUE_EN => false, + DEVICE_FAMILY => DEVICE_FAMILY) + 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(31 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_i <= ttl_pd_en and pd_pulse; + ttl_enc_p1_i <= ttl_enc_p1_en and enc_p1; + ttl_enc_p2_i <= ttl_enc_p2_en and enc_p2; + ttl_enc_zp_i <= ttl_enc_zp_en and enc_zp; + + ttl_pd <= ttl_pd_i; + ttl_enc_p1 <= ttl_enc_p1_i; + ttl_enc_p2 <= ttl_enc_p2_i; + ttl_enc_zp <= ttl_enc_zp_i; + + -- RS422 + rs422_pd_i <= rs422_pd_en and pd_pulse; + rs422_enc_p1_i <= rs422_enc_p1_en and enc_p1; + rs422_enc_p2_i <= rs422_enc_p2_en and enc_p2; + rs422_enc_zp_i <= rs422_enc_zp_en and enc_zp; + + rs422_pd <= rs422_pd_i; + rs422_enc_p1 <= rs422_enc_p1_i; + rs422_enc_p2 <= rs422_enc_p2_i; + rs422_enc_zp <= rs422_enc_zp_i; + + ----------------------------------------------------------------------------- + -- 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; + + enc_pd_emul_csr_regs_i : entity work.enc_pd_emul_3_csr_regs + generic map ( + ADDR_DECODE_WIDTH => 5 + ) + port map ( + -- Clock and reset + clk => clk, + rst_n => reset_n, + + -- auto-generated + + -- Internal signal ports + out_enable_ttl_pd_en => ttl_pd_en, + out_enable_ttl_ph1_en => ttl_enc_p1_en, + out_enable_ttl_ph2_en => ttl_enc_p2_en, + out_enable_ttl_zp_en => ttl_enc_zp_en, + out_enable_rs422_pd_en => rs422_pd_en, + out_enable_rs422_ph1_en => rs422_enc_p1_en, + out_enable_rs422_ph2_en => rs422_enc_p2_en, + out_enable_rs422_zp_en => rs422_enc_zp_en, + out_enable_ttl_pd_fh => ttl_pd_fh, + out_enable_ttl_ph1_fh => ttl_enc_p1_fh, + out_enable_ttl_ph2_fh => ttl_enc_p2_fh, + out_enable_ttl_zp_fh => ttl_enc_zp_fh, + out_enable_rs422_pd_fh => rs422_pd_fh, + out_enable_rs422_ph1_fh => rs422_enc_p1_fh, + out_enable_rs422_ph2_fh => rs422_enc_p2_fh, + out_enable_rs422_zp_fh => rs422_enc_zp_fh, + enc_ctrl_w_nco_en => enc_emul_en, + enc_ctrl_w_enc_dir => enc_dir, + enc_ctrl_w_max_pulses_en => max_pulses_en, + enc_nco_inc => nco_inc, + enc_pulse_num => max_pulses, + enc_zp_ppr => zero_phase_ppr, + pos_init_lsb => abs_pos_init(31 downto 0), + pos_init_msb => abs_pos_init(39 downto 32), + pd_ctrl_pd_en => pd_emul_en, + pd_pulse_width => pd_pulse_width, + seq_ctrl_seq_start_addr => seq_start_addr, + enc_ctrl_w_nco_init => enc_init, + enc_ctrl_w_set_abs_pos => set_abs_pos, + enc_ctrl_w_max_pulses_start => max_pulses_start, + pd_ctrl_pd_gen => pd_gen, + pd_ctrl_clr_pd_cnt => clr_pd_cnt, + seq_ctrl_seq_start_req => seq_start_req, + seq_ctrl_seq_ext_trig => ext_trigger, + out_status_ttl_pd => ttl_pd_i, + out_status_ttl_ph1 => ttl_enc_p1_i, + out_status_ttl_ph2 => ttl_enc_p2_i, + out_status_ttl_zp => ttl_enc_zp_i, + out_status_rs422_pd => rs422_pd_i, + out_status_rs422_ph1 => rs422_enc_p1_i, + out_status_rs422_ph2 => rs422_enc_p2_i, + out_status_rs422_zp => rs422_enc_zp_i, + enc_ctrl_r_max_pulses_done => max_pulses_done, + enc_ctrl_r_seq_present => seq_present, + pos_stat_lsb => abs_pos(31 downto 0), + pos_stat_msb => abs_pos(39 downto 32), + pd_cnt => pd_cnt, + + -- end auto-generated + + -- Slave bus port + avs_address => avs_address(4 downto 0), + avs_write => avs_write_i, + avs_writedata => avs_writedata, + avs_read => avs_read_i, + avs_readdata => avs_readdata_i + + ); + + + avs_readdata <= avs_readdata_i when avs_address(9 downto 5) = "00000" else + seq_csr_readdata when avs_address(9 downto 5) = "00001" else + seq_ram_readdata when avs_address(9 downto 5) = "1----" else + X"BAD1BAD0"; + +end architecture rtl; diff --git a/generic_ip/enc_pd_emul/3/src/test/enc_pd_emul_2_tb.vhd b/generic_ip/enc_pd_emul/3/src/test/enc_pd_emul_2_tb.vhd new file mode 100644 index 0000000..04be7e1 --- /dev/null +++ b/generic_ip/enc_pd_emul/3/src/test/enc_pd_emul_2_tb.vhd @@ -0,0 +1,527 @@ +------------------------------------------------------------------------------- +-- 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_2_pkg.all; + +entity enc_pd_emul_2_tb is + -- .. +end entity enc_pd_emul_2_tb; + +architecture behav of enc_pd_emul_2_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_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; + + constant SEQ_CSR_OFFSET : std_logic_vector(9 downto 0) := 10x"20"; + constant SEQ_RAM_OFFSET : std_logic_vector(9 downto 0) := 10x"200"; + + ----------------------------------------------------------------------------- + -- 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_2 + 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_readdata => avs_readdata); + + ----------------------------------------------------------------------------- + -- AVS Sequencer signal mapping + ----------------------------------------------------------------------------- + + avs_mm_s_rec.mm_readdata <= avs_readdata; + avs_mm_s_rec.mm_readdatavalid <= '0'; + avs_mm_s_rec.use_readvalid <= false; + + 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_R_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_W_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_W_ADDR, 32X"1"); + + wait for 50 us; + + -- Stop the encoder + csr_write(CSR_ENC_CTRL_W_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_W_ADDR, 32X"5"); + + wait for 50 us; + + -- Stop the encoder + csr_write(CSR_ENC_CTRL_W_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_ENC_PULSE_NUM_ADDR, 32X"64"); + csr_write(CSR_ENC_CTRL_W_ADDR, 32X"18"); + csr_write(CSR_ENC_CTRL_W_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_ENC_PULSE_NUM_ADDR, 32X"1"); + csr_write(CSR_ENC_CTRL_W_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_ENC_PULSE_NUM_ADDR, 32X"2"); + csr_write(CSR_ENC_CTRL_W_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_ENC_PULSE_NUM_ADDR, 32X"33"); + csr_write(CSR_ENC_CTRL_W_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_W_ADDR, 32X"08"); + log("Abs-Pos set to -100.", VMEDIUM); + + log("Running 101 steps in DIR-0 ...", VMEDIUM); + csr_write(CSR_ENC_PULSE_NUM_ADDR, 32X"65"); + csr_write(CSR_ENC_CTRL_W_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_ENC_PULSE_NUM_ADDR, 32X"0B"); + csr_write(CSR_ENC_CTRL_W_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_ENC_PULSE_NUM_ADDR, 32X"0A"); + csr_write(CSR_ENC_CTRL_W_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; diff --git a/generic_ip/enc_pd_emul/versions.txt b/generic_ip/enc_pd_emul/versions.txt new file mode 100644 index 0000000..195b5e7 --- /dev/null +++ b/generic_ip/enc_pd_emul/versions.txt @@ -0,0 +1 @@ +v3 - FPGA Vendor Independent. Uses Generic Sequencer 19 (also FPGA Vendor Independent) \ No newline at end of file