diff --git a/FPGA/VNA/MCP33131.vhd b/FPGA/VNA/MCP33131.vhd
index 8b560c3..3419a81 100644
--- a/FPGA/VNA/MCP33131.vhd
+++ b/FPGA/VNA/MCP33131.vhd
@@ -42,15 +42,16 @@ entity MCP33131 is
RESET_MINMAX : in STD_LOGIC;
SDO : in STD_LOGIC;
CONVSTART : out STD_LOGIC;
- SCLK : out STD_LOGIC);
+ SCLK : inout STD_LOGIC);
end MCP33131;
architecture Behavioral of MCP33131 is
signal conv_cnt : integer range 0 to CONVCYCLES-1;
signal div_cnt : integer range 0 to (CLK_DIV/2)-1;
+ signal bit_cnt : integer range 0 to 15;
signal sclk_phase : std_logic;
signal adc_data : std_logic_vector(15 downto 0);
- type States is (Idle, Conversion, WAIT_tEN, Transmission);
+ type States is (Idle, Conversion, WAIT_tEN, Transmission, Done);
signal state : States;
signal min_int, max_int, data_int : signed(15 downto 0);
begin
@@ -58,6 +59,14 @@ begin
MIN <= std_logic_vector(min_int);
MAX <= std_logic_vector(max_int);
DATA <= std_logic_vector(data_int);
+ SCLK <= sclk_phase;
+
+ process(SCLK)
+ begin
+ if(falling_edge(SCLK)) then
+ adc_data <= adc_data(14 downto 0) & SDO;
+ end if;
+ end process;
process(CLK, RESET)
begin
@@ -70,6 +79,7 @@ begin
CONVSTART <= '0';
conv_cnt <= 0;
div_cnt <= 0;
+ bit_cnt <= 0;
min_int <= to_signed(32767, 16);
max_int <= to_signed(-32768, 16);
else
@@ -86,8 +96,8 @@ begin
end if;
case state is
when Idle =>
- SCLK <= '0';
READY <= '0';
+ bit_cnt <= 0;
if START = '1' then
state <= Conversion;
conv_cnt <= 0;
@@ -99,7 +109,6 @@ begin
else
div_cnt <= 0;
CONVSTART <= '0';
- adc_data <= "0000000000000001";
state <= WAIT_tEN;
end if;
when WAIT_tEN =>
@@ -110,22 +119,20 @@ begin
else
if(sclk_phase = '0') then
sclk_phase <= '1';
- SCLK <= '1';
else
sclk_phase <= '0';
- SCLK <= '0';
- if(adc_data(15) = '0') then
- -- not the last bit yet
- adc_data <= adc_data(14 downto 0) & SDO;
+ if bit_cnt = 15 then
+ state <= Done;
else
- -- last bit, move to output and indicate ready state
- data_int <= signed(adc_data(14 downto 0) & SDO);
- READY <= '1';
- state <= Idle;
+ bit_cnt <= bit_cnt + 1;
end if;
end if;
div_cnt <= 0;
end if;
+ when Done =>
+ data_int <= signed(adc_data);
+ READY <= '1';
+ state <= Idle;
end case;
end if;
end if;
diff --git a/FPGA/VNA/Test_MCP33131.vhd b/FPGA/VNA/Test_MCP33131.vhd
index ed1c257..c3f8214 100644
--- a/FPGA/VNA/Test_MCP33131.vhd
+++ b/FPGA/VNA/Test_MCP33131.vhd
@@ -53,7 +53,7 @@ ARCHITECTURE behavior OF Test_MCP33131 IS
RESET_MINMAX : in STD_LOGIC;
SDO : IN std_logic;
CONVSTART : OUT std_logic;
- SCLK : OUT std_logic
+ SCLK : INOUT std_logic
);
END COMPONENT;
diff --git a/FPGA/VNA/VNA.gise b/FPGA/VNA/VNA.gise
index 52ca488..1766d7a 100644
--- a/FPGA/VNA/VNA.gise
+++ b/FPGA/VNA/VNA.gise
@@ -41,7 +41,9 @@
+
+
@@ -135,7 +137,7 @@
-
+
@@ -165,56 +167,87 @@
-
+
-
+
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -224,7 +257,7 @@
-
+
@@ -253,7 +286,7 @@
-
+
@@ -271,11 +304,11 @@
-
+
-
+
@@ -284,7 +317,7 @@
-
+
@@ -298,7 +331,7 @@
-
+
@@ -312,7 +345,7 @@
-
+
@@ -365,7 +398,7 @@
-
+
diff --git a/FPGA/VNA/VNA.xise b/FPGA/VNA/VNA.xise
index 23fe1cf..9864992 100644
--- a/FPGA/VNA/VNA.xise
+++ b/FPGA/VNA/VNA.xise
@@ -23,11 +23,11 @@
-
+
-
+
@@ -109,7 +109,7 @@
-
+
@@ -405,8 +405,8 @@
-
-
+
+
@@ -424,7 +424,7 @@
-
+
@@ -476,7 +476,7 @@
-
+
diff --git a/FPGA/VNA/top.bin b/FPGA/VNA/top.bin
index 5292ff7..c7fda7e 100644
Binary files a/FPGA/VNA/top.bin and b/FPGA/VNA/top.bin differ
diff --git a/FPGA/VNA/top.vhd b/FPGA/VNA/top.vhd
index ba5f8b1..70309ce 100644
--- a/FPGA/VNA/top.vhd
+++ b/FPGA/VNA/top.vhd
@@ -44,12 +44,12 @@ entity top is
TRIGGER_OUT : out STD_LOGIC;
PORT2_CONVSTART : out STD_LOGIC;
PORT2_SDO : in STD_LOGIC;
- PORT2_SCLK : out STD_LOGIC;
+ PORT2_SCLK : inout STD_LOGIC;
PORT2_MIX2_EN : out STD_LOGIC;
PORT2_MIX1_EN : out STD_LOGIC;
PORT1_CONVSTART : out STD_LOGIC;
PORT1_SDO : in STD_LOGIC;
- PORT1_SCLK : out STD_LOGIC;
+ PORT1_SCLK : inout STD_LOGIC;
PORT1_MIX2_EN : out STD_LOGIC;
PORT1_MIX1_EN : out STD_LOGIC;
LO1_MUX : in STD_LOGIC;
@@ -83,7 +83,7 @@ entity top is
SOURCE_CE : out STD_LOGIC;
REF_CONVSTART : out STD_LOGIC;
REF_SDO : in STD_LOGIC;
- REF_SCLK : out STD_LOGIC);
+ REF_SCLK : inout STD_LOGIC);
end top;
architecture Behavioral of top is
@@ -213,7 +213,7 @@ architecture Behavioral of top is
MAX : out STD_LOGIC_VECTOR (15 downto 0);
RESET_MINMAX : in STD_LOGIC;
CONVSTART : OUT std_logic;
- SCLK : OUT std_logic
+ SCLK : INOUT std_logic
);
END COMPONENT;
COMPONENT MAX2871