Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

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

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-1-17 17:04:50 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
CPLD MAXII 1270  PS/2 Keyboard 程式問題" ^# r% B4 N, O5 \
我在網路上收尋到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信號已被降至低準位,似乎鍵盤已被抑制送出信號,請高手們幫忙提供意見好嗎?感謝......' ?" p( G: {' l! s' M4 h0 B
程式:
$ a3 i' u6 t# p4 o1 s7 N3 y-- PS2_Ctrl.vhd
: ^$ F$ k' `5 b9 w  i-- ------------------------------------------------' J: _( Q6 X# S4 \; t# F# [
-- Simplified PS/2 Controller (kbd, mouse...)5 M% G: C8 d+ x2 l. \* B( m
-- ------------------------------------------------
% a: L3 p5 Q: D* @-- Only the Receive function is implemented !
. i: k$ U& ~% ^# L-- (c) ALSE. http://www.alse-fr.com
3 o6 X2 C4 H$ j; T3 z$ i( z2 dlibrary IEEE;
7 B, H. R6 Q! [5 x/ H( T% G; cuse IEEE.STD_LOGIC_1164.all;+ N3 M0 A8 W& i) T9 ~. P' v
use IEEE.Numeric_std.all;
7 s/ K. r3 s# @( L: N! U4 @0 f. V-- --------------------------------------
: |! ^7 R7 k# Q2 {% uEntity PS2_Ctrl is* A  S0 l7 }0 P0 z3 v. v
-- --------------------------------------
4 j3 f! L4 y0 B: Rgeneric (FilterSize : positive := 8);3 A4 U2 P4 z) V9 j+ Q
port( Clk : in std_logic; -- System Clock
4 p8 Y( P$ b7 a0 V/ \6 P  ~Reset : in std_logic; -- System Reset) D% E6 h1 q& b! L
PS2_Clk : in std_logic; -- Keyboard Clock Line
8 ]: G" W% M& X$ n! q6 kPS2_Data : in std_logic; -- Keyboard Data Line
' k9 }( U; ]3 J# K) a, ~$ f# @, `DoRead : in std_logic; -- From outside when reading the scan code
3 J1 b: M& G% zScan_Err : out std_logic; -- To outside : Parity or Overflow error; o/ X/ T7 A4 a* j# @( o5 j  q5 L
Scan_DAV : out std_logic; -- To outside when a scan code has arrived7 `5 q3 d4 y! D, r# W: Z
Scan_Code : out std_logic_vector(7 downto 0) -- Eight bits Data Out5 Z  _% v" H) a9 T; U  D8 C
);& I0 ~% m$ ]3 F; r
end PS2_Ctrl;
7 F) J2 K- ?, F3 P-- --------------------------------------
5 W$ g7 F0 B; J( IArchitecture ALSE_RTL of PS2_Ctrl is
% ^* ^. _- w1 f+ M( H-- --------------------------------------
+ h" n0 T+ h; r9 B( _; q6 l-- (c) ALSE. http://www.alse-fr.com/ [$ I' l* B) l  d3 e! ~
-- Author : Bert Cuzeau.2 h" l4 I6 M1 g9 l* D1 |
-- Fully synchronous solution, same Filter on PS2_Clk.! |) h% v6 w$ P
-- Still as compact as "Plain_wrong"...
8 v6 y$ `  o5 E5 V. ]$ b* [" d-- Possible improvement : add TIMEOUT on PS2_Clk while shifting' X( W( u" {$ z' N: d7 E, ]
-- Note: PS2_Data is resynchronized though this should not be. h  g$ N6 D) }. w+ T# v: p, `
-- necessary (qualified by Fall_Clk and does not change at that time).8 z" b/ \$ Q. f% `, `& r- W8 v
-- Note the tricks to correctly interpret 'H' as '1' in RTL simulation.; {' i  ?+ M1 s- r& {
signal PS2_Datr : std_logic;
2 B7 E" E0 T1 S% e/ m% Q% b+ [& Y* zsubtype Filter_t is std_logic_vector(FilterSize-1 downto 0);7 X) _4 u1 E& D5 b/ N8 Q( ?4 ]
signal Filter : Filter_t;+ _( J8 N  G, O8 }, ?8 ]" a
signal Fall_Clk : std_logic;
, L4 {0 a1 n( r) c  `7 _. \* Isignal Bit_Cnt : unsigned (3 downto 0);& [% w6 D) O$ ?0 l* p" [9 E
signal Parity : std_logic;/ s3 P, Z, |! A* `* i
signal Scan_DAVi : std_logic;
' T- K% R" N; Y" f8 L3 g8 Z  Y0 Ksignal S_Reg : std_logic_vector(8 downto 0);
) C+ ], f/ s/ Dsignal PS2_Clk_f : std_logic;0 ?4 _% r# O  a: F
Type State_t is (Idle, Shifting);: R! x0 l/ j  \0 u
signal State : State_t;
, b) v& v4 m# w0 u- r( x6 l0 rbegin% L6 {; U6 d- L0 F
Scan_DAV <= Scan_DAVi;% q! `/ U8 G. }/ n
-- This filters digitally the raw clock signal coming from the keyboard :, v' n& K7 g2 O- a- H
-- * Eight consecutive PS2_Clk=1 makes the filtered_clock go high
6 E5 T2 a3 }! s$ i1 L; p-- * Eight consecutive PS2_Clk=0 makes the filtered_clock go low/ c- q- O8 r  G, o" ]6 [8 [
-- Implies a (FilterSize+1) x Tsys_clock delay on Fall_Clk wrt Data% p: b1 {8 w+ Y  S9 V
-- Also in charge of the re-synchronization of PS2_Data- U# z9 {5 i: U6 D% Z+ [; L
process (Clk,Reset)
  |* |8 a2 c. |5 `0 qbegin
0 D- i  N6 m, b6 Q; N1 f, Rif Reset='1' then
/ `. g0 E, G) O' V7 l& EPS2_Datr <= '0';; @) N  K# m1 g; L, x
PS2_Clk_f <= '0';
: W6 U+ ?3 ]8 ^. b$ R2 u! uFilter <= (others=>'0');5 n* b& ^! N7 V
Fall_Clk <= '0';0 P" A7 [; J! j
elsif rising_edge (Clk) then
3 ]" e& ]0 Y5 ]# h) PPS2_Datr <= PS2_Data and PS2_Data; -- also turns 'H' into '1'% V! P( m' w* d' g' y! X
Fall_Clk <= '0';
) w% C& p9 b& b% C, GFilter <= (PS2_Clk and PS2_CLK) & Filter(Filter'high downto 1);, M, S- ?* m1 S8 g7 \) c1 j
if Filter = Filter_t'(others=>'1') then, ^7 v+ V1 s% a7 T: [* g+ T* w
PS2_Clk_f <= '1';
' ~9 n: ~7 o* f6 c3 ]) S; D" v) Delsif Filter = Filter_t'(others=>'0') then
+ R; g& y+ R! W6 r' f. q  v5 n  |PS2_Clk_f <= '0';
- g8 x/ V+ R& _  Zif PS2_Clk_f = '1' then
; N/ B5 U% N! u: s, d0 iFall_Clk <= '1';' H+ f- v4 g* ^
end if;
' t# ^0 V. r4 c7 _2 @( Fend if;" }4 V; f& j8 c( T0 o! H: V
end if;' f, [+ S5 U$ D* K2 |# x
end process;
; Z, {4 ^6 N7 {" M; H1 F-- This simple State Machine reads in the Serial Data& o1 X& B2 T9 K* h: D2 E1 i6 e9 C' i
-- coming from the PS/2 peripheral.. X# U5 N! B8 o1 p+ z, |3 m. |% }1 Q
process(Clk,Reset)! e  l- ?* a) J: j( ?! t4 O# G5 N- a
begin
7 f; Q- p7 C! d4 s+ m  g( Fif Reset='1' then
5 {6 _* `9 ~/ G4 H' J" ?+ QState <= Idle;1 G' S/ k6 e7 v' p* Z2 Q
Bit_Cnt <= (others => '0');2 l) |- n" X) R1 Y1 \* i
S_Reg <= (others => '0');5 v( G4 V+ K4 m* h4 G
Scan_Code <= (others => '0');
# B& p$ n2 T# eParity <= '0';, w  r( J% e. x$ T8 i
Scan_Davi <= '0';
; o  Q8 k/ D& U/ h: ^1 [Scan_Err <= '0';
1 e6 r" L% y& y; Oelsif rising_edge (Clk) then4 z' `1 ]: G7 S: C2 U6 k! b
if DoRead='1' then
8 a- ]3 J1 P- e5 K. d7 ?Scan_Davi <= '0'; -- note: this assgnmnt can be overriden2 U0 @3 e7 E9 q7 v0 L$ ^
end if;# f' J& b4 e6 T4 T
case State is$ [1 Q6 e# g" A5 b! u! E, F
when Idle =>% x2 r8 `* L. O% Z9 T( M; N/ t! ?
Parity <= '0';1 \" R6 V6 X: [9 c" _
Bit_Cnt <= (others => '0');
0 i% J3 E  G% _6 M2 p-- note that we dont need to clear the Shift Register
8 d- i1 _% s8 b8 \8 H) O+ oif Fall_Clk='1' and PS2_Datr='0' then -- Start bit
4 |' R! Z& t0 Q$ TScan_Err <= '0';; P0 m2 r  N( A' z8 r& ?/ n# s
State <= Shifting;
; x/ F) P+ ?( e# K; [. Yend if;& m9 q& ^6 d7 a  O$ [- y6 B
when Shifting =>9 O0 D. j* I# }' ]  X- u
if Bit_Cnt >= 9 then, F! V# X1 J0 S9 o1 l
if Fall_Clk='1' then -- Stop Bit
2 Y0 K( d* v$ v-- Error is (wrong Parity) or (Stop='0') or Overflow
* J! x7 F; n' b5 m( g' ]2 WScan_Err <= (not Parity) or (not PS2_Datr) or Scan_DAVi;5 N7 ?' h& |0 f: C- s
Scan_Davi <= '1';  z4 q4 f$ [' L* [' N. Z
Scan_Code <= S_Reg(7 downto 0);
) a  _: |7 W3 z9 E2 G7 b! SState <= Idle;" o9 r1 G( r6 {/ z6 c" ^
end if;1 D  Q  M6 c+ W- l' H
elsif Fall_Clk='1' then# N1 V( j1 H5 j! L% X, j
Bit_Cnt <= Bit_Cnt + 1;# e* ^. H6 \: ]8 m' J7 U& _% H! t9 \( l( |
S_Reg <= PS2_Datr & S_Reg (S_Reg'high downto 1); -- Shift right) p+ [6 b% D' }- |+ X) R) ^$ a. w
Parity <= Parity xor PS2_Datr;
- u. v( J0 J" d5 l4 @+ M/ Mend if;
, C- A8 G: u/ Q% c! |5 D( pwhen others => -- never reached6 q0 x0 _' I* t' H) p) z
State <= Idle;
9 t& z+ K. p* u. q( rend case;
) B! i+ ?, j+ Yend if;
6 c6 z$ l: C, Y, x1 F) G9 U4 s. Kend process;
5 O# K# W% g. w& h/ K7 zend ALSE_RTL;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
 樓主| 發表於 2008-1-17 17:07:11 | 只看該作者
補充:
. y' E5 i9 K4 T% D, U* D7 k
1 j6 K1 S% L  j( E我系統CLK是直接提供CPLD 16MHz振盪,Keyboard為15KHz,是否因為頻率關係,而無法啟動呢?- Y$ b# |% W. D
! H" \8 z- k' ?- e! }' V4 J5 r
THX....
3#
發表於 2008-1-17 20:24:56 | 只看該作者
你確定你找到的code會動......??
4 T" S. ]) J: X你把內部的資料拉出來量量看吧
4#
發表於 2008-1-18 01:27:38 | 只看該作者

來逛逛

在正式燒到CPLD之前一定要先用軟體跑過波形,8 J, i5 I& E# [! |* a% z
最好對protocol有一點聊解,
9 P& y0 L5 P, K) p這樣你就可以預先在軟體模擬波形是不是跟protocol一樣8 E; W4 J2 y. [; t
等到正確了,再將程式燒錄進CPLD才有意義
5#
發表於 2008-1-18 10:07:16 | 只看該作者
您好8 v; m' V1 H  [5 d9 w/ H4 Q
建議先將ps/2 protocol弄懂+ a* u) u" }9 z; ]2 m
然後再找ps/2鍵盤IC的Data sheet研究一下# [+ p0 ?# Z" f, `! l
再來就是自己從頭開始寫
3 `" p5 W* x) V: N# j9 Q這樣會比拿別人的code來改,還快
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-9-29 01:21 AM , Processed in 0.168010 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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