MDuse
New Contributor
6 years agoProgram not working as expected
Hi,
my device consists of MCU, MAX V CPLD and sensor device. MAX V CPLD is used to interface sensor to MCU.
I have a code in VHDL for MAX V CPLD:
entity Device is
port (
clk16: in std_logic; -- 16 MHz clock generated by MCU
start: inout std_logic; -- start pulse from MCU/operation complete from CPLD. This signal is normally high (pull up resistor). When MCU pulls it down, it tells CPLD to start reading data from sensor. CPLD pulls signal low during read. When it is finished CPLD stops pulling it low.
clk_out: buffer std_logic; -- output clock for sensor derived from clk16
start_pulse: out std_logic; -- start pulse for sensor (start command for sensor)
);
end Device;
architecture a of Device is
type T_STATE is (STOPPED, STARTING, ....another states....);
signal state: T_STATE := STOPPED;
begin
process (clk16)
begin
if rising_edge(clk16) then
clk_out <= not clk_out; -- create clk_out clock
end if;
if rising_edge(clk_out) then
case state is
when STOPPED =>
if start = '0' then
start_pulse <= '1';
state <= STARTING;
start <= '0' -- sometimes this doesn't happen
end if;
when STARTING =>
start_pulse <= '0';
-- code continues here....The problem is that sometimes line 28 is not "executed" - CPLD doesn't start pulling line low. However, state machine goes to the next state (STARTING) and start_pulse is set to 1 (and then to 0 when it is in STARTING state).
Can you please help me debug this code?
Thanks
Martin