Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

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

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-1-17 17:04:50 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
CPLD MAXII 1270  PS/2 Keyboard 程式問題
. E, `9 w7 l, ]我在網路上收尋到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信號已被降至低準位,似乎鍵盤已被抑制送出信號,請高手們幫忙提供意見好嗎?感謝......
" h% P7 F6 C3 L# s6 J程式:2 Q- g+ J7 L1 C
-- PS2_Ctrl.vhd
" Q7 [+ l  v& z: p) K' l-- ------------------------------------------------
5 A+ j* h  q3 ~! E7 ]( y-- Simplified PS/2 Controller (kbd, mouse...)
) q1 p' M& q7 Z  ]2 q  p-- ------------------------------------------------0 J- [, G, [: e& ?! E  ^) p
-- Only the Receive function is implemented !: F7 v6 g! _8 i. m. b; v+ w6 U
-- (c) ALSE. http://www.alse-fr.com0 d4 j: a" u2 A# n4 {- H# A
library IEEE;
0 E! V* d# A. r" V) N+ |3 r) Iuse IEEE.STD_LOGIC_1164.all;9 v, U9 z: R9 H* ]) T6 e! ?- k# G& I. Y
use IEEE.Numeric_std.all;
# b' K6 j8 p8 a. f& W4 f& X* Z-- --------------------------------------
' ~+ K! Y! V  BEntity PS2_Ctrl is. |) M/ ]) M/ ~3 D
-- --------------------------------------' i/ c' f- w2 U9 V4 m
generic (FilterSize : positive := 8);
5 [( y8 ~& J& N" @5 ?port( Clk : in std_logic; -- System Clock( T( X0 x. U& E( I) m. X* _  t
Reset : in std_logic; -- System Reset, a3 A0 j( U6 ?' `0 y# k) h& W' ^$ c
PS2_Clk : in std_logic; -- Keyboard Clock Line
0 ^8 K, h- p/ w! s4 t1 x$ DPS2_Data : in std_logic; -- Keyboard Data Line
/ U  z- G. ?8 M6 bDoRead : in std_logic; -- From outside when reading the scan code+ _# @: \8 b# }
Scan_Err : out std_logic; -- To outside : Parity or Overflow error1 \% }: K% w6 ]5 c) X7 x
Scan_DAV : out std_logic; -- To outside when a scan code has arrived
- W) v4 ^  s; v8 `Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out
5 f$ A5 I$ {" }$ A6 c- p);
' f$ b1 G; ~* D/ {end PS2_Ctrl;7 Z' u  Y2 D0 z* r) r$ w
-- --------------------------------------
$ y" A6 C. s% u; rArchitecture ALSE_RTL of PS2_Ctrl is
$ z7 R, Q& h' J4 ?7 d: p-- --------------------------------------
  T/ c. T0 P# N% M) K, j& a-- (c) ALSE. http://www.alse-fr.com
. {2 P3 d. A+ U0 N4 ?-- Author : Bert Cuzeau.3 D0 k' K* W' B
-- Fully synchronous solution, same Filter on PS2_Clk.' [6 C* Z" o' }- `( ?3 V. E& a
-- Still as compact as "Plain_wrong"...2 W- I/ M, m0 z8 S- K
-- Possible improvement : add TIMEOUT on PS2_Clk while shifting  }8 Q1 G! f  q6 P* h* ], V9 k
-- Note: PS2_Data is resynchronized though this should not be/ f2 @( k. A* |; ?0 E
-- necessary (qualified by Fall_Clk and does not change at that time).8 a" C' f& I! [) }2 t: F- t
-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.
0 }$ ], {" t5 V" a6 {. T8 Psignal PS2_Datr : std_logic;) e3 q7 w- c6 L' r& u
subtype Filter_t is std_logic_vector(FilterSize-1 downto 0);
& S' ]* S' t6 d3 Zsignal Filter : Filter_t;9 W9 t! R3 k9 a0 E# @
signal Fall_Clk : std_logic;
* t( l: y1 {: M# }" }8 ^- osignal Bit_Cnt : unsigned (3 downto 0);
) |- H8 \, a  s( p4 zsignal Parity : std_logic;
2 V( B0 B* o% X0 @signal Scan_DAVi : std_logic;$ q; y7 ?3 n7 I
signal S_Reg : std_logic_vector(8 downto 0);6 k- z8 I0 F5 j" c7 f( @5 X# v
signal PS2_Clk_f : std_logic;
) \" C4 \' C4 x2 }% jType State_t is (Idle, Shifting);4 ^! Z9 f2 [- ^* x( \3 m
signal State : State_t;
: a- h$ @1 ]8 Ebegin) n$ J! F- y0 V; d5 s, ~; O
Scan_DAV <= Scan_DAVi;- ~" b+ F& q4 n  E
-- This filters digitally the raw clock signal coming from the keyboard :; W; D# u$ B- O4 x& w$ _
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high
; {: e7 q7 \/ D3 s# o% k5 s-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low
1 H" c2 X" p  \. k-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data1 t5 L7 r: w4 x& C: V0 i% P" v
-- Also in charge of the re-synchronization of PS2_Data
; I8 ^, k) r) _0 j- Z1 E+ h( mprocess (Clk,Reset)
8 h& g, F3 v& V5 q( {: xbegin* U# R# n6 {& T5 X, m
if Reset='1' then
5 H1 J% V3 u/ Q) B0 J! XPS2_Datr <= '0';, K' U4 ]; w5 \
PS2_Clk_f <= '0';. M3 V! i/ g( o4 V; X& h
Filter <= (others=>'0');  E0 d  y9 @7 ~8 D
Fall_Clk <= '0';2 Y. z( {- z; w7 }3 q9 q
elsif rising_edge (Clk) then1 v, \" I1 u0 D' o5 l; k: q+ q
PS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'8 K8 j) }8 ?+ b; ]# k
Fall_Clk <= '0';8 _' g" A& e  k3 C( w2 C2 S7 ?
Filter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);  U; ^/ X8 ?( H6 {) c* S# H8 e
if Filter = Filter_t'(others=>'1') then  M( a$ ]3 }( i. F! A2 U+ H
PS2_Clk_f <= '1';- _, H' p/ t1 D0 w6 [( z
elsif Filter = Filter_t'(others=>'0') then' R4 B& I- v& W$ ~5 c
PS2_Clk_f <= '0';
# J2 P$ c' y. J4 Z' Iif PS2_Clk_f = '1' then3 x$ c( _  b7 g( K6 i* V! g! ^4 }1 C
Fall_Clk <= '1';2 J% [% m* B; K3 O% J* S
end if;
1 J% X1 ~7 {( G& d# E; H2 n% [# Qend if;
, G$ w+ A; E2 D- t7 V2 ?end if;/ E; V: ?% ?: B; U
end process;+ R/ Z6 g3 V" N& i0 ^* t
-- This simple State Machine reads in the Serial Data
# x7 c* u1 v) m6 w0 f-- coming from the PS/2 peripheral.
- y# T8 m! i, v. G: Eprocess(Clk,Reset)
, j- n7 J7 G4 Cbegin
8 J: \9 M, _$ I7 V; rif Reset='1' then
/ O* s9 c1 J( A! S4 P. l# Y8 l4 `State <= Idle;) {0 Y3 |( C2 O: J
Bit_Cnt <= (others => '0');
; C# I' S8 n( O" Q# MS_Reg <= (others => '0');. ~; W8 V* u6 g. V% Z8 E
Scan_Code <= (others => '0');1 A) S3 U  c. X9 W# f& h
Parity <= '0';
0 Z* K" N% ~# i- YScan_Davi <= '0';
  p& e, _1 l8 g# z2 G, EScan_Err <= '0';
: v% ^# F4 k' C2 ]0 X! h7 ^- ielsif rising_edge (Clk) then4 Y0 I( L3 r- ~* s7 ?$ {0 H
if DoRead='1' then) T* E6 |; l1 b8 Z
Scan_Davi <= '0'; -- note: this assgnmnt can be overriden
& V, `! H* W  K: P. ~3 h9 b1 \9 fend if;, o2 x. _0 c5 D
case State is
4 T6 S3 P; N2 A# u' H! Y  v/ {  gwhen Idle =>
9 M  t- P$ ^3 ^) `; H- AParity <= '0';
. A, p1 _9 Q& j! K# t6 k# Z) MBit_Cnt <= (others => '0');
! J* P. C8 e" p' u* d, b; h& g! ^-- note that we dont need to clear the Shift Register- `: V$ }; ?6 N7 o! e
if Fall_Clk='1' and PS2_Datr='0' then -- Start bit
. Y6 Q4 B) i. P. K' A/ I: lScan_Err <= '0';. s6 A$ [. {' l4 q" b+ K1 a
State <= Shifting;+ c& o  q% [# h( W3 F5 y4 Z
end if;! Y/ @  G8 s( E5 Q0 t2 B. x
when Shifting =>
. @0 c  n1 ~! }, x+ g4 pif Bit_Cnt >= 9 then
4 a5 [$ b4 D& A0 }& _1 y% |- I; M8 |if Fall_Clk='1' then -- Stop Bit
2 u6 V% {( Z& x# W0 ]9 {3 H& P-- Error is (wrong Parity) or (Stop='0') or Overflow- g/ p7 O+ c1 S/ h
Scan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;1 z5 R" p0 w0 e6 r* |
Scan_Davi <= '1';
( g0 S0 t6 `/ C# H& Y! lScan_Code <= S_Reg(7 downto 0);/ P, N2 p5 C  h3 W  n
State <= Idle;3 ^* x6 j3 f+ r- G' O7 \+ \  `
end if;1 Z+ ~$ `, Y8 O7 ]' L- \$ w) y
elsif Fall_Clk='1' then. w, c; q4 O+ K4 ~
Bit_Cnt <= Bit_Cnt + 1;
; e4 J) ~8 ^  z$ h0 bS_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right
' P/ b8 \+ B& ^+ H. OParity <= Parity xor PS2_Datr;3 S) H  }: ]9 A
end if;
# `5 f0 g/ n: _; ]when others => -- never reached
1 `& l8 y- n# Y# J) aState <= Idle;& |" I% O1 Y" I" t) M2 g
end case;3 v% G! z7 Y  n; T- o5 G; o* e
end if;
1 @# h; o* _, Y6 D2 ~/ N4 i8 lend process;
% z& e, x" j6 T; T, Aend ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
 樓主| 發表於 2008-1-17 17:07:11 | 只看該作者
補充:
9 E! g8 Y# Z% T+ r0 \" j+ {+ D* i" E8 i  V$ I% e# V7 J6 ]; r! [
我系統CLK是直接提供CPLD 16MHz振盪,Keyboard為15KHz,是否因為頻率關係,而無法啟動呢?
7 o& c3 i3 f# C2 G) r- w" a
2 M' a- ~# w4 `6 s' M3 T% {THX....
3#
發表於 2008-1-17 20:24:56 | 只看該作者
你確定你找到的code會動......??3 `3 D* F& ~/ O- G: q% N  E/ f
你把內部的資料拉出來量量看吧
4#
發表於 2008-1-18 01:27:38 | 只看該作者

來逛逛

在正式燒到CPLD之前一定要先用軟體跑過波形,
9 ]! J& C- n; P( \最好對protocol有一點聊解,
! W$ D, u& S$ n9 ]這樣你就可以預先在軟體模擬波形是不是跟protocol一樣, K% F% f. }/ @- b
等到正確了,再將程式燒錄進CPLD才有意義
5#
發表於 2008-1-18 10:07:16 | 只看該作者
您好
. y( S+ Z+ |" y/ R  c2 y) L+ y建議先將ps/2 protocol弄懂" j( @. h0 m3 h! y. p
然後再找ps/2鍵盤IC的Data sheet研究一下6 Y+ l2 g4 Z2 ~4 W
再來就是自己從頭開始寫- G" m- o/ X* T+ A' d8 {
這樣會比拿別人的code來改,還快
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-9-28 09:26 PM , Processed in 0.174010 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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