| 1 |
-- Copyright (c) 2015 Nuand LLC |
| 2 |
-- |
| 3 |
-- Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 |
-- of this software and associated documentation files (the "Software"), to deal |
| 5 |
-- in the Software without restriction, including without limitation the rights |
| 6 |
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 |
-- copies of the Software, and to permit persons to whom the Software is |
| 8 |
-- furnished to do so, subject to the following conditions: |
| 9 |
-- |
| 10 |
-- The above copyright notice and this permission notice shall be included in |
| 11 |
-- all copies or substantial portions of the Software. |
| 12 |
-- |
| 13 |
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 |
-- THE SOFTWARE. |
| 20 |
library ieee; |
| 21 |
use ieee.std_logic_1164.all; |
| 22 |
use ieee.numeric_std.all; |
| 23 |
|
| 24 |
entity dac161s055_model is |
| 25 |
generic ( |
| 26 |
-- Defaults chosen to match bladerf.pdf |
| 27 |
DAC_WIDTH : positive := 16; |
| 28 |
VREF : real := 2.5; |
| 29 |
MZB : boolean := true; -- power on mid-scale? |
| 30 |
DIRECT_CONTROL : boolean := true |
| 31 |
); |
| 32 |
port ( |
| 33 |
-- SPI Control interface |
| 34 |
--sclk : in std_logic; |
| 35 |
--sen : in std_logic; |
| 36 |
--sdi : in std_logic; |
| 37 |
--sdo : out std_logic; |
| 38 |
|
| 39 |
-- Direct control interface |
| 40 |
dac_count : in unsigned(DAC_WIDTH-1 downto 0); |
| 41 |
ldacb : in std_logic := '0'; |
| 42 |
|
| 43 |
-- Analog output |
| 44 |
vout : out real |
| 45 |
); |
| 46 |
end entity; |
| 47 |
|
| 48 |
architecture arch of dac161s055_model is |
| 49 |
|
| 50 |
constant DAC_MID_SCALE : unsigned(DAC_WIDTH-1 downto 0) := |
| 51 |
to_unsigned( ((2**(DAC_WIDTH))/2)-1 , DAC_WIDTH ); |
| 52 |
|
| 53 |
constant DAC_LSB_VOLTAGE : real := ( (VREF) / real(2**DAC_WIDTH) ); |
| 54 |
|
| 55 |
-- Given a DAC value, get the analog output voltage |
| 56 |
function get_voltage( dac : unsigned ) return real is |
| 57 |
begin |
| 58 |
return ( real(to_integer(dac)) * DAC_LSB_VOLTAGE ); |
| 59 |
end function; |
| 60 |
|
| 61 |
|
| 62 |
-- FSM States |
| 63 |
--type fsm_t is ( ); |
| 64 |
|
| 65 |
-- State of internal signals |
| 66 |
--type state_t is record |
| 67 |
-- state : fsm_t; |
| 68 |
--end record; |
| 69 |
|
| 70 |
--constant RESET_VALUE : state_t := ( |
| 71 |
-- state => RESET_COUNTERS, |
| 72 |
--); |
| 73 |
|
| 74 |
|
| 75 |
--signal current : state_t := RESET_VALUE; |
| 76 |
--signal future : state_t := RESET_VALUE; |
| 77 |
|
| 78 |
signal powered_up : boolean := false; |
| 79 |
|
| 80 |
begin |
| 81 |
|
| 82 |
dac_guts : if( DIRECT_CONTROL = true ) generate |
| 83 |
comb_proc : process( all ) |
| 84 |
begin |
| 85 |
|
| 86 |
if( powered_up = false ) then |
| 87 |
-- Power-up voltage output |
| 88 |
if( MZB ) then |
| 89 |
vout <= get_voltage(DAC_MID_SCALE); |
| 90 |
else |
| 91 |
vout <= 0.0; |
| 92 |
end if; |
| 93 |
powered_up <= true; |
| 94 |
end if; |
| 95 |
|
| 96 |
if( ldacb = '0' ) then |
| 97 |
vout <= get_voltage(dac_count); |
| 98 |
end if; |
| 99 |
|
| 100 |
end process; |
| 101 |
end generate; |
| 102 |
|
| 103 |
end architecture; |