I've been wanting to learn how to use FPGAs so I recently got a MachXO2 breakout board. I read up a bit on VHDL and decided to make an 8 bit counter to drive the LEDs on the board.
The code runs fine in the simulator and gives the expected results, but once I got it to synthesize and uploaded the code to the board it didn't work. All the LEDs stay lit, but I suspected they were just running at a very high frequency so I took some readings.
The LEDs were switching between 1.1MHz and 1.8MHz but not in any order - most around 1.5MHz. I also mapped the CLK port to one of the pins and it read ~1.7MHz (should be ~ 3 Hz). I'm not confident that these numbers are accurate other than they are far higher than they should be.
It is quite possible I might have missed a step somewhere - although I think I've got the hang of the Diamond IDE.
Or maybe I messed up the VHDL in a way that won't show up in the simulation?
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
library machxo2;
use machxo2.all;
entity COUNT is
port( CLK : inout bit;
CNT : buffer std_logic_vector (7 downto 0) := "00000000");
end COUNT;
library IEEE;
use IEEE.std_logic_1164.all;
entity Clk_gen is
port(CLKsig : inout bit);
end;
architecture Clk_behv of Clk_gen is
signal tick : std_logic;
component OSCH is
generic( nom_freq: string);
port( STDBY : in std_logic;
OSC : out std_logic);
end component;
begin
Inst0: OSCH generic map (nom_freq => "3.02")
port map ('0', tick);
process(tick)
variable counter: integer Range 0 to 500000;
begin
if (tick = '1') then
if (counter< 500000) then
counter := counter + 1;
else
counter := 0;
CLKsig <= not CLKsig;
end if;
end if;
end process;
end Clk_behv;
architecture Count_behv of COUNT is
component Clk_gen is
port( CLKsig : inout bit);
end component;
begin
inst1:Clk_gen port map (CLK);
process(CLK)
begin
if(CLK = '1') then
if (CNT = "11111111") then
CNT <= (others => '0');
else
CNT <= CNT + "1";
end if;
end if;
end process;
end Count_behv;
THe vector CNT drives the LEDs. Any help is appreciated.