Hi all, I am new here. I tell you my problem. I have been now several days trying to figure it out how to control shift registers SIPO 74LS164 with my FPGA. I am doing a clock, displaying hours, minutes and seconds with NIXIE tubes. What I need to do is to send each second, 24 bits, and remain those 24 bits displaying in the NIXIE tubes during the second, till the new second comes and new 24 bits are sent. Maybe this is a stupid question but I don't know how to produce my clock signal and my serial output to control this ICs. I already have a vector of 24 bits and the schematic of how cascading these ICs so that's not the problem. I think you get which my problem is. Please if somebody can help me would be so so great! Thank you very much Regards
Hi, what HDL do you use? In Verilog I would try something like this (prob. with errors and not a good style)
1 | module( start, stop, secminhour, clk, clkout, dataout); |
2 | |
3 | input start, secminhour, clk; |
4 | output dataout, clkout; |
5 | |
6 | reg stop = 1'b1; |
7 | reg[0:3] cnt = 4'b0000; |
8 | |
9 | wire[0:23] secminhour = 24'b0; |
10 | wire start; |
11 | wire clk; |
12 | wire clkout; |
13 | wire dataout; |
14 | |
15 | assign dataout = secminhour[cnt]; |
16 | assign clkout = (stop == 1'b0) ? clk : 0; |
17 | |
18 | always @(posedge clk) begin |
19 | |
20 | if (start = 1'b0) begin |
21 | cnt <= 4'b0000; |
22 | stop <= 1'b0; |
23 | end else begin |
24 | cnt <= cnt + 1; |
25 | if (cnt >= 23) begin |
26 | cnt <= 4'b0000; |
27 | stop <= 1'b1; |
28 | end |
29 | end |
30 | |
31 | end |
32 | |
33 | endmodule |
U also need a StateMachine to controll this, something like generate Data, set start from low to high, wait till stop is set (and the Data output was generated) and set start low.
Hi, thank you for your answer, I use VHDL, have never used Verilog. I didn't think about doing it with a StateMachine, maybe that solve my problem, I'll focus the problem from this point of view. Really, thank you. Regards
Joserra wrote: > I didn't think about doing it with a StateMachine, maybe that solve my > problem Just keep in mind: even every lousy little conter is a State Machine... Joserra wrote: > I don't know how to produce my clock signal and my serial output to > control this ICs. Its fairly easy, because no framing is needed for this shift registers. So the only thing you must provide is a shift "clock" and stable data on the rising edge of this clock...
1 | library IEEE; |
2 | use IEEE.STD_LOGIC_1164.ALL; |
3 | use IEEE.NUMERIC_STD.ALL; |
4 | |
5 | |
6 | entity SPI_Master is -- SPI-Modus 0: CPOL=0, CPHA=0 |
7 | Port ( TX_Data : in STD_LOGIC_VECTOR (Length-1 downto 0); -- Sendedaten |
8 | MOSI : out STD_LOGIC; |
9 | SCLK : out STD_LOGIC; |
10 | TX_Start : in STD_LOGIC; |
11 | TX_Active : out STD_LOGIC; |
12 | clk : in STD_LOGIC |
13 | );
|
14 | end SPI_Master; |
15 | |
16 | architecture Behavioral of SPI_Master is |
17 | type tx_states is (idle,txactive); |
18 | signal txstate : tx_states := idle; |
19 | |
20 | signal spiclk : std_logic; |
21 | signal spiclklast: std_logic; |
22 | |
23 | signal bitcounter : integer range 0 to Length; -- if bitcounter = Length --> all bits transmitted |
24 | signal tx_reg : std_logic_vector(Length-1 downto 0) := (others=>'0'); |
25 | |
26 | begin
|
27 | ------ management FSM --------
|
28 | process begin |
29 | wait until rising_edge(CLK); |
30 | spiclklast <= spiclk; |
31 | case txstate is |
32 | when idle => |
33 | TX_Active <= '0'; |
34 | bitcounter <= Length; |
35 | sclk <= '0'; |
36 | if(TX_Start = '1') then |
37 | stxstate <= txactive; |
38 | TX_Active <= '1'; |
39 | end if; |
40 | |
41 | when txactive => -- transmit tx_reg |
42 | spiclk <= not spiclk; |
43 | if (bitcounter=0) then -- all bits transmitted -> idle |
44 | spiclk <= '0'; |
45 | txstate <= idle; |
46 | end if; |
47 | if(spiclk='1') then |
48 | bitcounter <= bitcounter-1; |
49 | end if; |
50 | end case; |
51 | end process; |
52 | |
53 | ---- TX Shiftregister -------
|
54 | process begin |
55 | wait until rising_edge(CLK); |
56 | if (spitxstate=idle) then -- reload when idle |
57 | tx_reg <= TX_Data; |
58 | end if; |
59 | if (spiclk='1' and spiclklast='0') then -- rising_edge --> assign next data bit |
60 | tx_reg <= tx_reg(tx_reg'left-1 downto 0) & tx_reg(0); |
61 | end if; |
62 | end process; |
63 | |
64 | SCLK <= spiclk; |
65 | MOSI <= tx_reg(tx_reg'left); |
66 | |
67 | end Behavioral; |
(Based on the SPI-Master: http://www.lothar-miller.de/s9y/categories/45-SPI-Master)
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.