]> rtime.felk.cvut.cz Git - fpga/virtex2/uart.git/commitdiff
Peripheral connected to the quadcount module and an incremental encoder. Interrupt...
authorVladimir Burian <buriavl2@fel.cvut.cz>
Mon, 10 Jan 2011 19:21:09 +0000 (20:21 +0100)
committerVladimir Burian <buriavl2@fel.cvut.cz>
Mon, 10 Jan 2011 20:12:44 +0000 (21:12 +0100)
When incremental encoder is turned by one period or more, interrupt is generated and MCU sends current position over RS-232.

omsp_quadcount.vhd
openMSP430_uart.prj
openMSP430_uart.ucf
openMSP430_uart.vhd
software/hardware.h
software/main.c

index e334f41c2af3409a20d72d2479a0024f8b694a35..5c84577c1c5d7ebf384cf1757ebf383a15b9e9d4 100644 (file)
@@ -12,7 +12,7 @@ entity omsp_quadcount is
     per_wen     : in  std_logic_vector (1  downto 0);  -- unused
     puc         : in  std_logic;                       -- unused
     per_irq_acc : in  std_logic;                       -- unused
-    per_irq     : out std_logic;                       -- unused
+    per_irq     : out std_logic;
     per_dout    : out std_logic_vector (15 downto 0);
     
     qcount      : in  std_logic_vector (31 downto 0)
index 8da597078b672028f3fa9a65b07b5f9895c7758f..d13221438e43b8b77f580a52ec0fddc9bac23d4d 100644 (file)
@@ -20,6 +20,8 @@ verilog work openmsp430/periph/omsp_gpio.v
 verilog work openmsp430/periph/omsp_timerA.v
 
 vhdl work omsp_quadcount.vhd
+vhdl work quadcount/dff.vhdl
+vhdl work quadcount/qcounter.vhdl
 
 vhdl work coregen/ram_8x512.vhd
 vhdl work coregen/rom_8x2k.vhd
index ae1106c9a3b3d51798f4d66b1da3ab0f55d6275e..480060c38096a64541a8d1b77846b04d266e7e72 100644 (file)
@@ -14,3 +14,13 @@ NET "RESET"             LOC = "B6";
 NET "RXD"               LOC = "A7";     # input to RS232 driver
 NET "TXD"               LOC = "B7";     # output from RS232 driver
 
+#==============================================================================#
+# Incremental rotary encoder                                                   #
+#==============================================================================#
+# Connected to the header J4.
+
+NET "ROT_FEED"          LOC = "H2";                 # pin 01
+NET "ROT_A"             LOC = "J2"    | PULLDOWN;   # pin 03
+NET "ROT_B"             LOC = "K2"    | PULLDOWN;   # pin 05
+NET "ROT_PRESS"         LOC = "E4"    | PULLDOWN;   # pin 07
+
index cbcd0ef237ccd422b141c780fd23f8a9cd9dea9b..eafcbc8df48ce99494f4d7a028e70aa8e44b44ef 100644 (file)
@@ -9,7 +9,12 @@ entity openMSP430_uart is
     RESET: in std_logic;
 
     RXD : out std_logic;
-    TXD : in std_logic
+    TXD : in std_logic;
+    
+    ROT_FEED : out std_logic;
+    ROT_A : in std_logic;
+    ROT_B : in std_logic;
+    ROT_PRESS : in std_logic
   );
 end openMSP430_uart;
 
@@ -168,6 +173,17 @@ architecture rtl of openMSP430_uart is
     );
   end component;
 
+  component qcounter is
+    port (
+      clock    : in std_logic;
+      reset    : in std_logic;
+      a0, b0   : in std_logic;
+      qcount   : out std_logic_vector (31 downto 0);
+      a_rise, a_fall, b_rise, b_fall, ab_event : out std_logic;
+      ab_error : out std_logic
+    );
+  end component;
+
 
   signal mclk : std_logic;
   signal puc : std_logic;
@@ -200,6 +216,9 @@ architecture rtl of openMSP430_uart is
 
   signal irq_ta0 : std_logic;
   signal irq_ta1 : std_logic;
+  signal omsp_quadcount_irq : std_logic;
+
+  signal qcount : std_logic_vector (31 downto 0);
 
 --------------------------------------------------------------------------------
 
@@ -359,10 +378,24 @@ begin
     per_wen     => "00",
     puc         => '0',
     per_irq_acc => '0',
-    per_irq     => open,
+    per_irq     => omsp_quadcount_irq,
     per_dout    => omsp_quadcount_dout,
     
-    qcount      => X"0001E240" -- 123456
+    qcount      => qcount
+  );
+
+  qcounter_0 : qcounter port map (
+    clock     => mclk,
+    reset     => ROT_PRESS,
+    a0        => ROT_A,
+    b0        => ROT_B,
+    qcount    => qcount,
+    a_rise    => open,
+    a_fall    => open,
+    b_rise    => open,
+    b_fall    => open,
+    ab_event  => open,
+    ab_error  => open
   );
 
 --------------------------------------------------------------------------------
@@ -371,7 +404,10 @@ begin
   
   irq <= (9 => irq_ta0,
           8 => irq_ta1,
+          7 => omsp_quadcount_irq,
           others => '0');
   
+  ROT_FEED <= '1';
+  
 end rtl;
 
index d7131041c5c0f2b5bf0463ec800aa05d7852c6fe..cb99613037ab0d9a84607955a4aee5915b01a707 100644 (file)
@@ -14,6 +14,8 @@
 sfrw(QCNTL,QCNTL_);
 #define QCNTH_             0x0152
 sfrw(QCNTH,QCNTH_);
+//QuadCount IRQ vector
+#define QCNT_VECTOR        14
 
 
 //PINS
index 15b2a056c19c4b4ec8f849089e3e41d24537f64c..bf98951974bc10d20af9a79ed132be1a8d24b067 100644 (file)
@@ -23,6 +23,14 @@ inline uint32_t qcount() {
   return result;
 }
 
+/**
+Handling of QuadCounter IRQ
+*/
+interrupt(QCNT_VECTOR) qcount_isr() {
+  printf("[QCount = 0x%08lX]\n", qcount() >> 2);
+}
+
+
 /**
 Delay function.
 */