Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

One cycle delay vhdl

Status
Not open for further replies.

needhelp123

Newbie level 5
Joined
Aug 7, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
65
In need of help, I have a program here which I need to submit next week. I just need to add in 1 cycle clock delay but I have no idea how.
This is my code


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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;
 
ENTITY fpga is
port(
    data_clk: in std_logic;
    data_out: out std_logic;
    data_in: in std_logic;
    osc: in std_logic;
    rst: in std_logic;
    LED: out std_logic
    );
END fpga;
 
ARCHITECTURE behaviour of fpga is 
signal counter: integer range 0 to 7;
signal data: std_logic;
signal output2: std_logic_vector(7 downto 0);
signal receiving: std_logic_vector(7 downto 0); 
begin
    
    process(osc,rst)    
        begin 
                if(rst = '0') then          -- reset button pressed
                counter <= 0;               -- counter will show 0
                output2 <= "01000110";      -- output2 still running
                LED <= '1';                 -- LED will not light up
                data_out <= '0';
                
            elsif (rising_edge(osc)) then   
                receiving <= receiving(6 downto 0) & data_in;   --shifts the bottom seven bits of receiving left by one
                                                                --puts the new data bit from the data_in to bit 0 of dat_reg
            
            
                if (data_in = data_out) then                    -- compare data_in & data_out
                    LED <= '0';
                else
                    LED <= '1';
                end if;
 
                    if(counter < 7) then
                        counter <= counter + 1;
                    else
                        counter <= 0;
                    end if;
                    
                    case counter is             -- Transmitter
                        when 0 =>
                            data_out <= output2(0);
                        when 1 =>
                            data_out <= output2(1);
                        when 2 =>
                            data_out <= output2(2);
                        when 3 =>
                            data_out <= output2(3);
                        when 4 => 
                            data_out <= output2(4);
                        when 5 => 
                            data_out <= output2(5);
                        when 6 =>
                            data_out <= output2(6);
                        when 7 =>
                            data_out <= output2(7);
                        when others => 
                            data_out <= '0';    
                    
                    end case;                   
            end if;
    end process;
end behaviour;

 
Last edited by a moderator:

suppose you want to delay a signal named temp, then you can do it like this:

Code:
if(rising_edge(clk)) then
   temp_delay <= temp;
end if;
 

They state that it is a Misspelled variable, signal or procedure name?. Do I have to declare any signal?
 

yes. Think about what circuit you are describing - each register needs a separate name.
 

I modified your code but didnt test it coz I dont have a simulator.
Please tell me what you get with this code.


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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;
 
ENTITY fpga is
port(
data_clk: in std_logic;
data_out: out std_logic;
data_in: in std_logic;
osc: in std_logic;
rst: in std_logic;
LED: out std_logic
);
END fpga;
 
ARCHITECTURE behaviour of fpga is
signal counter: integer range 0 to 7;
signal data: std_logic;
signal output2: std_logic_vector(7 downto 0);
signal receiving: std_logic_vector(7 downto 0);
begin
 
process(osc,rst)
variable tmp: std_logic;                            -- <----------------------------Variable used in the process
begin
 
 
tmp:=data                                           -- <----------------------------Output result 
data_out<=tmp
if(rst = '0') then -- reset button pressed
counter <= 0; -- counter will show 0
output2 <= "01000110"; -- output2 still running
LED <= '1'; -- LED will not light up
data_out <= '0';
 
elsif (rising_edge(osc)) then
receiving <= receiving(6 downto 0) & data_in; --shifts the bottom seven bits of receiving left by one
--puts the new data bit from the data_in to bit 0 of dat_reg
 
 
if (data_in = data_out) then -- compare data_in & data_out
LED <= '0';
else
LED <= '1';
end if;
 
if(counter < 7) then
counter <= counter + 1;
else
counter <= 0;
end if;
 
case counter is                                              --     <---------------------------Memorise the result
when 0 =>
data <= output2(0);
when 1 =>
data <= output2(1);
when 2 =>
data <= output2(2);
when 3 =>
data <= output2(3);
when 4 =>
data <= output2(4);
when 5 =>
data <= output2(5);
when 6 =>
data <= output2(6);
when 7 =>
data <= output2(7);
when others =>
data_out <= '0';
 
 
end case;
end if;
end process;
end behaviour;

 
Last edited by a moderator:

Apart from the syntax errors, that makes no difference to the code, as you put the variable assignment before the output signal assignment. Hence it just makes a wire. Plus its not even in the clock branch.
Terrible example AdvaRes
 

@TrickyDicky,
The output signal assimement can be as indicated in the code or like you mentioned in the clock branch. Another mistake in declaring the variable, it should be before the begin. I corrected it.
I have no simulator to verify it. I gave just the idea.
 
Last edited:

It will not work the way you wrote it. It will NOT add an extra pipeline delay. It is very poorly written code.
 

@TrickyDicky
With all my respect Sir, we dont need a troll to comment our posts in this forum.
If you are cleaver answer the question.


@needhelp123
Please try this one and let me know.


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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;
 
ENTITY fpga is
port(
data_clk: in std_logic;
data_out: out std_logic;
data_in: in std_logic;
osc: in std_logic;
rst: in std_logic;
LED: out std_logic
);
END fpga;
 
ARCHITECTURE behaviour of fpga is
signal counter: integer range 0 to 7;
signal data: std_logic;
signal output2: std_logic_vector(7 downto 0);
signal receiving: std_logic_vector(7 downto 0);
begin
 
process(osc,rst)
begin
if(rst = '0') then -- reset button pressed
counter <= 0; -- counter will show 0
output2 <= "01000110"; -- output2 still running
LED <= '1'; -- LED will not light up
data_out <= '0';
 
elsif (rising_edge(osc)) then
receiving <= receiving(6 downto 0) & data_in; --shifts the bottom seven bits of receiving left by one
--puts the new data bit from the data_in to bit 0 of dat_reg
 
 
if (data_in = data_out) then -- compare data_in & data_out
LED <= '0';
else
LED <= '1';
end if;
 
if(counter < 7) then
counter <= counter + 1;
else
counter <= 0;
end if;
 
case counter is -- Transmitter
when 0 =>
data <= output2(0);
when 1 =>
data <= output2(1);
when 2 =>
data <= output2(2);
when 3 =>
data <= output2(3);
when 4 =>
datat <= output2(4);
when 5 =>
data <= output2(5);
when 6 =>
data <= output2(6);
when 7 =>
data <= output2(7);
when others =>
data <= '0';
 
end case;
 
data_out<=data
 
end if;
end process;
end behaviour;

 
Last edited by a moderator:

I still couldn't get the one clock cycle delay. It makes no difference from the code I've given, the LED will still light up even though I didn't connect the wires. It should only light up when I short the pins

- - - Updated - - -

on which signal u want one cycle dealy...?

I need 1 cycle delay on the dataout
 

@needhelp123
plz check i hav added delay in data_out.... by making some miner chenges....


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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
 
ENTITY fpga is
port(
data_clk: in std_logic;
data_out: inout std_logic;
data_in: in std_logic;
osc: in std_logic;
rst: in std_logic;
LED: out std_logic
);
END fpga;
 
ARCHITECTURE behaviour of fpga is
signal counter: integer range 0 to 7;
signal data: std_logic;
signal output2: std_logic_vector(7 downto 0);
signal receiving: std_logic_vector(7 downto 0);
signal add_delay: std_logic; 
begin
 
process(osc,rst)
begin
if(rst = '0') then -- reset button pressed
counter <= 0; -- counter will show 0
output2 <= "01000110"; -- output2 still running
LED <= '1'; -- LED will not light up
 
receiving<= X"00";
data<='0';
 add_delay<='0';
elsif (rising_edge(osc)) then
receiving <= receiving(6 downto 0) & data_in; --shifts the bottom seven bits of receiving left by one
--puts the new data bit from the data_in to bit 0 of dat_reg
 
 
if (data_in = data_out) then -- compare data_in & data_out
LED <= '0';
else
LED <= '1';
end if;
 
if(counter < 7) then
counter <= counter + 1;
else
counter <= 0;
end if;
 
case counter is -- Transmitter
when 0 =>
data <= output2(0);
when 1 =>
data <= output2(1);
when 2 =>
data <= output2(2);
when 3 =>
data <= output2(3);
when 4 =>
data <= output2(4);
when 5 =>
data <= output2(5);
when 6 =>
data <= output2(6);
when 7 =>
data <= output2(7);
when others =>
data <= '0';
 
end case;
 add_delay<= data;
end if;
 
end process;
--data_out<=add_dealy;
 
process(osc,rst)
  begin
     if rst='0' then
        data_out<='0';
       
     elsif (rising_edge(osc)) then
        --add_delay<= data;
        data_out<= add_delay;
    end if;
  end process;
 
end behaviour;

 
Last edited by a moderator:

The LED still doesn't turn off when I did not short the 2 ports. It should be offed, and the LED will only light up when the 2 ports are short together
 

waveform.png

check this simulation
 
Then how can I make receiving the same as output2 ?
 

give that output2 to respective receving signal thats all......
receiving<= output2;
 

Is it possible to not make data_in always '1' ?
 

sure...y not...
but in ur code its input so we dnt hav controll on it...
if u wnt to use it as always '1' then make it internal signal ans during initialisation itself assign it to '1' and remove that data_in input from entity.....thats all...
 

However in the simulation you gave, 'data_in' is always '1'. Is there another way to make receiving = output2 without internal altering of the code as I have to do it externally via output and input pins?
 

in simulation i hav taken it '1' it dosent mean it should be always '1'.... its not in our control u can take it '0' and test it see the results.....wether its according to ur requirments of funtionality.....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top