Hi,
I am generating a 127-bit PN code using the following code: I just want to generate a trigger signal after every 127-bit sequence. So, basically, i count the positive edges of the clock after the PN code starts and then after the counter reaches 127, i generate the trigger signal. NOW, MY QUESTION HAS NOTHING TO DO WITH THE PN CODE. It is quite a simple one. When i simulate at low frequency like 1MHz, everything is fine. When i try to simulate at 25Mhz, the counter messes up. The "count" variable in the code increments from 0 to 120 then goes back to 0 and starts incrementing again.
I have seen this before. When you try to increment an integer variable, it always messes up at high frequencies.does all kinds of stupid things while incrementing. like once...it incremented until 49 and then it read 17 after that, etc etc. Am i doing something wrong ? Can't the PLD just do a simple thing as incrementing an integer variable properly ? There should nothing be wrong with the logic because it works perfectly at 1Mhz.
Is there a better alternative to a problem where you need to wait until a condition is reached to perform an action.
The PLD i am downloading the code into is an altera device EPF10K70RC240-4. I am using the ALtera Maxplus II Baseline software.
The code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity onlypn is
port( clock,reset,enable : in std_logic;
output,trigger : out std_logic;
counter : out integer
);
end onlypn;
architecture behavioural of onlypn is
signal new_bit: std_logic;
signal internal_reg: std_logic_vector(127 downto 0);
signal internal_reg_next: std_logic_vector(127 downto 0);
begin
code_gen: process(clock,reset,internal_reg,new_bit,enable)
variable count: integer;
begin
counter <= count;
new_bit <= internal_reg(6) xor internal_reg(5);
output <= internal_reg(0);
internal_reg_next <= internal_reg(126 downto 0) & new_bit;
if (reset = '1') then
internal_reg <= (3 => '1', OTHERS => '0');
elsif (clock'EVENT AND clock ='1') then
if(enable = '1') then
internal_reg <= internal_reg_next;
count := count +1;
if (count = 127) then
count := 0;
trigger <= '1';
else trigger <= '0';
end if;
end if;
end if;
end process;
end behavioural;
Thank you
I am generating a 127-bit PN code using the following code: I just want to generate a trigger signal after every 127-bit sequence. So, basically, i count the positive edges of the clock after the PN code starts and then after the counter reaches 127, i generate the trigger signal. NOW, MY QUESTION HAS NOTHING TO DO WITH THE PN CODE. It is quite a simple one. When i simulate at low frequency like 1MHz, everything is fine. When i try to simulate at 25Mhz, the counter messes up. The "count" variable in the code increments from 0 to 120 then goes back to 0 and starts incrementing again.
I have seen this before. When you try to increment an integer variable, it always messes up at high frequencies.does all kinds of stupid things while incrementing. like once...it incremented until 49 and then it read 17 after that, etc etc. Am i doing something wrong ? Can't the PLD just do a simple thing as incrementing an integer variable properly ? There should nothing be wrong with the logic because it works perfectly at 1Mhz.
Is there a better alternative to a problem where you need to wait until a condition is reached to perform an action.
The PLD i am downloading the code into is an altera device EPF10K70RC240-4. I am using the ALtera Maxplus II Baseline software.
The code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity onlypn is
port( clock,reset,enable : in std_logic;
output,trigger : out std_logic;
counter : out integer
);
end onlypn;
architecture behavioural of onlypn is
signal new_bit: std_logic;
signal internal_reg: std_logic_vector(127 downto 0);
signal internal_reg_next: std_logic_vector(127 downto 0);
begin
code_gen: process(clock,reset,internal_reg,new_bit,enable)
variable count: integer;
begin
counter <= count;
new_bit <= internal_reg(6) xor internal_reg(5);
output <= internal_reg(0);
internal_reg_next <= internal_reg(126 downto 0) & new_bit;
if (reset = '1') then
internal_reg <= (3 => '1', OTHERS => '0');
elsif (clock'EVENT AND clock ='1') then
if(enable = '1') then
internal_reg <= internal_reg_next;
count := count +1;
if (count = 127) then
count := 0;
trigger <= '1';
else trigger <= '0';
end if;
end if;
end if;
end process;
end behavioural;
Thank you