repo2/atari_chips/pokeyv2/SID/oscillator.vhdl
| 1043 | markw | ---------------------------------------------------------------------------
|
|
-- (c) 2020 mark watson
|
|||
-- I am happy for anyone to use this for non-commercial use.
|
|||
-- If my vhdl files are used commercially or otherwise sold,
|
|||
-- please contact me for explicit permission at scrameta (gmail).
|
|||
-- This applies for source and binary form and derived works.
|
|||
---------------------------------------------------------------------------
|
|||
LIBRARY ieee;
|
|||
USE ieee.std_logic_1164.all;
|
|||
use ieee.numeric_std.all;
|
|||
ENTITY SID_oscillator IS
|
|||
PORT
|
|||
(
|
|||
CLK : IN STD_LOGIC;
|
|||
RESET_N : IN STD_LOGIC;
|
|||
ENABLE : IN STD_LOGIC;
|
|||
BITS_OUT : OUT STD_LOGIC_VECTOR(11 downto 0);
|
|||
| 1056 | markw | TEST : IN STD_LOGIC;
|
|
| 1043 | markw | SYNC_IN : IN STD_LOGIC;
|
|
SYNC_OUT : OUT STD_LOGIC;
|
|||
| 1056 | markw | LFSR_ENABLE : OUT STD_LOGIC;
|
|
| 1213 | markw | CHANGING : OUT STD_LOGIC;
|
|
| 1043 | markw | ||
| 1062 | markw | ADJ : IN STD_LOGIC_VECTOR(15 downto 0)
|
|
);
|
|||
| 1043 | markw | END SID_oscillator;
|
|
ARCHITECTURE vhdl OF SID_oscillator IS
|
|||
signal count_reg: unsigned(23 downto 0);
|
|||
signal count_next: unsigned(23 downto 0);
|
|||
| 1284 | markw | ||
signal lfsr_enable_shift_reg: std_logic_vector(1 downto 0);
|
|||
signal lfsr_enable_shift_next: std_logic_vector(1 downto 0);
|
|||
| 1043 | markw | BEGIN
|
|
-- register
|
|||
process(clk, reset_n)
|
|||
begin
|
|||
if (reset_n = '0') then
|
|||
count_reg <= (others=>'0');
|
|||
| 1284 | markw | lfsr_enable_shift_reg <= (others=>'0');
|
|
| 1043 | markw | elsif (clk'event and clk='1') then
|
|
count_reg <= count_next;
|
|||
| 1284 | markw | lfsr_enable_shift_reg <= lfsr_enable_shift_next;
|
|
| 1043 | markw | end if;
|
|
end process;
|
|||
-- next state
|
|||
| 1284 | markw | process(count_reg,count_next,enable,adj,sync_in,test,lfsr_enable_shift_reg)
|
|
| 1062 | markw | variable count_inc : unsigned(23 downto 0);
|
|
| 1284 | markw | variable lfsr_enable_raw : std_logic;
|
|
| 1043 | markw | begin
|
|
count_next <= count_reg;
|
|||
| 1284 | markw | lfsr_enable_shift_next <= lfsr_enable_shift_reg;
|
|
| 1043 | markw | sync_out <= '0';
|
|
| 1213 | markw | changing <= '0';
|
|
| 1043 | markw | ||
if (enable = '1') then
|
|||
| 1056 | markw | count_inc := count_reg+resize(unsigned(adj),24);
|
|
| 1043 | markw | ||
| 1056 | markw | sync_out <= count_inc(23) and not(count_reg(23));
|
|
| 1284 | markw | lfsr_enable_raw := count_inc(19) and not(count_reg(19));
|
|
| 1043 | markw | ||
| 1056 | markw | if (sync_in='1' or test='1') then
|
|
| 1043 | markw | count_next <= (others=>'0');
|
|
else
|
|||
count_next <= count_inc;
|
|||
end if;
|
|||
| 1213 | markw | ||
if (count_reg(23 downto 12) /= count_next(23 downto 12)) then
|
|||
changing <= '1';
|
|||
end if;
|
|||
| 1284 | markw | ||
lfsr_enable_shift_next <= lfsr_enable_shift_reg(0 downto 0)&lfsr_enable_raw;
|
|||
| 1043 | markw | end if;
|
|
end process;
|
|||
--output
|
|||
| 1062 | markw | bits_out <= std_logic_vector(count_reg(23 downto 12));
|
|
| 1284 | markw | lfsr_enable <= lfsr_enable_shift_reg(1) and enable;
|
|
| 1043 | markw | ||
END vhdl;
|