hdl: Updated testbench to use part models.
Added a VCTCXO model and a 16-bit DAC model for the bladeRF. The mm_driver.vhd has a more reasonable frequency adjust state. Simulations will need to be tweaked because they take way too long. Perhaps best to not use the device models because the changes are too small to see over a reasonable simulation time.
This commit is contained in:
parent
58efb99aba
commit
2112d4cd6c
5 changed files with 331 additions and 210 deletions
|
|
@ -12,16 +12,50 @@ vcom {*}$vcom_opts -work ${vcom_lib} ../vhdl/pps_counter.vhd
|
|||
vcom {*}$vcom_opts -work ${vcom_lib} ../vhdl/ppscal.vhd
|
||||
|
||||
# Testbench
|
||||
vcom {*}$vcom_opts -work ${vcom_lib} ../vhdl/tb/asvtx12a384m_model.vhd
|
||||
vcom {*}$vcom_opts -work ${vcom_lib} ../vhdl/tb/dac161s055_model.vhd
|
||||
vcom {*}$vcom_opts -work ${vcom_lib} ../vhdl/tb/mm_driver.vhd
|
||||
vcom {*}$vcom_opts -work ${vcom_lib} ../vhdl/tb/ppscal_tb.vhd
|
||||
|
||||
vcom {*}$vcom_opts -work ${vcom_lib} ../vhdl/tb/dacxo_tb.vhd
|
||||
|
||||
vsim ${vcom_lib}.ppscal_tb
|
||||
#vsim ${vcom_lib}.dacxo_tb
|
||||
|
||||
log -r *
|
||||
#log -r *
|
||||
|
||||
add wave -hex sim:/ppscal_tb/uut/*
|
||||
add wave -hex sim:/ppscal_tb/driver/*
|
||||
# Default radix
|
||||
radix -hexadecimal
|
||||
|
||||
run 500 us
|
||||
# Change radixes for a select few signals
|
||||
radix signal sim:/ppscal_tb/uut/pps_1s.count decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_1s.target decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_1s.count_mm_hold decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_10s.count decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_10s.target decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_10s.count_mm_hold decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_100s.count decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_100s.target decimal
|
||||
radix signal sim:/ppscal_tb/uut/pps_100s.count_mm_hold decimal
|
||||
|
||||
radix signal sim:/ppscal_tb/driver/current.pps_1s_count decimal
|
||||
radix signal sim:/ppscal_tb/driver/current.pps_10s_count decimal
|
||||
radix signal sim:/ppscal_tb/driver/current.pps_100s_count decimal
|
||||
|
||||
radix signal sim:/ppscal_tb/driver/current.holdoff_count decimal
|
||||
|
||||
# Add signals to waveform
|
||||
#add wave sim:/ppscal_tb/uut/*
|
||||
add wave sim:/ppscal_tb/uut/pps_1s*
|
||||
add wave sim:/ppscal_tb/uut/pps_10s*
|
||||
add wave sim:/ppscal_tb/uut/pps_100s*
|
||||
#add wave sim:/ppscal_tb/uut/int_req_proc/*
|
||||
add wave sim:/ppscal_tb/driver/*
|
||||
add wave sim:/ppscal_tb/dac/*
|
||||
add wave sim:/ppscal_tb/vctcxo/*
|
||||
add wave sim:/ppscal_tb/*
|
||||
|
||||
run 10 ms
|
||||
#run 500 ms
|
||||
|
||||
wave zoomfull
|
||||
|
|
|
|||
|
|
@ -28,25 +28,28 @@ library std;
|
|||
entity asvtx12a384m_model is
|
||||
port(
|
||||
vcon : in real; -- control voltage
|
||||
clock : out std_logic; -- output clock
|
||||
clock : out std_logic -- output clock
|
||||
);
|
||||
end entity;
|
||||
|
||||
architecture arch of asvtx12a384m_model is
|
||||
|
||||
constant FREQ_NOMINAL : real := 38.4e6;
|
||||
constant FREQ_STABILITY_MIN : real := (-2.0 / (1e6));
|
||||
constant FREQ_STABILITY_MAX : real := (+2.0 / (1e6));
|
||||
|
||||
-- Control Voltage Tolerances
|
||||
constant VCON_MIN : real := 0.4;
|
||||
constant VCON_MAX : real := 2.4;
|
||||
|
||||
-- Nominal output frequency
|
||||
constant FREQ_NOMINAL : real := 38.4e6;
|
||||
|
||||
-- Frequency stability tolerance
|
||||
constant PPM_STABILITY_MIN : real := -2.0;
|
||||
constant PPM_STABILITY_MAX : real := 2.0;
|
||||
|
||||
-- Frequency Tuning Tolerances
|
||||
constant PPM_VCON_MIN_MIN : real := (-5.0 / (1e6));
|
||||
constant PPM_VCON_MIN_MAX : real := (-9.5 / (1e6));
|
||||
constant PPM_VCON_MAX_MIN : real := (5.0 / (1e6));
|
||||
constant PPM_VCON_MAX_MAX : real := (9.5 / (1e6));
|
||||
constant PPM_VCON_MIN_MIN : real := -5.0;
|
||||
constant PPM_VCON_MIN_MAX : real := -9.5;
|
||||
constant PPM_VCON_MAX_MIN : real := 5.0;
|
||||
constant PPM_VCON_MAX_MAX : real := 9.5;
|
||||
|
||||
-- Given a frequency, compute the half period time
|
||||
function half_clk_per( freq : real ) return time is
|
||||
|
|
@ -61,19 +64,45 @@ architecture arch of asvtx12a384m_model is
|
|||
variable rand : real;
|
||||
begin
|
||||
uniform(seed1, seed2, rand);
|
||||
return (rand*ppm_max + ppm_min);
|
||||
return (rand*(ppm_max-ppm_min) + ppm_min);
|
||||
end function;
|
||||
|
||||
-- Given a Vcon voltage, calculate the minimum possible PPM error
|
||||
function vcon_ppm_min_calc( vcon : real ) return real is
|
||||
variable slope : real := 0.0;
|
||||
variable intercept : real := 0.0;
|
||||
variable rv : real := 0.0;
|
||||
begin
|
||||
return ( (5.0 * vcon) - 7.0 );
|
||||
slope := (PPM_VCON_MAX_MIN-PPM_VCON_MIN_MIN)/(VCON_MAX-VCON_MIN);
|
||||
intercept := PPM_VCON_MAX_MIN-(slope*VCON_MAX);
|
||||
if( (vcon >= VCON_MIN) and (vcon <= VCON_MAX) ) then
|
||||
rv := ( (slope * vcon) + intercept );
|
||||
else
|
||||
report "vcon_ppm_min_calc: vcon out of recommended range. Returning 0."
|
||||
severity warning;
|
||||
rv := 0.0;
|
||||
end if;
|
||||
|
||||
return rv;
|
||||
end function;
|
||||
|
||||
-- Given a Vcon voltage, calculate the maximum possible PPM error
|
||||
function vcon_ppm_max_calc( vcon : real ) return real is
|
||||
variable slope : real := 0.0;
|
||||
variable intercept : real := 0.0;
|
||||
variable rv : real := 0.0;
|
||||
begin
|
||||
return ( (9.5 * vcon) - 13.3 );
|
||||
slope := (PPM_VCON_MAX_MAX-PPM_VCON_MIN_MAX)/(VCON_MAX-VCON_MIN);
|
||||
intercept := PPM_VCON_MAX_MAX-(slope*VCON_MAX);
|
||||
if( (vcon >= VCON_MIN) and (vcon <= VCON_MAX) ) then
|
||||
rv := ( (slope * vcon) + intercept );
|
||||
else
|
||||
report "vcon_ppm_max_calc: vcon out of recommended range. Returning 0."
|
||||
severity warning;
|
||||
rv := 0.0;
|
||||
end if;
|
||||
|
||||
return rv;
|
||||
end function;
|
||||
|
||||
-- Given a Vcon PPM and a frequency stability PPM, compute the freuqency
|
||||
|
|
@ -81,143 +110,38 @@ architecture arch of asvtx12a384m_model is
|
|||
variable rv : real;
|
||||
begin
|
||||
-- Frequency with Vcon PPM error applied
|
||||
rv := ( (FREQ_NOMINAL) + (vcon_ppm/1.0e6)*FREQ_NOMINAL);
|
||||
rv := ( FREQ_NOMINAL * ( 1.0 + (vcon_ppm/1.0e6) ) );
|
||||
-- Apply frequency stability tolerance
|
||||
rv := ( (rv) + (tol_ppm/1.0e6)*rv);
|
||||
rv := ( rv * (1.0 + (tol_ppm/1.0e6)) );
|
||||
return rv;
|
||||
end function;
|
||||
|
||||
-- Current outputs
|
||||
signal freq : real;
|
||||
signal half_per : time;
|
||||
|
||||
|
||||
signal half_per : time := 13.021 ns;
|
||||
signal clock_i : std_logic := '1';
|
||||
|
||||
begin
|
||||
|
||||
|
||||
|
||||
|
||||
tcxo_clock_i <= not tcxo_clock_i after current.tcxo_half_per;
|
||||
tcxo_clock <= tcxo_clock_i;
|
||||
|
||||
sync_proc : process( mm_clock, mm_reset )
|
||||
begin
|
||||
if( mm_reset = '1' ) then
|
||||
current <= RESET_VALUE;
|
||||
elsif( rising_edge(mm_clock) ) then
|
||||
current <= future;
|
||||
end if;
|
||||
end process;
|
||||
-- i don't think the frequency is changing at all
|
||||
-- even though vcon is changing
|
||||
|
||||
comb_proc : process( all )
|
||||
variable tuning_ppm : real := 0.0;
|
||||
variable stability_ppm : real := 0.0;
|
||||
variable total_ppm : real := 0.0;
|
||||
begin
|
||||
mm_rd_req <= '0';
|
||||
mm_wr_req <= '0';
|
||||
mm_addr <= (others => '0');
|
||||
mm_wr_data <= (others => '0');
|
||||
stability_ppm := random_ppm(PPM_STABILITY_MIN, PPM_STABILITY_MAX);
|
||||
report "Setting stability error to: " & real'image(stability_ppm) & " PPM.";
|
||||
tuning_ppm := random_ppm(vcon_ppm_min_calc(vcon), vcon_ppm_max_calc(vcon));
|
||||
report "Setting tuning error to: " & real'image(tuning_ppm) & " PPM.";
|
||||
|
||||
case (current.state) is
|
||||
when RESET_COUNTERS =>
|
||||
mm_wr_req <= '1';
|
||||
mm_wr_data <= x"07";
|
||||
mm_addr <= std_logic_vector(to_unsigned(CONTROL_ADDR,mm_addr'length));
|
||||
future.holdoff_count <= 0;
|
||||
future.state <= START_COUNTERS;
|
||||
|
||||
when START_COUNTERS =>
|
||||
future.holdoff_count <= current.holdoff_count + 1;
|
||||
if( current.holdoff_count = RESET_TIME ) then
|
||||
future.holdoff_count <= 0;
|
||||
mm_wr_req <= '1';
|
||||
mm_wr_data <= x"00";
|
||||
mm_addr <= std_logic_vector(to_unsigned(CONTROL_ADDR,mm_addr'length));
|
||||
future.state <= HOLDOFF;
|
||||
end if;
|
||||
|
||||
when ENABLE_IRQS =>
|
||||
mm_wr_req <= '1';
|
||||
mm_wr_data <= x"01";
|
||||
mm_addr <= std_logic_vector(to_unsigned(INTERRUPT_ADDR,mm_addr'length));
|
||||
future.state <= WAIT_FOR_IRQ;
|
||||
|
||||
when WAIT_FOR_IRQ =>
|
||||
if( mm_irq = '1' ) then
|
||||
future.holdoff_count <= 0;
|
||||
mm_wr_req <= '1';
|
||||
mm_wr_data <= x"10"; -- clear and disable interrupts
|
||||
mm_addr <= std_logic_vector(to_unsigned(INTERRUPT_ADDR,mm_addr'length));
|
||||
--future.state <= READ_PPS_1S;
|
||||
future.state <= READ_COUNTS;
|
||||
else
|
||||
future.holdoff_count <= current.holdoff_count + 1;
|
||||
if( current.holdoff_count = IRQ_TIMEOUT ) then
|
||||
future.holdoff_count <= 0;
|
||||
future.state <= TERMINATE_SIMULATION;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
when READ_COUNTS =>
|
||||
future.holdoff_count <= current.holdoff_count + 1;
|
||||
mm_rd_req <= '1';
|
||||
if( current.holdoff_count < 8 ) then
|
||||
mm_addr <= std_logic_vector(to_unsigned(PPS_CNT_1S_ADDR+(current.holdoff_count mod 8),mm_addr'length));
|
||||
future.pps_1s_count <= mm_rd_data &
|
||||
current.pps_1s_count(current.pps_1s_count'left downto
|
||||
current.pps_1s_count'right+mm_rd_data'length);
|
||||
elsif( current.holdoff_count < 16 ) then
|
||||
-- Need to shift in the last byte of data from previous count
|
||||
if( current.holdoff_count = 8 ) then
|
||||
future.pps_1s_count <= mm_rd_data &
|
||||
current.pps_1s_count(current.pps_1s_count'left downto
|
||||
current.pps_1s_count'right+mm_rd_data'length);
|
||||
end if;
|
||||
-- Also start capturing the next counter value
|
||||
mm_addr <= std_logic_vector(to_unsigned(PPS_CNT_10S_ADDR+(current.holdoff_count mod 8),mm_addr'length));
|
||||
future.pps_10s_count <= mm_rd_data &
|
||||
current.pps_10s_count(current.pps_10s_count'left downto
|
||||
current.pps_10s_count'right+mm_rd_data'length);
|
||||
elsif( current.holdoff_count < 24 ) then
|
||||
-- Need to shift in the last byte of data from previous count
|
||||
if( current.holdoff_count = 16 ) then
|
||||
future.pps_10s_count <= mm_rd_data &
|
||||
current.pps_10s_count(current.pps_10s_count'left downto
|
||||
current.pps_10s_count'right+mm_rd_data'length);
|
||||
end if;
|
||||
-- Also start capturing the next counter value
|
||||
mm_addr <= std_logic_vector(to_unsigned(PPS_CNT_100S_ADDR+(current.holdoff_count mod 8),mm_addr'length));
|
||||
future.pps_100s_count <= mm_rd_data &
|
||||
current.pps_100s_count(current.pps_100s_count'left downto
|
||||
current.pps_100s_count'right+mm_rd_data'length);
|
||||
else
|
||||
-- Need to shift in the last byte of data from previous count
|
||||
if( current.holdoff_count = 24 ) then
|
||||
future.pps_100s_count <= mm_rd_data &
|
||||
current.pps_100s_count(current.pps_100s_count'left downto
|
||||
current.pps_100s_count'right+mm_rd_data'length);
|
||||
end if;
|
||||
mm_rd_req <= '0';
|
||||
future.holdoff_count <= 0;
|
||||
future.state <= FREQ_ADJUST;
|
||||
end if;
|
||||
|
||||
when FREQ_ADJUST =>
|
||||
future.tcxo_half_per <= half_clk_per(current.tcxo_freq+TCXO_INCR_FREQ);
|
||||
future.tcxo_freq <= current.tcxo_freq + TCXO_INCR_FREQ;
|
||||
future.state <= HOLDOFF;
|
||||
|
||||
when HOLDOFF =>
|
||||
future.holdoff_count <= current.holdoff_count + 1;
|
||||
if( current.holdoff_count = DEAD_TIME ) then
|
||||
future.holdoff_count <= 0;
|
||||
future.state <= ENABLE_IRQS;
|
||||
end if;
|
||||
|
||||
when TERMINATE_SIMULATION =>
|
||||
--stop(0);
|
||||
null;
|
||||
|
||||
end case;
|
||||
freq <= freq_calc(tuning_ppm, stability_ppm);
|
||||
half_per <= half_clk_per(freq);
|
||||
report "freq_error=" & real'image(freq-FREQ_NOMINAL);
|
||||
report "freq=" & real'image(freq);
|
||||
end process;
|
||||
|
||||
clock_i <= not clock_i after half_per;
|
||||
clock <= clock_i;
|
||||
|
||||
end architecture;
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@ library ieee;
|
|||
entity dac161s055_model is
|
||||
generic (
|
||||
-- Defaults chosen to match bladerf.pdf
|
||||
BIT_WIDTH : positive := 16;
|
||||
DAC_WIDTH : positive := 16;
|
||||
VREF : real := 2.5;
|
||||
MZB : boolean := true -- power on mid-scale?
|
||||
--bypass_spi : boolean := true
|
||||
)
|
||||
MZB : boolean := true; -- power on mid-scale?
|
||||
DIRECT_CONTROL : boolean := true
|
||||
);
|
||||
port (
|
||||
-- Control interface
|
||||
-- SPI Control interface
|
||||
--sclk : in std_logic;
|
||||
--sen : in std_logic;
|
||||
--sdi : in std_logic;
|
||||
--sdo : out std_logic;
|
||||
|
||||
-- Direct control interface (if bypassing SPI)
|
||||
dac_count : in unsigned(BIT_WIDTH-1 downto 0);
|
||||
-- Direct control interface
|
||||
dac_count : in unsigned(DAC_WIDTH-1 downto 0);
|
||||
ldacb : in std_logic := '0';
|
||||
|
||||
-- Analog output
|
||||
|
|
@ -45,59 +45,59 @@ entity dac161s055_model is
|
|||
);
|
||||
end entity;
|
||||
|
||||
architecture arch of mm_driver is
|
||||
architecture arch of dac161s055_model is
|
||||
|
||||
constant DAC_MID_SCALE : unsigned(BIT_WIDTH-1 downto 0) :=
|
||||
to_unsigned( ((2**(BIT_WIDTH))/2) , BIT_WIDTH );
|
||||
constant DAC_MID_SCALE : unsigned(DAC_WIDTH-1 downto 0) :=
|
||||
to_unsigned( ((2**(DAC_WIDTH))/2)-1 , DAC_WIDTH );
|
||||
|
||||
constant DAC_LSB_VOLTAGE : real := ( (VREF) / (2**BIT_WIDTH) );
|
||||
constant DAC_LSB_VOLTAGE : real := ( (VREF) / real(2**DAC_WIDTH) );
|
||||
|
||||
-- Given a DAC value, get the analog output voltage
|
||||
function get_voltage( dac : unsigned ) return real is
|
||||
begin
|
||||
return ( real(to_integer(dac)) * DAC_LSB_VOLTAGE;
|
||||
return ( real(to_integer(dac)) * DAC_LSB_VOLTAGE );
|
||||
end function;
|
||||
|
||||
|
||||
-- FSM States
|
||||
type fsm_t is (
|
||||
);
|
||||
--type fsm_t is ( );
|
||||
|
||||
-- State of internal signals
|
||||
type state_t is record
|
||||
state : fsm_t;
|
||||
--type state_t is record
|
||||
-- state : fsm_t;
|
||||
--end record;
|
||||
|
||||
end record;
|
||||
|
||||
constant RESET_VALUE : state_t := (
|
||||
state => RESET_COUNTERS,
|
||||
|
||||
);
|
||||
--constant RESET_VALUE : state_t := (
|
||||
-- state => RESET_COUNTERS,
|
||||
--);
|
||||
|
||||
|
||||
signal current : state_t := RESET_VALUE;
|
||||
signal future : state_t := RESET_VALUE;
|
||||
--signal current : state_t := RESET_VALUE;
|
||||
--signal future : state_t := RESET_VALUE;
|
||||
|
||||
signal powered_up : boolean := false;
|
||||
|
||||
begin
|
||||
|
||||
comb_proc : process( all )
|
||||
begin
|
||||
dac_guts : if( DIRECT_CONTROL = true ) generate
|
||||
comb_proc : process( all )
|
||||
begin
|
||||
|
||||
-- Power-up voltage output
|
||||
if( MZB ) then
|
||||
vout <= DAC_MID_SCALE;
|
||||
else
|
||||
vout <= 0.0;
|
||||
end if;
|
||||
if( powered_up = false ) then
|
||||
-- Power-up voltage output
|
||||
if( MZB ) then
|
||||
vout <= get_voltage(DAC_MID_SCALE);
|
||||
else
|
||||
vout <= 0.0;
|
||||
end if;
|
||||
powered_up <= true;
|
||||
end if;
|
||||
|
||||
-- Continuously load the DAC
|
||||
load_dac : while( ldacb = '0' ) loop
|
||||
vout <= get_voltage(dac_count);
|
||||
end loop;
|
||||
if( ldacb = '0' ) then
|
||||
vout <= get_voltage(dac_count);
|
||||
end if;
|
||||
|
||||
report "dac161s055 completed." severity warning;
|
||||
wait;
|
||||
|
||||
end process;
|
||||
end process;
|
||||
end generate;
|
||||
|
||||
end architecture;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ entity mm_driver is
|
|||
|
||||
mm_irq : in std_logic;
|
||||
|
||||
dac_count : out unsigned(15 downto 0);
|
||||
tcxo_clock : out std_logic
|
||||
);
|
||||
end entity;
|
||||
|
|
@ -49,9 +50,25 @@ architecture arch of mm_driver is
|
|||
return ( (0.5 sec) / real(freq) );
|
||||
end function;
|
||||
|
||||
constant TCXO_START_FREQ : real := 20.4e6;
|
||||
constant TCXO_TARGET_FREQ : real := 38.4e6;
|
||||
constant TCXO_INCR_FREQ : real := 1.0e6;
|
||||
constant TCXO_START_FREQ : real := 20.4e6;
|
||||
constant TCXO_TARGET_FREQ : real := 38.4e6;
|
||||
constant TCXO_INCR_FREQ : real := 1.0e6;
|
||||
|
||||
--constant PPS_1S_TARGET : signed(63 downto 0) := to_signed(7, 64);
|
||||
--constant PPS_10S_TARGET : signed(63 downto 0) := to_signed(77, 64);
|
||||
--constant PPS_100S_TARGET : signed(63 downto 0) := to_signed(768, 64);
|
||||
--
|
||||
--constant PPS_1S_MAX_ERROR : signed(63 downto 0) := to_signed(1, 64);
|
||||
--constant PPS_10S_MAX_ERROR : signed(63 downto 0) := to_signed(5, 64);
|
||||
--constant PPS_100S_MAX_ERROR : signed(63 downto 0) := to_signed(10, 64);
|
||||
|
||||
constant PPS_1S_TARGET : signed(63 downto 0) := x"0000_0000_0000_9600";--12_2C00";
|
||||
constant PPS_10S_TARGET : signed(63 downto 0) := x"0000_0000_0005_DC00";--B_B800";
|
||||
constant PPS_100S_TARGET : signed(63 downto 0) := x"0000_0000_003A_9800";--75_3000";
|
||||
|
||||
constant PPS_1S_MAX_ERROR : signed(63 downto 0) := to_signed(1, 64);
|
||||
constant PPS_10S_MAX_ERROR : signed(63 downto 0) := to_signed(3, 64);
|
||||
constant PPS_100S_MAX_ERROR : signed(63 downto 0) := to_signed(38, 64);
|
||||
|
||||
-- FSM States
|
||||
type fsm_t is (
|
||||
|
|
@ -65,30 +82,43 @@ architecture arch of mm_driver is
|
|||
TERMINATE_SIMULATION
|
||||
);
|
||||
|
||||
type error_t is record
|
||||
error : signed(63 downto 0);
|
||||
end record;
|
||||
|
||||
|
||||
-- State of internal signals
|
||||
type state_t is record
|
||||
state : fsm_t;
|
||||
holdoff_count : natural;
|
||||
pps_1s_count : std_logic_vector(63 downto 0);
|
||||
pps_10s_count : std_logic_vector(63 downto 0);
|
||||
pps_100s_count : std_logic_vector(63 downto 0);
|
||||
tcxo_half_per : time;
|
||||
tcxo_freq : real;
|
||||
state : fsm_t;
|
||||
holdoff_count : natural;
|
||||
pps_1s_count : std_logic_vector(63 downto 0);
|
||||
pps_10s_count : std_logic_vector(63 downto 0);
|
||||
pps_100s_count : std_logic_vector(63 downto 0);
|
||||
tcxo_half_per : time;
|
||||
tcxo_freq : real;
|
||||
pid_1s : error_t;
|
||||
pid_10s : error_t;
|
||||
pid_100s : error_t;
|
||||
dac : unsigned(dac_count'range);
|
||||
end record;
|
||||
|
||||
constant RESET_VALUE : state_t := (
|
||||
state => RESET_COUNTERS,
|
||||
holdoff_count => 0,
|
||||
pps_1s_count => (others => '-'),
|
||||
pps_10s_count => (others => '-'),
|
||||
pps_100s_count => (others => '-'),
|
||||
tcxo_half_per => half_clk_per( TCXO_START_FREQ ),
|
||||
tcxo_freq => TCXO_START_FREQ
|
||||
state => RESET_COUNTERS,
|
||||
holdoff_count => 0,
|
||||
pps_1s_count => (others => '-'),
|
||||
pps_10s_count => (others => '-'),
|
||||
pps_100s_count => (others => '-'),
|
||||
tcxo_half_per => half_clk_per( TCXO_START_FREQ ),
|
||||
tcxo_freq => TCXO_START_FREQ,
|
||||
pid_1s => ( error => (others => '0') ),
|
||||
pid_10s => ( error => (others => '0') ),
|
||||
pid_100s => ( error => (others => '0') ),
|
||||
dac => x"7FFF"
|
||||
);
|
||||
|
||||
constant RESET_TIME : natural := 50;
|
||||
constant DEAD_TIME : natural := 1000;
|
||||
constant IRQ_TIMEOUT : natural := 20000;
|
||||
constant IRQ_TIMEOUT : natural := 2**30; --40000;
|
||||
|
||||
constant PPS_CNT_1S_ADDR : natural := 0*8;
|
||||
constant PPS_CNT_10S_ADDR : natural := 1*8;
|
||||
|
|
@ -116,12 +146,17 @@ begin
|
|||
end process;
|
||||
|
||||
comb_proc : process( all )
|
||||
variable pps_1s_error : signed(63 downto 0) := (others => '0');
|
||||
variable pps_10s_error : signed(63 downto 0) := (others => '0');
|
||||
variable pps_100s_error : signed(63 downto 0) := (others => '0');
|
||||
begin
|
||||
mm_rd_req <= '0';
|
||||
mm_wr_req <= '0';
|
||||
mm_addr <= (others => '0');
|
||||
mm_wr_data <= (others => '0');
|
||||
|
||||
dac_count <= current.dac;
|
||||
|
||||
case (current.state) is
|
||||
when RESET_COUNTERS =>
|
||||
mm_wr_req <= '1';
|
||||
|
|
@ -150,9 +185,8 @@ begin
|
|||
if( mm_irq = '1' ) then
|
||||
future.holdoff_count <= 0;
|
||||
mm_wr_req <= '1';
|
||||
mm_wr_data <= x"11"; -- clear and disable interrupts
|
||||
mm_wr_data <= x"11"; -- clear the interrupt
|
||||
mm_addr <= std_logic_vector(to_unsigned(INTERRUPT_ADDR,mm_addr'length));
|
||||
--future.state <= READ_PPS_1S;
|
||||
future.state <= READ_COUNTS;
|
||||
else
|
||||
future.holdoff_count <= current.holdoff_count + 1;
|
||||
|
|
@ -207,6 +241,47 @@ begin
|
|||
end if;
|
||||
|
||||
when FREQ_ADJUST =>
|
||||
|
||||
-- Current error (only valid if the count is > 0)
|
||||
if( unsigned(current.pps_1s_count) /= to_unsigned(0,current.pps_1s_count'length) ) then
|
||||
pps_1s_error := signed(current.pps_1s_count)-PPS_1S_TARGET;
|
||||
end if;
|
||||
|
||||
if( unsigned(current.pps_10s_count) /= to_unsigned(0,current.pps_10s_count'length) ) then
|
||||
pps_10s_error := signed(current.pps_10s_count)-PPS_10S_TARGET;
|
||||
end if;
|
||||
|
||||
if( unsigned(current.pps_100s_count) /= to_unsigned(0,current.pps_100s_count'length) ) then
|
||||
pps_100s_error := signed(current.pps_100s_count)-PPS_100S_TARGET;
|
||||
end if;
|
||||
|
||||
-- Save current error off for next time "previous error"
|
||||
future.pid_1s.error <= pps_1s_error;
|
||||
future.pid_10s.error <= pps_10s_error;
|
||||
future.pid_100s.error <= pps_100s_error;
|
||||
|
||||
if( abs(pps_1s_error) > PPS_1S_MAX_ERROR ) then
|
||||
if( pps_1s_error < 0 ) then -- too slow, increase DAC
|
||||
future.dac <= current.dac + to_unsigned(1024,current.dac'length);
|
||||
else -- too fast, lower the DAC
|
||||
future.dac <= current.dac - to_unsigned(1024,current.dac'length);
|
||||
end if;
|
||||
elsif( abs(pps_10s_error) > PPS_10S_MAX_ERROR ) then
|
||||
if( pps_10s_error < 0 ) then -- too slow, increase DAC
|
||||
future.dac <= current.dac + to_unsigned(512,current.dac'length);
|
||||
else -- too fast, lower the DAC
|
||||
future.dac <= current.dac - to_unsigned(512,current.dac'length);
|
||||
end if;
|
||||
elsif( abs(pps_100s_error) > PPS_100S_MAX_ERROR ) then
|
||||
if( pps_100s_error < 0 ) then -- too slow, increase DAC
|
||||
future.dac <= current.dac + to_unsigned(128,current.dac'length);
|
||||
else -- too fast, lower the DAC
|
||||
future.dac <= current.dac - to_unsigned(128,current.dac'length);
|
||||
end if;
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
future.tcxo_half_per <= half_clk_per(current.tcxo_freq+TCXO_INCR_FREQ);
|
||||
future.tcxo_freq <= current.tcxo_freq + TCXO_INCR_FREQ;
|
||||
future.state <= HOLDOFF;
|
||||
|
|
@ -219,7 +294,7 @@ begin
|
|||
end if;
|
||||
|
||||
when TERMINATE_SIMULATION =>
|
||||
--stop(0);
|
||||
stop(0);
|
||||
null;
|
||||
|
||||
end case;
|
||||
|
|
|
|||
|
|
@ -32,9 +32,11 @@ architecture tb of ppscal_tb is
|
|||
end function;
|
||||
|
||||
constant SYS_CLK_PER : time := half_clk_per( 80.0e6 );
|
||||
constant REF_1PPS_PER : time := half_clk_per( 5.0e6 );
|
||||
constant REF_1PPS_PER : time := half_clk_per( 1.0e3 ); --5.0e6 );
|
||||
constant IDEAL_384_PER : time := half_clk_per( 38.4e6 );
|
||||
|
||||
signal ref_1pps : std_logic := '1';
|
||||
signal ideal_38p4 : std_logic := '1';
|
||||
|
||||
signal sys_clk : std_logic := '1';
|
||||
signal sys_rst : std_logic;
|
||||
|
|
@ -48,15 +50,75 @@ architecture tb of ppscal_tb is
|
|||
signal irq : std_logic;
|
||||
signal tcxo_clock : std_logic;
|
||||
|
||||
signal dac_count : unsigned(15 downto 0) := x"7FFF";
|
||||
signal tcxo_vcon : real := 1.4;
|
||||
|
||||
-- alias uut_pps_1s_target is << signal .ppscal_tb.uut.pps_1s.target : signed(63 downto 0) >>;
|
||||
-- alias uut_pps_10s_target is << signal .ppscal_tb.uut.pps_10s.target : signed(63 downto 0) >>;
|
||||
-- alias uut_pps_100s_target is << signal .ppscal_tb.uut.pps_100s.target : signed(63 downto 0) >>;
|
||||
--
|
||||
-- alias drv_pps_1s_target is << signal .ppscal_tb.driver.PPS_1S_TARGET : signed(63 downto 0) >>;
|
||||
-- alias drv_pps_10s_target is << signal .ppscal_tb.driver.PPS_10S_TARGET : signed(63 downto 0) >>;
|
||||
-- alias drv_pps_100s_target is << signal .ppscal_tb.driver.PPS_100S_TARGET : signed(63 downto 0) >>;
|
||||
--
|
||||
-- constant PPS_1S_TARGET : signed(63 downto 0) := x"0000_0000_0000_0F00";--12_2C00";
|
||||
-- constant PPS_10S_TARGET : signed(63 downto 0) := x"0000_0000_0000_9600";--B_B800";
|
||||
-- constant PPS_100S_TARGET : signed(63 downto 0) := x"0000_0000_0005_DC00";--75_3000";
|
||||
|
||||
begin
|
||||
|
||||
--process
|
||||
--begin
|
||||
-- uut_pps_1s_target <= force PPS_1S_TARGET;
|
||||
-- drv_pps_1s_target <= force PPS_1S_TARGET;
|
||||
--
|
||||
-- uut_pps_10s_target <= force PPS_10S_TARGET;
|
||||
-- drv_pps_10s_target <= force PPS_10S_TARGET;
|
||||
--
|
||||
-- uut_pps_100s_target <= force PPS_100S_TARGET;
|
||||
-- drv_pps_100s_target <= force PPS_100S_TARGET;
|
||||
-- wait;
|
||||
--end process;
|
||||
|
||||
|
||||
sys_clk <= not sys_clk after SYS_CLK_PER;
|
||||
sys_rst <= '1', '0' after SYS_CLK_PER*5;
|
||||
|
||||
ref_1pps <= not ref_1pps after REF_1PPS_PER;
|
||||
|
||||
ideal_38p4 <= not ideal_38p4 after IDEAL_384_PER;
|
||||
|
||||
-- process
|
||||
-- begin
|
||||
-- dac_count <= (others => '0');
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait for 10 us;
|
||||
-- dac_count <= dac_count + x"1000";
|
||||
-- wait;
|
||||
-- end process;
|
||||
|
||||
|
||||
uut : entity work.ppscal(arch)
|
||||
generic map (
|
||||
SIMULATION => true
|
||||
)
|
||||
port map(
|
||||
-- Physical Interface
|
||||
ref_1pps => ref_1pps,
|
||||
|
|
@ -92,7 +154,33 @@ begin
|
|||
|
||||
mm_irq => irq,
|
||||
|
||||
tcxo_clock => tcxo_clock
|
||||
dac_count => dac_count,
|
||||
tcxo_clock => open --tcxo_clock
|
||||
);
|
||||
|
||||
dac : entity work.dac161s055_model
|
||||
generic map (
|
||||
DIRECT_CONTROL => true
|
||||
)
|
||||
port map (
|
||||
-- SPI Control interface
|
||||
--sclk : in std_logic;
|
||||
--sen : in std_logic;
|
||||
--sdi : in std_logic;
|
||||
--sdo : out std_logic;
|
||||
|
||||
-- Direct control interface
|
||||
dac_count => dac_count, -- in unsigned(DAC_WIDTH-1 downto 0);
|
||||
ldacb => '0', -- in std_logic := '0';
|
||||
|
||||
-- Analog output
|
||||
vout => tcxo_vcon -- out real
|
||||
);
|
||||
|
||||
vctcxo : entity work.asvtx12a384m_model
|
||||
port map (
|
||||
vcon => tcxo_vcon, -- in real; -- control voltage
|
||||
clock => tcxo_clock -- out std_logic -- output clock
|
||||
);
|
||||
|
||||
end architecture;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue