Forum Discussion
Altera_Forum
Honored Contributor
13 years agoU2 samples PI whenever CS is high and there is a rising edge on sys_clk. So PI is being sampled quite often, whenever the CS isn't active.
process(CLK, nRESET)
begin
if (nRESET = '0') then
tmp <= (others => '0');
elsif rising_edge(CLK) then
if CS_sync = '0' then
if SCK_falling = '1' then
tmp <= tmp(PI'high -1 downto PI'low) & '0';
end if;
elsif CS_sync = '1' then
tmp <= PI;
end if;
end if;
end process;
SO <= tmp(PI'high) when nCS = '0' else 'Z'; U1 will keep PO stable until and unless a new command is given and CS is rises. The command isn't executed until and unless CS goes back high. if (nRESET = '0') then
temp <= (others => '0');
shift_count := 0;
elsif rising_edge(CLK) then
if CS_rising = '1' then
case cmd is
when "00000001" =>
temp <= (others => '0');
temp(0) <= '1';
shift_count := 1;
when "00001111" =>
temp <= (others => '0');
shift_count := 0;
when "10101010" =>
temp <= temp(WIDTH - 2 downto 0) & '0';
shift_count := shift_count + 1;
when "11110000" =>
ACK <= '1';
when others =>
null;
end case;
shift_count_vector <= std_logic_vector(to_unsigned(shift_count,shift_count_vector'length));
elsif CS_falling = '1' then
ACK <= '0';
end if;
end if; What the MCU does is that it first sends the command "shiftVector" to U1. As soon as the transmission is done, the CS for U1 is brought high and the MCU begins lowering CS for U2 and starts receiving data. So the amount of cycles between when the vector is shifted and when data is received will depends on how fast the MCU is executing. This should be straight forward to measure, I have a 2-channel o-scope and I'll put channel 1 on the CS of U1 and channel 2 on CS of U2. The time we're interested in is between the rising edge of U1's CS and the falling edge of U2's CS. This should be sufficient enough that PI is sampled, right? So, basically, greater than 50 ns - at least 100 ns? The MCU, by the way, is working at 8 MHz. Thank you replying, by the way. I have nobody here to discuss it with and it really helps to go through about with someone who really knows what they're doing. :)