Hi all,
At the moment am programming my first VHDL program within 'ise project
navigator' from xilinx. (using the coolrunner 2 board from digilent)
I am trying to generate an TTL encoder signal like this:
http://www.a-m-c.com/products/img/incremental-encoder.jpg
I have an kflop encoder card which counts this pulses.
The idea for my test:
1. A push button add 100 to an counter.
2. Every X microsecond: while the counter is higher than 0 it gives a
puls and decrease the counter with one.
I wrote this program: (Also attached: Test.zip)
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 |
|
4 | entity dts_signals is
|
5 | Port (
|
6 | clk_in : in STD_LOGIC;
|
7 | btn0 : in STD_LOGIC;
|
8 | A0 : out STD_LOGIC;
|
9 | A0_N : out STD_LOGIC;
|
10 | A1 : out STD_LOGIC;
|
11 | A1_N : out STD_LOGIC
|
12 | );
|
13 | end dts_signals;
|
14 |
|
15 | architecture Behavioral of dts_signals is
|
16 | signal c_TTL : integer range 0 to 81910 := 0; -- 2^13 reset after 10 cycle
|
17 | signal position : integer range 0 to 8191 := 0; -- 2^13
|
18 | signal A0_M : std_logic := '0';
|
19 | signal A1_M : std_logic := '0';
|
20 | signal btn0_M : std_logic := '0';
|
21 | signal c_TTL_M : std_logic := '0';
|
22 | begin
|
23 | dts_signals: process (clk_in) begin
|
24 | if rising_edge(clk_in) then
|
25 | if (btn0 = '1' and btn0_M = '0' and position < 5000) then
|
26 | position <= (position + 200);
|
27 | btn0_M <= '1';
|
28 | end if;
|
29 | if (btn0 = '0' and btn0_M = '1') then
|
30 | btn0_M <= '0'; --Memory rising_edge button
|
31 | end if;
|
32 |
|
33 | if c_TTL = 60000 then --at very lo speed 60000 counts of 20Mhz cristal
|
34 | c_TTL <= 0;
|
35 | c_TTL_M<='0';
|
36 | if position > 2000 then
|
37 | if (A0_M='0' and A1_M='0' and c_TTL_M='0') then A1_M<='1';c_TTL_M<='1'; end if;
|
38 | if (A0_M='0' and A1_M='1' and c_TTL_M='0') then A0_M<='1';c_TTL_M<='1'; end if;
|
39 | if (A0_M='1' and A1_M='0' and c_TTL_M='0') then A0_M<='0';c_TTL_M<='1'; end if;
|
40 | if (A0_M='1' and A1_M='1' and c_TTL_M='0') then A1_M<='0';c_TTL_M<='1'; end if;
|
41 | if (A0_M = '1') then A0_N<='0';A0<='1'; else A0_N<='1';A0<='0';end if;
|
42 | if (A1_M = '1') then A1_N<='0';A1<='1'; else A1_N<='1';A1<='0';end if;
|
43 | position <= (position - 1);
|
44 | end if;
|
45 | else
|
46 | c_TTL <= c_TTL + 1;
|
47 | end if;
|
48 | end if;
|
49 | end process;
|
50 | end Behavioral;
|
But when I test te program this is wat happen:
10x push button0: nothing happen --good because of position > 2000
5x push button0: kflop board counts position: 500 pulses --good
3x push button0: stil position 500 no change ... --false
1x push button0: position 572 -- very strange! I expect it to be a
multiply of 100.
reset position of the kflop counter.
13x push button0: position 1300 --good
1x push button0: position 1300 --wrong
1x push button0: position 1372 --wrong!
Some how the program send's 0 pulses or 72 pulses or 100 pulses after
every push of button 0. I would expect 100 pulses every push...
Do you know what i do wrong?
Frank