Hello all, I designing an SPI interface between an FPGA and a audio reciever IC. In order for the information to be passed correctly, the data has to be transmitted exactly when the Word Clock (ILRCK_i) toggles. Thus far I have not been able to accomplish this, I lose 2 to 3 clock cycles before things start to transmit. I would be grateful for any help I could receive.
Data_out: process(RESET, ILRCK_i, ISCLK_i)
begin
ILRCK_o <= ILRCK_i;
ISCLK_o <= ISCLK_i;
if(RESET = '1')then
ILRCK_o <= '0';
ISCLK_o <= '0';
SD_out <= '0';
counter_l <= 0;
counter_r <= 0;
SD_L_tmp <= ZERO;
SD_R_tmp <= ZERO;
flag_R <= '0';
flag_L <= '0';
elsif(ISCLK_i'event and ISCLK_i = '1')then
counter_r <= counter_r + 1;
counter_l <= counter_l + 1;
case ILRCK_i is
when '0' =>
SD_out <= SD_R_tmp(max_val);
counter_L <= 0;
if(flag_R = '0')then
SD_R_tmp <= SD_R;
flag_R <= '1';
else
flag_L <= '0';
if(counter_r >= max_val+1)then
SD_R_tmp <= ZERO;
counter_r <= 0;
else
SD_R_tmp <= SD_R_tmp((max_val -1)downto) & '0';
end if;
end if;
when '1' =>
SD_out <= SD_L_tmp(max_val);
counter_r <= 0;
if(flag_L = '0')then
SD_L_tmp <= SD_L;
flag_L <= '1';
else
flag_R <= '0';
if (counter_l >= max_val + 1)then
SD_L_tmp <= ZERO;
counter_l <= 0;
else
SD_L_tmp <= SD_L_tmp((max_val -1) downto 0) & '0';
end if;
end if;
when others =>
counter_l <= 0;
counter_r <= 0;
end case;
end if;
end process;
Data_out: process(RESET, ILRCK_i, ISCLK_i)
begin
ILRCK_o <= ILRCK_i;
ISCLK_o <= ISCLK_i;
if(RESET = '1')then
ILRCK_o <= '0';
ISCLK_o <= '0';
SD_out <= '0';
counter_l <= 0;
counter_r <= 0;
SD_L_tmp <= ZERO;
SD_R_tmp <= ZERO;
flag_R <= '0';
flag_L <= '0';
elsif(ISCLK_i'event and ISCLK_i = '1')then
counter_r <= counter_r + 1;
counter_l <= counter_l + 1;
case ILRCK_i is
when '0' =>
SD_out <= SD_R_tmp(max_val);
counter_L <= 0;
if(flag_R = '0')then
SD_R_tmp <= SD_R;
flag_R <= '1';
else
flag_L <= '0';
if(counter_r >= max_val+1)then
SD_R_tmp <= ZERO;
counter_r <= 0;
else
SD_R_tmp <= SD_R_tmp((max_val -1)downto) & '0';
end if;
end if;
when '1' =>
SD_out <= SD_L_tmp(max_val);
counter_r <= 0;
if(flag_L = '0')then
SD_L_tmp <= SD_L;
flag_L <= '1';
else
flag_R <= '0';
if (counter_l >= max_val + 1)then
SD_L_tmp <= ZERO;
counter_l <= 0;
else
SD_L_tmp <= SD_L_tmp((max_val -1) downto 0) & '0';
end if;
end if;
when others =>
counter_l <= 0;
counter_r <= 0;
end case;
end if;
end process;