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.

std_logic_vector to integer in VHDL

Status
Not open for further replies.

dumindu89

Member level 1
Joined
Feb 26, 2012
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,585
Hello I am trying to convert a std_logic_vector to integer. Here is how I did the std_logic_vector to integer conversion.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity programmable_divider is
port( clk : in std_logic;
clk_out : out std_logic;
divide_value : in std_logic_vector (9 downto 0)
);
end programmable_divider;

architecture Behavioral of programmable_divider is
signal counter,programmable_divide: integer := 0;
begin
programmable_divide <= to_integer(unsigned(divide_value(9 downto 0)));

But this didn't gave the correct output when I enter 4 as binary (0000000100) in the simulation via Quartus II 7.2 (The device is : MAX II EPM240T100C5). I mean the divider should divide the clk by 4.
Instead of that I observed around divide by 5 or 6.

Please help me to solve this case.
 

Can you confirm what is the exact output result you have observed ?
 

I think the error is probably due to the implementation of the counter/divider rather than the conversion.
 

Here is the full 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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
 
entity programmable_divider is
port( clk : in std_logic;
clk_out : out std_logic;
divide_value : in std_logic_vector (9 downto 0)
);
end divider;
 
architecture Behavioral of divider is
 
signal counter,programmable_divide : integer := 0;
 
begin
 
programmable_divide <= to_integer(unsigned(divide_value(9 downto 0)));
 
process(clk)
begin
if( rising_edge(clk) ) then
if(counter < programmable_divide/2-1) then
counter <= counter + 1;
clk_out <= '0';
elsif(counter < programmable_divide-1) then
counter <= counter + 1;
clk_out <= '1';
else
clk_out <= '0';
counter <= 0;
end if;
end if;
end process; 
 
end Behavioral;



If there is no errors in the code may I program the CPLD and check the result? Because few my friends told that though they get these type of simulation resulrts they were able to get the correct outputs in real implementation without errors.
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top