From 67981366db36c2e7679ccffb8ab879a6825cbd51 Mon Sep 17 00:00:00 2001 From: Vladimir Burian Date: Mon, 10 Jan 2011 20:21:09 +0100 Subject: [PATCH 1/1] Peripheral connected to the quadcount module and an incremental encoder. Interrupt generation and handling added. When incremental encoder is turned by one period or more, interrupt is generated and MCU sends current position over RS-232. --- omsp_quadcount.vhd | 2 +- openMSP430_uart.prj | 2 ++ openMSP430_uart.ucf | 10 ++++++++++ openMSP430_uart.vhd | 42 +++++++++++++++++++++++++++++++++++++++--- software/hardware.h | 2 ++ software/main.c | 8 ++++++++ 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/omsp_quadcount.vhd b/omsp_quadcount.vhd index e334f41..5c84577 100644 --- a/omsp_quadcount.vhd +++ b/omsp_quadcount.vhd @@ -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) diff --git a/openMSP430_uart.prj b/openMSP430_uart.prj index 8da5970..d132214 100644 --- a/openMSP430_uart.prj +++ b/openMSP430_uart.prj @@ -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 diff --git a/openMSP430_uart.ucf b/openMSP430_uart.ucf index ae1106c..480060c 100644 --- a/openMSP430_uart.ucf +++ b/openMSP430_uart.ucf @@ -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 + diff --git a/openMSP430_uart.vhd b/openMSP430_uart.vhd index cbcd0ef..eafcbc8 100644 --- a/openMSP430_uart.vhd +++ b/openMSP430_uart.vhd @@ -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; diff --git a/software/hardware.h b/software/hardware.h index d713104..cb99613 100644 --- a/software/hardware.h +++ b/software/hardware.h @@ -14,6 +14,8 @@ sfrw(QCNTL,QCNTL_); #define QCNTH_ 0x0152 sfrw(QCNTH,QCNTH_); +//QuadCount IRQ vector +#define QCNT_VECTOR 14 //PINS diff --git a/software/main.c b/software/main.c index 15b2a05..bf98951 100644 --- a/software/main.c +++ b/software/main.c @@ -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. */ -- 2.39.2