0

line 62: Signal s cannot be synthesized, bad synchronous description. The description style you are using to describe a synchronous element (register, memory, etc.) is not supported in the current software release.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity clock is
    Port ( start : in  STD_LOGIC;                       
           reset : in  STD_LOGIC;                       
           CLOCK : in  STD_LOGIC;                       
           setH, setM, setS : in  STD_LOGIC;            
           alarmH, alarmM, alarmS : in  STD_LOGIC; 
           Alarm_On : in  STD_LOGIC;                    
           Buzzer_Stop : in  STD_LOGIC;                 
           BUZZER : out STD_LOGIC;                      
           hh, mm, ss : out INTEGER);                   
end clock;

architecture Behavioral of clock is

signal h, m, s : INTEGER range 0 to 60 := 0;
signal hA, mA, sA : INTEGER range 0 to 60 := 0;
signal clk : std_logic :='0';
signal count : integer :=1;

begin

Frequency_Reducer : process(CLOCK)  --Reducing Frequency From 40MHz to 1Hz
begin
    if rising_edge(CLOCK) then
            count <= count + 1;
        if(count = 20000000) then
            clk <= not clk;
            count <=1;
        end if;
    end if;
end process;

Clock_Logic : process(start, reset, clk)
begin
    if reset = '1' then  
        h <= 00;
        m <= 00;
        s <= 0;
    end if;

    if start = '1' then   
        if rising_edge(clk) then        --Clock Logic Start
            s <= s + 1; 
        end if;
    end if;

        if s = 60 then
            s <= 0;
            m <= m + 1;
        end if; 
        if m = 60 then 
            m <= 0;
            h <= h + 1;
        end if; 
        if h = 24 then
            h <= 0;
        end if;                             --Clock Logic End

    if setH = '1' then                  --Set Time Logic Start
        h <= h + 1;
    end if;
    if setM = '1' then
        m <= m + 1;
    end if;
    if setS = '1' then
        s <= s + 1;
    end if;                                 -- Set Time Logic End
end process;

hh <= h;
mm <= m;
ss <= s;

end Behavioral;
Martin Zabel
  • 3,589
  • 3
  • 19
  • 34
  • 1
    Not all your assignments to `s` are synchronous to the rising edge of the clock. And your code is also not a description of a latch. Please check the manual of your synthesis tool on the supported styles of registers. It seems that all assignments below the reset should be synchronous to the rising edge of the clock. – Martin Zabel Mar 10 '16 at 09:04
  • @MartinZabel I tried it, it didn't solve the problem – Harsh Vira Mar 10 '16 at 09:34
  • With a one second clock you can't set the seconds while the clock is running, it would require a load. You could consider using a register for seconds, minutes and hours loaded from the clock and incremented by a buttons, reloaded into the clock when done (a set mode). An extra register can be used for an alarm, too. Or you could simply reset the seconds and increment the minutes and hours as in [vhdl manual clock hour set](https://stackoverflow.com/questions/27207698/vhdl-manual-clock-hour-set). Check out the answer, it shows everything clocked and is synthesis eligible. –  Mar 10 '16 at 18:04

1 Answers1

3

Let's take a look at the assignments of signal s only:

Clock_Logic : process(start, reset, clk)
begin
    if reset = '1' then  
        s <= 0;
    end if;

    if start = '1' then   
        if rising_edge(clk) then        --Clock Logic Start
            s <= s + 1; 
        end if;
    end if;

    if s = 60 then
        s <= 0;
    end if; 

    if setS = '1' then
        s <= s + 1;
    end if;                                 -- Set Time Logic End
end process;

In the last assignment, you are requesting that s is incremented when setS is high and the process is executed (resumed). The process is executed initially after system startup and every time when one of the signals in the sensitivity list changes. Thus, you are requesting flipf-flops clocked on both edges of three signals start, reset and clock. I suspect, that this increment should be done only on the rising edge of the clock:

    if rising_edge(clk) then        --Clock Logic Start
        if setS = '1' then
            s <= s + 1;
        end if;                                 -- Set Time Logic End
    end if;

The asynchronous reset of s when s reaches 60 is possible, but error prone due to glitches. s is is multi-bit signal in hardware. Thus, when it is incremented it could be equal to 60 for short moments in time even when the final value is below 60! You should reset it synchronously to 0, when current value is 59.

The increment of s when start is high and a rising-edge on the clock occur is ok, but synthesis tool often request to re-arrange this so that the outer if block checks for the rising edge:

    if rising_edge(clk) then        --Clock Logic Start
        if start = '1' then   
            s <= s + 1; 
        end if;
    end if;

Finally, the asynchronous reset (or set) inputs on flip-flops have always a higher priority then the synchronous data inputs. Thus, you must arrange it either this way:

Clock_Logic : process(reset, clk)
begin
    if reset = '1' then
        -- asynchronous part
        s <= 0;
    elsif rising_edge(clk) then
        -- synchronous part (add more conditions if required)
        s <= s + 1;
    end if;
end process;

or this way:

Clock_Logic : process(reset, clk)
begin
    if rising_edge(clk) then
        -- synchronous part (add more conditions if required)
        s <= s + 1;
    end if;
    if reset = '1' then
        -- asynchronous part
        s <= 0;
    end if;
end process;

The synchronous assignments can be more complex. For example, if you want to synchronously reset a counter when it reaches 59 and to increment it otherwise when the signal setS is high:

Clock_Logic : process(reset, clk)
begin
    if reset = '1' then
        -- asynchronous part
        s <= 0;
    elsif rising_edge(clk) then
        -- synchronous part
        if s = 59 then
            s <= 0;
        elsif setS = '1' then
            s <= s + 1;
        end if;
    end if;
end process;
Martin Zabel
  • 3,589
  • 3
  • 19
  • 34