| 1 |
-- Copyright (c) 2017 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 |
|
| 21 |
library ieee; |
| 22 |
use ieee.std_logic_1164.all; |
| 23 |
use ieee.numeric_std.all; |
| 24 |
use ieee.math_real.all; |
| 25 |
|
| 26 |
-- ---------------------------------------------------------------------------- |
| 27 |
-- Power supply synchronization controller |
| 28 |
-- ---------------------------------------------------------------------------- |
| 29 |
entity ps_sync is |
| 30 |
generic ( |
| 31 |
OUTPUTS : natural := 1; -- Number of ps sync signals |
| 32 |
USE_LFSR : boolean := true; -- Use LFSR to cycle through freqs |
| 33 |
HOP_LIST : integer_vector; -- Array of number of refclk cycles |
| 34 |
-- that sync remains at '0' or '1'. |
| 35 |
HOP_RATE : natural := 1 -- Number of times to repeat each |
| 36 |
-- hop freq. before moving on. |
| 37 |
); |
| 38 |
port ( |
| 39 |
refclk : in std_logic; |
| 40 |
sync : out std_logic_vector(OUTPUTS-1 downto 0) := (others => '0') |
| 41 |
); |
| 42 |
end entity; |
| 43 |
|
| 44 |
architecture arch of ps_sync is |
| 45 |
|
| 46 |
begin |
| 47 |
|
| 48 |
sync_proc : process(refclk) |
| 49 |
variable count : natural; |
| 50 |
variable count_rate : natural; |
| 51 |
variable sync_v : std_logic := '0'; |
| 52 |
variable sel : natural range HOP_LIST'range := HOP_LIST'low; |
| 53 |
|
| 54 |
-- A 10-bit maximal length LFSR should be plenty for the number of hop freqs |
| 55 |
constant LFSR_SEED : unsigned(9 downto 0) := 10x"281"; |
| 56 |
variable lfsr : unsigned(LFSR_SEED'range) := LFSR_SEED; |
| 57 |
|
| 58 |
-- FSM |
| 59 |
type fsm_t is ( |
| 60 |
LOAD_COUNT, |
| 61 |
DOWNCOUNT_LOW, |
| 62 |
DOWNCOUNT_HIGH |
| 63 |
); |
| 64 |
variable state : fsm_t := LOAD_COUNT; |
| 65 |
|
| 66 |
begin |
| 67 |
if( rising_edge(refclk) ) then |
| 68 |
|
| 69 |
case state is |
| 70 |
|
| 71 |
when LOAD_COUNT => |
| 72 |
|
| 73 |
if( USE_LFSR = true ) then |
| 74 |
sel := to_integer(lfsr) mod HOP_LIST'length; |
| 75 |
end if; |
| 76 |
|
| 77 |
count := HOP_LIST(sel) - 1; -- this cycle counts as the first |
| 78 |
count_rate := HOP_RATE; |
| 79 |
sync_v := '0'; |
| 80 |
state := DOWNCOUNT_LOW; |
| 81 |
|
| 82 |
when DOWNCOUNT_LOW => |
| 83 |
|
| 84 |
sync_v := '0'; |
| 85 |
|
| 86 |
if( count = 1 ) then |
| 87 |
sync_v := '1'; |
| 88 |
count := HOP_LIST(sel); |
| 89 |
state := DOWNCOUNT_HIGH; |
| 90 |
else |
| 91 |
count := count - 1; |
| 92 |
end if; |
| 93 |
|
| 94 |
when DOWNCOUNT_HIGH => |
| 95 |
|
| 96 |
sync_v := '1'; |
| 97 |
|
| 98 |
if( count = 1 ) then |
| 99 |
if( count_rate = 1 ) then |
| 100 |
if( USE_LFSR = true ) then |
| 101 |
lfsr := lfsr(lfsr'high-1 downto lfsr'low) & (lfsr(9) xor lfsr(6)); |
| 102 |
else |
| 103 |
sel := (sel + 1) mod HOP_LIST'length; |
| 104 |
end if; |
| 105 |
sync_v := '0'; |
| 106 |
state := LOAD_COUNT; |
| 107 |
else |
| 108 |
sync_v := '0'; |
| 109 |
count := HOP_LIST(sel); |
| 110 |
count_rate := count_rate - 1; |
| 111 |
state := DOWNCOUNT_LOW; |
| 112 |
end if; |
| 113 |
else |
| 114 |
count := count - 1; |
| 115 |
end if; |
| 116 |
|
| 117 |
when others => |
| 118 |
|
| 119 |
sel := HOP_LIST'low; |
| 120 |
sync_v := '0'; |
| 121 |
state := LOAD_COUNT; |
| 122 |
|
| 123 |
end case; |
| 124 |
|
| 125 |
sync <= (others => sync_v); |
| 126 |
|
| 127 |
end if; |
| 128 |
end process; |
| 129 |
|
| 130 |
end architecture; |