--- /dev/null
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+
+
+entity pwm_generator is
+ generic(
+ CHANNELS : integer := 32
+ );
+ port(
+ CLK : in std_logic;
+
+ DATA_IN : in std_logic_vector(15 downto 0) := (others => '0');
+ DATA_OUT : out std_logic_vector(15 downto 0);
+ WRITE_IN : in std_logic := '0';
+ COMP_IN : in signed(15 downto 0);
+ ADDR_IN : in std_logic_vector(4 downto 0) := (others => '0');
+
+
+ PWM : out std_logic_vector(CHANNELS-1 downto 0)
+
+ );
+end entity;
+
+
+
+architecture pwm_arch of pwm_generator is
+
+type ram_t is array(0 to CHANNELS-1) of unsigned(15 downto 0);
+signal set : ram_t := (others => x"87C1");
+signal set_tmp : ram_t;
+
+type cnt_t is array(0 to CHANNELS-1) of unsigned(16 downto 0);
+signal cnt : cnt_t := (others => (others => '0'));
+
+signal last_flag : std_logic_vector(CHANNELS-1 downto 0) := (others => '0');
+signal flag : std_logic_vector(CHANNELS-1 downto 0) := (others => '0');
+signal pwm_i : std_logic_vector(CHANNELS-1 downto 0) := (others => '0');
+
+signal i : integer range 0 to CHANNELS-1 := 0;
+signal clock_enable : std_logic_vector(15 downto 0) := x"0001";
+begin
+
+PROC_MEM : process begin
+ wait until rising_edge(CLK);
+ if WRITE_IN = '1' then
+ set(to_integer(unsigned(ADDR_IN))) <= unsigned(DATA_IN);
+ end if;
+ DATA_OUT <= std_logic_vector(set(to_integer(unsigned(ADDR_IN))));
+end process;
+
+
+GEN_REAL_VALUES : process begin
+ wait until rising_edge(CLK);
+ set_tmp(i) <= unsigned(signed(set(i)) + COMP_IN);
+ i <= i + 1;
+end process;
+
+process begin
+ wait until rising_edge(CLK);
+ clock_enable <= clock_enable(14 downto 0) & clock_enable(15);
+end process;
+
+gen_channels : for i in 0 to CHANNELS-1 generate
+ flag(i) <= cnt(i)(16);
+
+ process begin
+ wait until rising_edge(CLK);
+ if clock_enable(i) = '1' then
+ last_flag(i) <= flag(i);
+ pwm_i(i) <= (last_flag(i) xor flag(i));
+ cnt(i) <= cnt(i) + resize(set_tmp(i),17);
+ end if;
+ end process;
+end generate;
+
+
+
+PWM(CHANNELS-1 downto 0 ) <= pwm_i(CHANNELS-1 downto 0);
+
+end architecture;
add_file -vhdl -lib work "../../trbnet/trb_net_std.vhd"
add_file -vhdl -lib work "../../logicbox/code/uart_sctrl.vhd"
add_file -vhdl -lib work "../../logicbox/code/sedcheck.vhd"
-add_file -vhdl -lib work "../../mdcfee/code/pwm.vhd"
+add_file -vhdl -lib work "../code/pwm_machxo.vhd"
add_file -vhdl -lib work "../../trbnet/special/uart_rec.vhd"
add_file -vhdl -lib work "../../trbnet/special/uart_trans.vhd"
\r
entity thresholds is\r
port(\r
- CLK : in std_logic;\r
- \r
+ ID : in std_logic;\r
OUTPUT : out std_logic_vector(15 downto 0);\r
- TX_IN : in std_logic;\r
- RX_OUT : out std_logic\r
+ TX_IN : in std_logic;\r
+ RX_OUT : out std_logic\r
-- MISO_OUT : out std_logic;\r
-- MOSI_IN : in std_logic;\r
-- SCLK_IN : in std_logic;\r
signal flash_busy : std_logic;\r
signal flash_err : std_logic;\r
\r
+ signal compensate_i : signed(15 downto 0);\r
+ signal pwm_i : std_logic_vector(15 downto 0);\r
\r
component OSCH\r
generic (NOM_FREQ: string := "33.25");\r
if bus_read = '1' then\r
bus_ready <= '1';\r
case uart_addr is\r
+ when x"10" => uart_tx_data <= std_logic_vector(compensate_i);\r
when x"ee" => uart_tx_data <= sed_debug;\r
end case;\r
elsif bus_write = '1' then\r
else\r
case uart_addr is\r
-- when x"10" => reg <= uart_rx_data;\r
+ when x"10" => compensate_i <= signed(uart_rx_data(15 downto 0);\r
when x"ee" => controlsed_i <= uart_rx_data(3 downto 0);\r
end case;\r
end if; \r
CLK => clk_i,\r
DATA_IN => pwm_data_i,\r
DATA_OUT => open,\r
- COMP_IN => (others => '0'),\r
+ COMP_IN => compensate_i,\r
WRITE_IN => pwm_write_i,\r
ADDR_IN => pwm_addr_i,\r
- PWM => OUTPUT\r
+ PWM => pwm_i\r
); \r
+\r
+--TODO connect to output according to ID\r
+OUTPUT <= pwm_i;\r
\r
---------------------------------------------------------------------------\r
-- Flash Controller\r
end architecture;\r
\r
\r
-
\ No newline at end of file
+ \r