Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL code do not work in altera cpld

Status
Not open for further replies.

lgeorge123

Full Member level 2
Joined
Jun 13, 2004
Messages
130
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Hong Kong
Activity points
1,403
I have a rotary encoder write in VHDL but this code does not work in real CPLD , output port led do not show any increase in number!



Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
entity left_right_leds is
    Port (             led : out unsigned(7 downto 0);
                  rotary_a : in std_logic;
                  rotary_b : in std_logic;
                  clk : in std_logic);
    end left_right_leds;
 
architecture Behavioral of left_right_leds is
 
--
signal      rotary_a_in : std_logic;
signal      rotary_b_in : std_logic;
 
signal        rotary_in : std_logic_vector(1 downto 0);
signal        rotary_q1 : std_logic;
signal        rotary_q2 : std_logic;
signal  delay_rotary_q1 : std_logic;
signal     rotary_event : std_logic;
signal      rotary_left : std_logic;
 
signal      led_pattern : unsigned(7 downto 0):= "10000000"; --initial value puts one LED on near the middle.
 
 
begin
 
 
  rotary_filter: process(clk)
  begin
    if clk'event and clk='1' then
 
      --Synchronise inputs to clock domain using flip-flops in input/output blocks.
      rotary_a_in <= rotary_a;
      rotary_b_in <= rotary_b;
      
 
      --concatinate rotary input signals to form vector for case construct.
      rotary_in <= rotary_b_in & rotary_a_in;
 
      case rotary_in is
 
        when "00" => rotary_q1 <= '0';         
                     rotary_q2 <= rotary_q2;
 
        when "01" => rotary_q1 <= rotary_q1;
                     rotary_q2 <= '0';
 
        when "10" => rotary_q1 <= rotary_q1;
                     rotary_q2 <= '1';
 
        when "11" => rotary_q1 <= '1';
                     rotary_q2 <= rotary_q2; 
 
        when others => rotary_q1 <= rotary_q1; 
                       rotary_q2 <= rotary_q2; 
      end case;
 
    end if;
  end process rotary_filter;
 
  direction: process(clk)
  begin
    if clk'event and clk='1' then
 
      delay_rotary_q1 <= rotary_q1;
      if rotary_q1='1' and delay_rotary_q1='0' then
        rotary_event <= '1';
        rotary_left <= rotary_q2;
       else
        rotary_event <= '0';
        rotary_left <= rotary_left;
      end if;
 
    end if;
  end process direction;
 
  led_display: process(clk)
  begin
    if clk'event and clk='1' then
 
      if rotary_event='1' then
        if rotary_left='1' then 
          led_pattern <= led_pattern+ 1; 
             if led_pattern = 255 then
                 led_pattern <= "11111111";
         else
          led_pattern <= led_pattern - 1; 
              if led_pattern = 0 then
                   led_pattern <= "00000000";
        end if;
      end if;
      end if;
      end if;
        led <= led_pattern ;
    end if;
  end process led_display;
 
end Behavioral;

 
Last edited by a moderator:

Hi,

I didn't try to understand the functionnal aspect of your code but first, you should consider using a reset signal to set initial values of your signals.

Franck.
 

In your direction process you need to look at both rotary_q1 and rotary _q2 to determine if the encoder was turned and which way. The way it is now you only see a change when rotary_q1 changes to 1 from 0. It also needs to see a change from 0 to 1. You also need to compare the complete rotary_in signal to the previous rotary_in signal to determine the direction.
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
I must confess, that I'm not too motivated to find out if the shown design can somehow work similar to a standard quadrature decoder.

The latter uses the combination of rotary_in and rotary_in_previous to determine all possible position changes and derive a step and direction signal, as bking suggested. Overflow (change of both inputs between consecutive clock cycles) would be detected as well.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top