Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

VHDL SPI code testbench ok but no syntheiszable

Status
Not open for further replies.

SOMANDAL88

Newbie level 2
Joined
Nov 8, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
I am trying to build a SPI interface using VHDL. The testbench is ok. But it is not synthesizable on Spartan 6. Could anyone please figure out the problem.


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
LIBRARY IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity L6470_SPI_MASTER is
port(clk: in std_logic;
    sdo_master: out std_logic;
    ck_master: out std_logic;
    cs_bar: out std_logic);
end L6470_SPI_MASTER;
architecture arch of L6470_SPI_MASTER is
signal temp: integer range 0 to 9;
signal reg_array: std_logic_vector(7 downto 0);
begin
process (clk)
variable count: integer range 0 to 10:=0;
begin
if (rising_edge(clk)) then
count :=count+1;
end if;
if (count=10) then
count:=0;
end if;
temp<=count;
end process;
process(temp)
begin
case temp is
when 0 => cs_bar <= '1'; 
when 1 => cs_bar <= '0';
when 2 => cs_bar <= '0';
when 3 => cs_bar <= '0';
when 4 => cs_bar <= '0';
when 5 => cs_bar <= '0';
when 6 => cs_bar <= '0';
when 7 => cs_bar <= '0';
when 8 => cs_bar <= '0';
when 9 => cs_bar <= '0';
end case;
end process;
process (clk)
variable piso_reg: std_logic_vector (7 downto 0):= "11001010";
begin
if (rising_edge(clk) and temp=0) then
reg_array(7 downto 0)<=piso_reg(7 downto 0);
elsif (rising_edge(clk)) then
sdo_master<=reg_array(7);
reg_array(7 downto 1)<= reg_array(6 downto 0);
reg_array(0)<='0';
end if;
end process;
ck_master <= not(clk);
end arch;

 
Last edited by a moderator:

TrickyDicky

Advanced Member level 5
Joined
Jun 7, 2010
Messages
7,045
Helped
2,069
Reputation
4,155
Reaction score
2,023
Trophy points
1,393
Activity points
38,827
you shouldnt have code outside the clocked part of the process unless it is an async reset. The async reset should have priority over the clock.
 

lucbra

Advanced Member level 2
Joined
Oct 30, 2003
Messages
514
Helped
73
Reputation
146
Reaction score
63
Trophy points
1,308
Location
Belgium
Activity points
3,251
Do you mean that you want to synthesize a testbench to fit in a Spartan6? By definition a testbench is meant to fit in a device but runs on a simulator (like Modelsim, Active HDL, ...)
 

SOMANDAL88

Newbie level 2
Joined
Nov 8, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
To lucbra
No, I mean to say that the testbench runs well in VHDL Testbench file in PC. But I was unable to synthesize the code on FPGA.
Actually, I have a L6470 IC which drives high current stepper motor (upto 7 A Vpeak). It works on SPI based commands. I was unable to run it by the code which I presented due to the fact that it was not synthesizable on FPGA Spartan 6. If you have some alternative please suggest like in previous post trickydicky suggested one. Unfortunately it didnt work.
 

lucbra

Advanced Member level 2
Joined
Oct 30, 2003
Messages
514
Helped
73
Reputation
146
Reaction score
63
Trophy points
1,308
Location
Belgium
Activity points
3,251
Tricky referred to the process starting at line 15
the part where count is checked for a value of 10 should be in the rising_edge part of the process
so something like:


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
process (clk, reset)
variable count natural range 0 to 10 := 0;
begin
   if reset = '1' then
      temp <= 0;
   elsif rising_edge(clk)
      if count = 10 then
         count := 0;
      else
         count := count + 1;
      end if;
      temp <= count;
   end if;
end process



second, what's the clock frequency of your SPI_Master module?
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top