1 ------------------------------------------------------------------------------- 2 -- File : Ad9249ConfigNoPullup.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2013-09-23 5 -- Last update: 2016-12-12 6 ------------------------------------------------------------------------------- 7 -- Description: AD9249 Configuration/Status Module (no pullup version) 8 ------------------------------------------------------------------------------- 9 -- This file is part of 'SLAC Firmware Standard Library'. 10 -- It is subject to the license terms in the LICENSE.txt file found in the 11 -- top-level directory of this distribution and at: 12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 13 -- No part of 'SLAC Firmware Standard Library', including this file, 14 -- may be copied, modified, propagated, or distributed except according to 15 -- the terms contained in the LICENSE.txt file. 16 ------------------------------------------------------------------------------- 20 use ieee.std_logic_1164.
all;
21 use ieee.std_logic_arith.
all;
22 use ieee.std_logic_unsigned.
all;
28 --! @ingroup devices_AnalogDevices_ad9249 56 end Ad9249ConfigNoPullup;
59 -- Define architecture 63 constant SCLK_COUNTER_SIZE_C : := bitSize(SPI_CLK_PERIOD_DIV2_CYCLES_C);
66 signal intShift : (23 downto 0);
69 signal shiftCnt : (12 downto 0);
76 signal sclkCounter : (SCLK_COUNTER_SIZE_C-1 downto 0);
79 constant ST_IDLE : (1 downto 0) := "01";
80 constant ST_SHIFT : (1 downto 0) := "10";
81 constant ST_DONE : (1 downto 0) := "11";
82 signal curState : (1 downto 0);
83 signal nxtState : (1 downto 0);
85 signal adcWrData : (7 downto 0);
86 signal adcRdData : (7 downto 0);
87 signal adcAddr : (12 downto 0);
93 constant PWDN_ADDR_BIT_C : := 11 + CHIP_SEL_WIDTH_C;
94 constant PWDN_ADDR_C : slv(PWDN_ADDR_BIT_C downto 0) := toSlv(2**PWDN_ADDR_BIT_C, PWDN_ADDR_BIT_C+1);
96 type StateType is (ADC_IDLE_S, ADC_READ_S, ADC_WRITE_S);
99 type RegType is record 104 chipSel : slv(CHIP_SEL_WIDTH_C-1 downto 0);
105 wrData : slv(23 downto 0);
111 constant REG_INIT_C : RegType := ( 115 chipSel => (others => '0'), 116 wrData => (others => '0'), 119 pdwn => (others => '0'));
121 signal r : RegType := REG_INIT_C;
122 signal rin : RegType;
128 variable v : RegType;
136 -- Any other address is forwarded to the chip via SPI 139 v.wrData(23) := '0';
-- Write bit 140 v.wrData(22 downto 21) := "00";
-- Number of bytes (1) 141 v.wrData(20 downto 17) := "0000";
-- Unused address bits 156 v.wrData(23) := '1';
-- read bit 157 v.wrData(22 downto 21) := "00";
-- Number of bytes (1) 158 v.wrData(20 downto 17) := "0000";
-- Unused address bits 160 v.wrData(7 downto 0) := (others => '0');
175 if r.adcWrReq = '1' then 176 v.state := ADC_WRITE_S;
177 elsif r.adcRdReq = '1' then 178 v.state := ADC_READ_S;
185 v.state := ADC_IDLE_S;
193 v.state := ADC_IDLE_S;
210 adcWrReq <= r.adcWrReq;
211 adcRdReq <= r.adcRdReq;
212 adcWrData <= r.wrData(7 downto 0);
213 adcAddr <= r.wrData(20 downto 8);
221 r <= rin after TPD_G;
227 -- Generate clock enable for state machine 232 sclkCounter <= (others => '0');
235 if (sclkCounter = SPI_CLK_PERIOD_DIV2_CYCLES_C) then 236 sclkCounter <= (others => '0');
239 sclkCounter <= sclkCounter + 1;
247 adcRdData <= intShift(7 downto 0);
250 adcSDout <= locSDout when adcSDir = '0' else '1';
251 -- Enable for the top level tri-state 254 -- Control shift memory register 259 adcAck <= '0' after TPD_G;
260 adcSDir <= '0' after TPD_G;
261 locSDout <= '0'
after TPD_G;
264 nextClk <= '1' after TPD_G;
265 shiftCnt <= (others => '0') after TPD_G;
266 shiftCntEn <= '0' after TPD_G;
267 intShift <= (others => '0') after TPD_G;
268 curState <= ST_IDLE after TPD_G;
269 elsif axilClkEn = '1' then 272 curState <= nxtState after TPD_G;
273 adcAck <= nextAck after TPD_G;
275 -- Shift count is not enabled 276 if shiftCntEn = '0' then 278 locSDout <= '0'
after TPD_G;
279 adcSDir <= '0' after TPD_G;
281 nextClk <= '1' after TPD_G;
283 -- Wait for shift request 284 if shiftEn = '1' then 285 shiftCntEn <= '1' after TPD_G;
286 shiftCnt <= (others => '0') after TPD_G;
287 intShift(23) <= adcRdReq after TPD_G;
288 intShift(22 downto 21) <= "00" after TPD_G;
289 intShift(20 downto 8) <= adcAddr after TPD_G;
290 intShift(7 downto 0) <= adcWrData after TPD_G;
293 shiftCnt <= shiftCnt + 1 after TPD_G;
295 -- Clock 0, setup output 296 if shiftCnt(7 downto 0) = 0 then 298 -- Clock goes back to zero 301 -- Shift Count 0-23, output and shift data 302 if shiftCnt(12 downto 8) < 24 then 303 locSDout <= intShift(
23)
after TPD_G;
304 intShift <= intShift(22 downto 0) & adcSDin after TPD_G;
306 nextClk <= '1' after TPD_G;
308 -- Done, Sample last value 310 intShift <= intShift(22 downto 0) & adcSDin after TPD_G;
311 locSDout <= '0'
after TPD_G;
313 nextClk <= '0' after TPD_G;
316 -- Clock 3, clock output 317 elsif shiftCnt(7 downto 0) = 8 then 320 -- Tristate after 16 bits if read 321 if shiftCnt(12 downto 8) = 15 and adcRdReq = '1' then 322 adcSDir <= '1' after TPD_G;
326 if shiftCnt(12 downto 8) = 24 then 327 shiftCntEn <= '0' after TPD_G;
336 -- State machine control 337 process (curState, adcWrReq, adcRdReq, shiftCntEn)
341 -- IDLE, wait for request 346 if adcWrReq = '1' or adcRdReq = '1' then 348 nxtState <= ST_SHIFT;
351 nxtState <= curState;
359 -- Wait for shift to be done 360 if shiftCntEn = '0' then 363 nxtState <= curState;
371 -- Wait for request to go away 372 if adcRdReq = '0' and adcWrReq = '0' then 375 nxtState <= curState;
385 end architecture rtl;
in axilReadMasterAxiLiteReadMasterType
in axilWriteMasterAxiLiteWriteMasterType
AXIL_ERR_RESP_Gslv( 1 downto 0) := AXI_RESP_DECERR_C
out axilReadSlaveAxiLiteReadSlaveType
CLK_PERIOD_Greal := 8.0e-9
slv( 1 downto 0) := "11" AXI_RESP_DECERR_C
out adcCsbstd_logic_vector( NUM_CHIPS_G* 2- 1 downto 0)
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
out adcPdwnstd_logic_vector( NUM_CHIPS_G- 1 downto 0)
CLK_EN_PERIOD_Greal := 16.0e-9
slv( 1 downto 0) := "00" AXI_RESP_OK_C
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C
out axilWriteSlaveAxiLiteWriteSlaveType