Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 4416|回復: 4
打印 上一主題 下一主題

[問題求助] CPLD PS/2 Keyboard 程式問題..thx

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-1-17 17:04:50 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
CPLD MAXII 1270  PS/2 Keyboard 程式問題6 i" d& u5 ~. \  M$ m' N$ e+ ]
我在網路上收尋到FPGA 收 PS/2 Keyboard程式,將程式套用在CPLD上,Compiler後,無問題,依照程式將Pin腳定義,提供系統CLK,Reset,和PS/2 CLK,PS/2 Data,將DoRead和Scan_DAV(偵測PS/2是否送出信號)相接,Scan_Err接一顆LED(險示Overflow錯誤),Scan_Code接8顆LED(顯示PS/2 8bit Data),但燒錄後,CPLD啟動後,按鍵按下,毫無反應,並且PS/2 CLOCK信號已被降至低準位,似乎鍵盤已被抑制送出信號,請高手們幫忙提供意見好嗎?感謝......
9 ?: W; T8 H6 e5 O; C) ~程式:
; q& C0 V( U) @3 B1 E6 L- N. i6 F5 x0 }-- PS2_Ctrl.vhd
2 j% W( X5 y! \9 v7 z; t-- ------------------------------------------------
* j+ m& ]* u& S! b-- Simplified PS/2 Controller (kbd, mouse...)
( c2 o& ]& q$ P. r) Q-- ------------------------------------------------
& ]# L, G4 |8 Q& s% O  l-- Only the Receive function is implemented !
; P0 I0 M8 r; i( T-- (c) ALSE. http://www.alse-fr.com
, b8 ~: _7 L8 Clibrary IEEE;
6 t9 ~+ u5 h+ X0 l9 e. Kuse IEEE.STD_LOGIC_1164.all;: |) _* S2 S$ l5 A7 T/ H5 @
use IEEE.Numeric_std.all;& g- z! t# `6 e9 t
-- --------------------------------------- U5 X- K; R  J' X
Entity PS2_Ctrl is
' T% s3 X8 E2 L4 S-- --------------------------------------; r; _& }/ o: g7 p8 O/ `, B
generic (FilterSize : positive := 8);
* T4 l; t, b, L& ?* A+ I# bport( Clk : in std_logic; -- System Clock' R8 u; I7 O9 D/ T6 E! _+ W
Reset : in std_logic; -- System Reset6 g5 l- _% P- a6 U6 @( q: k
PS2_Clk : in std_logic; -- Keyboard Clock Line
  Z, E8 [3 E0 M0 E: hPS2_Data : in std_logic; -- Keyboard Data Line, d$ `) B% f6 g( u5 l, r
DoRead : in std_logic; -- From outside when reading the scan code7 V$ ~* K9 ]% d) E  _
Scan_Err : out std_logic; -- To outside : Parity or Overflow error
1 |" C# P' C! S; M8 T+ ~$ iScan_DAV : out std_logic; -- To outside when a scan code has arrived
. d# E7 _; }- q) s* LScan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out
2 i: O1 G7 X) |7 U' N);
/ [3 E# ~4 p# s' v# Xend PS2_Ctrl;
% O5 G$ q7 N& {0 a" w1 U  m0 H$ _-- --------------------------------------+ u9 @; m; r8 [: a, c# w  M8 M5 p
Architecture ALSE_RTL of PS2_Ctrl is9 b  k( |2 T# l3 F- A
-- --------------------------------------
4 q; f# ]# k. V+ ^4 S-- (c) ALSE. http://www.alse-fr.com
# E% |3 D7 x. |1 d" J% i-- Author : Bert Cuzeau.2 S) B, a+ s- @' `# ?' U0 ?
-- Fully synchronous solution, same Filter on PS2_Clk., g4 A, e% L: ^; F# `! r
-- Still as compact as "Plain_wrong"...
' K3 R4 `/ R  F: t3 V-- Possible improvement : add TIMEOUT on PS2_Clk while shifting
5 x: N; Z7 I6 S. k' J) T0 \-- Note: PS2_Data is resynchronized though this should not be
" H  C1 }9 i0 d) V6 P-- necessary (qualified by Fall_Clk and does not change at that time).
8 W' A8 m% W2 P! Q-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.8 `$ S5 j. y/ G/ M
signal PS2_Datr : std_logic;
& O1 F4 [: E* Q  m( ^subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);
5 o' t" \2 }- ^signal Filter : Filter_t;& y% L1 |( l; E! S
signal Fall_Clk : std_logic;0 i" [! G- j6 m: {6 d7 g8 R
signal Bit_Cnt : unsigned (3 downto 0);
$ J  G7 B; M! Jsignal Parity : std_logic;
. ?, W* a$ `: a5 B+ w# [signal Scan_DAVi : std_logic;
! y6 }+ E# N: U) j, dsignal S_Reg : std_logic_vector(8 downto 0);
" E' g8 k9 X' n; {. m$ Q( Bsignal PS2_Clk_f : std_logic;& W; c/ |# m* U( G
Type State_t is (Idle, Shifting);
: R! `- V0 A( K2 lsignal State : State_t;% V( Z& X5 s7 R+ A% v
begin
! k' P* g6 D" f2 M7 G; a* MScan_DAV <= Scan_DAVi;
; a, A2 h. K6 j" _-- This filters digitally the raw clock signal coming from the keyboard :
& @$ _; K1 b' m1 S-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high
5 z# {- Y# O- P8 a-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low( Q9 E6 l- o% M3 }. ~
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data/ u6 E" F; \  [: B! r$ }; F; Y3 ]! V
-- Also in charge of the re-synchronization of PS2_Data, X: Y# `8 w: @6 B& u4 V
process (Clk,Reset)
  N0 D* X' F& abegin
& J9 ?$ Q; ?6 o8 o. f. vif Reset='1' then' H7 @" A# L! D3 g' `& C. |
PS2_Datr <= '0';
$ j+ y: g. F$ jPS2_Clk_f <= '0';0 n# \6 M! E* R
Filter <= (others=>'0');# b5 p: x8 C* _4 G6 i: ^
Fall_Clk <= '0';) U2 a) B5 Q3 ]/ v) ^9 X
elsif rising_edge (Clk) then8 M( W: J' u* i8 T) {
PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'/ M% @- P+ o7 Y/ l9 g4 d
Fall_Clk <= '0';
& _" Q" z; C/ O/ f  l! }Filter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);) W( A" w7 r+ K' v8 A
if Filter = Filter_t'(others=>'1') then
) n" j& z8 a4 X! ~# t) OPS2_Clk_f <= '1';. y; X2 W3 y( C
elsif Filter = Filter_t'(others=>'0') then3 X- R# \" ~$ }
PS2_Clk_f <= '0';
; A% H- k" B) Yif PS2_Clk_f = '1' then0 A% d& k1 R6 Y" I- B
Fall_Clk <= '1';
- o4 Q6 N/ V1 t: T) }+ Z9 h  I  |end if;( }( w" O1 c; p
end if;
  r' j9 @  n0 H! Mend if;
! X: y6 N6 X; fend process;6 O2 a6 v$ D# ~- w0 ~8 x- M
-- This simple State Machine reads in the Serial Data
/ I' C+ c, ?, B. x( n4 E/ i-- coming from the PS/2 peripheral.# O$ [, B" o/ Q5 ?( _% B+ Z- A, E0 Y% s
process(Clk,Reset)
9 {  y7 O: L3 q8 Qbegin
' C; U# A2 n" y" {if Reset='1' then
# z9 _5 O+ r/ G: i4 ?State <= Idle;7 R- f5 ^9 K9 Q9 D' W# U5 {  y; A
Bit_Cnt <= (others => '0');* C- {* N( R( m8 P/ W& }# O; i# ?; ^
S_Reg <= (others => '0');8 ?( w1 Z' X9 E
Scan_Code <= (others => '0');; H1 {0 ^& T' s+ I( v0 K
Parity <= '0';1 m; m) `4 V3 h. \
Scan_Davi <= '0';
& b* y% L( n- aScan_Err <= '0';
* O" T* ]5 e# t1 l: Nelsif rising_edge (Clk) then
3 k! H6 P+ f: K& @+ G6 n2 yif DoRead='1' then* b9 b0 T( i1 k1 h8 L8 g$ C2 a
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden" [' y1 z4 N2 {5 k
end if;
$ k- q" @, f+ k( s6 v$ ccase State is
) P( ~/ ~* J, J4 U9 Nwhen Idle =>6 [% o$ ~" W0 q. c: j: @
Parity <= '0';/ l, m0 u0 R3 n4 D- h
Bit_Cnt <= (others => '0');
' g  P- c9 |) _" y1 Z-- note that we dont need to clear the Shift Register. z9 A# H* ]) M2 T0 ^, C
if Fall_Clk='1' and PS2_Datr='0' then -- Start bit! c" ^" p3 x9 F. a1 k
Scan_Err <= '0';
; S$ {: y% g" q6 u7 cState <= Shifting;1 P4 L7 x8 {$ x4 w* e
end if;, F! r9 @+ i' {+ @
when Shifting =>
+ [) v* ?/ F- d9 t, Bif Bit_Cnt >= 9 then
: T; P: ]3 R* P8 z" y! Cif Fall_Clk='1' then -- Stop Bit
8 ], y& J2 G* e/ e4 j. v% J' o- D: j* Y-- Error is (wrong Parity) or (Stop='0') or Overflow; z# ?) b1 @, R3 u( |
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;
4 S( ^6 h3 m4 ~1 @0 cScan_Davi <= '1';$ Q; D) F3 u6 m% I* B3 o* ?
Scan_Code <= S_Reg(7 downto 0);
4 w9 J* }" M8 c0 U0 l% FState <= Idle;  E8 o6 |7 V5 N& ?  s
end if;
( H: C% C( Z! C8 w3 [/ N. r: Selsif Fall_Clk='1' then9 I: D- m' ~  V4 I, y( d; M( ~
Bit_Cnt <= Bit_Cnt + 1;
2 C' e+ W: p4 g( T; FS_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right3 U) v! R! T1 D" w' k$ |3 A
Parity <= Parity xor PS2_Datr;
) H( k& m+ `- aend if;
/ R0 J  d4 ^5 p: awhen others => -- never reached
* T; x/ b# e' E3 B) z& W1 [State <= Idle;
: c( D( f$ X# l; I: U( zend case;
: ^, d" @: u' A4 S, Eend if;& T* I1 x; N6 {; j8 o/ M
end process;' C9 g+ w! N* D$ b+ V
end ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
5#
發表於 2008-1-18 10:07:16 | 只看該作者
您好$ q# l* T9 y) \- t; ?: Y  E% L
建議先將ps/2 protocol弄懂
0 @* w( B2 E+ p2 V然後再找ps/2鍵盤IC的Data sheet研究一下
+ [8 r; o9 p+ i( e再來就是自己從頭開始寫7 M1 J. ^) y9 v0 m
這樣會比拿別人的code來改,還快
4#
發表於 2008-1-18 01:27:38 | 只看該作者

來逛逛

在正式燒到CPLD之前一定要先用軟體跑過波形,, y. l. O( z" i8 P* A3 U3 i" z$ m" i
最好對protocol有一點聊解,; k! D- v. f, p% K6 O9 e
這樣你就可以預先在軟體模擬波形是不是跟protocol一樣
, B  r: \1 c# W) `9 u" @等到正確了,再將程式燒錄進CPLD才有意義
3#
發表於 2008-1-17 20:24:56 | 只看該作者
你確定你找到的code會動......??2 ~% \9 w, z8 z4 I
你把內部的資料拉出來量量看吧
2#
 樓主| 發表於 2008-1-17 17:07:11 | 只看該作者
補充:0 _- O, h' q' g9 Z
7 N- ^' K0 T/ J& B& W
我系統CLK是直接提供CPLD 16MHz振盪,Keyboard為15KHz,是否因為頻率關係,而無法啟動呢?- e' V- R- j0 D$ d4 w

# {. }; [; }! i- v; m# N" }2 {THX....
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

首頁|手機版|Chip123 科技應用創新平台 |新契機國際商機整合股份有限公司

GMT+8, 2024-9-28 11:29 PM , Processed in 0.167009 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表