Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17255 Discussions

Trouble compiling my JK flip flop VHDL code!? "Syntax Error"

Altera_Forum
Honored Contributor II
3,266 Views

--The below code doesn't compile. I am given the following errors. Could someone help me troubleshoot this.  

 

--ERRORS: 

 

Error (10500): VHDL syntax error at lab4_jke.vhd(14) near text "if"; expecting "end", or "(", or an identifier ("if" is a reserved keyword), or a concurrent statement 

Error (10500): VHDL syntax error at lab4_jke.vhd(14) near text "then"; expecting "<=" 

Error (10500): VHDL syntax error at lab4_jke.vhd(15) near text "then"; expecting "<=" 

Error (10500): VHDL syntax error at lab4_jke.vhd(17) near text "elsif"; expecting "end", or "(", or an identifier ("elsif" is a reserved keyword), or a concurrent statement 

Error (10500): VHDL syntax error at lab4_jke.vhd(17) near text "then"; expecting "<=" 

Error (10500): VHDL syntax error at lab4_jke.vhd(19) near text "elsif"; expecting "end", or "(", or an identifier ("elsif" is a reserved keyword), or a concurrent statement 

Error (10500): VHDL syntax error at lab4_jke.vhd(19) near text "then"; expecting "<=" 

Error (10500): VHDL syntax error at lab4_jke.vhd(21) near text "elsif"; expecting "end", or "(", or an identifier ("elsif" is a reserved keyword), or a concurrent statement 

Error (10500): VHDL syntax error at lab4_jke.vhd(21) near text "then"; expecting "<=" 

Error (10500): VHDL syntax error at lab4_jke.vhd(23) near text "if"; expecting ";", or an identifier ("if" is a reserved keyword), or "architecture" 

 

 

 

 

 

 

--CODE: 

 

 

LIBRARY IEEE; 

USE IEEE.STD_LOGIC_1164.ALL; 

USE IEEE.STD_LOGIC_ARITH.ALL; 

USE IEEE.STD_LOGIC_UNSIGNED.ALL; 

 

 

ENTITY lab4_jke IS 

PORT( 

S,R,J,K,CLK : IN STD_LOGIC; 

Q : OUT STD_LOGIC; 

NQ : OUT STD_LOGIC); 

END lab4_jke; 

ARCHITECTURE behavior OF lab4_jke IS 

BEGIN 

if (CLK'EVENT AND CLK='1') then 

if (J='0' AND K='0') then 

Q <= Q; 

elsif (J='1' AND K='0') then 

Q <= '1'; 

elsif (J='0' AND K='1') then 

Q <= '0'; 

elsif (J='1' AND K='1') then 

Q <= NOT(Q); 

END if; 

END if; 

END behavior;
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
2,316 Views

LIBRARY IEEE; 

USE IEEE.STD_LOGIC_1164.ALL; 

 

 

ENTITY lab4_jke IS 

PORT( 

S,R,J,K,CLK : IN STD_LOGIC; 

Q : OUT STD_LOGIC; 

NQ : OUT STD_LOGIC); 

END lab4_jke; 

 

ARCHITECTURE behavior OF lab4_jke IS 

BEGIN 

process(clk) 

begin 

if (CLK'EVENT AND CLK='1') then 

if (J='0' AND K='0') then 

Q <= Q; 

elsif (J='1' AND K='0') then 

Q <= '1'; 

elsif (J='0' AND K='1') then 

Q <= '0'; 

elsif (J='1' AND K='1') then 

Q <= NOT(Q); 

END if; 

END if; 

end process; 

END behavior;
0 Kudos
Altera_Forum
Honored Contributor II
2,316 Views

How can I incorporate the functionality of S "Set" and R "Reset" into my code?

0 Kudos
Altera_Forum
Honored Contributor II
2,316 Views

A JK flip-flop doesn't have Set and Reset inputs. may be you want a preset and clear asynchronous inputs. In a FPGA you do that with a single asynchronous reset: 

 

process(clr, clk) 

begin 

if( clr = '1' ) then 

q_reg <= '0'; 

elsif( clk'event and clk = '1' ) then 

q_reg <= q_next; 

end if; 

end process; 

 

q_next <= '0' when ( j = '0' and k = '1' ) else ....etc
0 Kudos
Reply