Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Clock problem

Hi All,

I am trying to reduce the clock frequency from 25 MHZ to 12.5 MHZ using VHDL. I also intend to implement this in hardware, however I am having a lot of difficulty with my code. I can not assign a new clock frequency to an output variable which I wanted to assign to an output pin.

I am getting the following error for my code which is shown below:

Error (10517): VHDL type mismatch error at clock.vhd(23): std_logic_vector type does not match integer literal

My Code:

-- Divide clock frequency by 2

-- Standard libary delarations

library ieee;

use ieee.std_logic_1164.all;

-- define input and outputs for the entity

entity clock is port(

clk_in: in std_logic;

clk_out: buffer std_logic;

va: buffer std_logic_vector(2 downto 0) );

end clock;

-- internal function of enetity

architecture behave of clock is

--internal variable

signal count : integer :=1;

begin

process (clk_in,clk_out,va)

begin

-- Required in order to convert the sinewave to a square wave

clk_out <= not clk_in;

-- Check for rising edge of clock

if(clk_out'event and clk_out='1') then

--increment the count variable by 1

count <=count+1;

-- when count is 2

if(count = 2) then

--assign 1 to the variable which will be assigned to an output pin

va <= 1;

end if;

end if;

end process;

end behave;

Thank you in advance.

12 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Gated clocks are bad.

    but anyway, what's the point of using signal va as std_logic_vector? You're assigning one bit value to 3bit bus. Also the code logically won't work, since You don't reset the counter.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I can't understand what you are trying to do.

    From your first sentence I assumed you want clk_out to be half the frequency of clk_in.

    This can be done with simple code, like this:

    if(clk_in'event and clk_in='1') then

    clk_out <= not clk_out;

    end if;

    Regarding the error. that's normal if you write va <= 1

    You defined va as a std_logic vector 3 bits long, so you must use va <= "000"

    Anyway, your code seems to be useless since va is not initialized to any other value

    and assigned only to 1 when count is 2.

    I'd expect at least a reset signal, in order to reset count and va to initial status.