第10章シリアル通信制御回路imai/class/digital/pdf...vhdlでの記述例 2007/01/16...
TRANSCRIPT
![Page 1: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/1.jpg)
2007/01/16 ©2007, Masaharu Imai 1
第10章 シリアル通信制御回路
大阪大学 大学院 情報科学研究科今井 正治
E-mail: [email protected]://www-ise1.ist.osaka-u.ac.jp/~imai/
![Page 2: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/2.jpg)
2007/01/16 ©2007, Masaharu Imai 2
内容
RS232Cの仕様
Dsub 9ピンコネクタ
パリティの生成とチェック
データの送受信手順
クロック生成回路
VHDLでの記述例
![Page 3: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/3.jpg)
2007/01/16 ©2007, Masaharu Imai 3
RS232C
コンピュータ(DTE)と回線終端装置(DCE)間の
標準シリアル・インタフェースDTE: Data Terminal Equipment(コンピュータなど)
DCE: Data Circuit Equipment (モデムなど)
コンピュータ(DTE)
モデム(DCE)
コンピュータ(DTE)
モデム(DCE)
通信回線
(電話回線)
RS232C RS232C
![Page 4: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/4.jpg)
2007/01/16 ©2007, Masaharu Imai 4
RS232Cの応用
コンピュータとモデムストレート・ケーブル
コンピュータ同士クロス・ケーブル
コンピュータ(DTE)
モデム(DCE)
RS232C コンピュータ(DTE)
コンピュータ(DTE)
RS232C
I/O装置(プリンタ,プロッタなど)には、DCE仕様の製品とDTE仕様の製品があるので注意が必要
![Page 5: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/5.jpg)
2007/01/16 ©2007, Masaharu Imai 5
タイムチャートデータ通信可能期間
DTR (DTE)
DSR (DCE)
RTS (DTE)
CTS (DCE)
DCD (DCE)送信可能
受信可能
TxD (DTE)
RxD (DCE)
![Page 6: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/6.jpg)
2007/01/16 ©2007, Masaharu Imai 6
DTEとDCEとの間のデータ通信手順
DTE1. DTRをONにする
2. DSRがONになるまで待つ
3. 送信または受信を繰り返す
4. DTRをOFFにする
5. DSRがOFFになるまで待つ
DCE
1. DSRをONにする
3. 送信または受信を繰り返す
4. DSRをOFFにする
![Page 7: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/7.jpg)
2007/01/16 ©2007, Masaharu Imai 7
DTEからDCEへのデータの送信手順
DTE1. RTSをONにする
2. CTSがONになるまで待つ
3. データを送信する
4. RTSをOFFにする
5. CTSがOFFになるまで待つ
DCE
1. CTSをONにする
3. データを受信する
4. CTSをOFFにする
![Page 8: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/8.jpg)
2007/01/16 ©2007, Masaharu Imai 8
DCEからDTEへのデータの送信手順
DTE
1. DCDがONになったのを認識
2. データを受信する
3. DCDがOFFになったのを認識
DCE
1. DCDをONにする
2. データを送信する
3. DCDをOFFにする
![Page 9: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/9.jpg)
2007/01/16 ©2007, Masaharu Imai 9
信号名一覧
慣用略号 JIS略号 信号の意味
FGSDRDRSCSDR
GND SG 信号用接地 ((Signal) Ground)CDERCI
TxD保安用接地 (Frame Ground)
送信データ
受信データ
送信要求
送信可
データ・セット・レディ
データチャネル受信キャリア検出
DTR データ端末レディ
RI
RxDRTSCTSDSR
被呼表示
DCD
![Page 10: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/10.jpg)
2007/01/16 ©2007, Masaharu Imai 10
RS232Cの信号レベル
状態 L H
電圧 -25 ~ -3 V +3 ~ +25 V
論理 ‘1’ ‘0’
名称 マーク スペース
![Page 11: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/11.jpg)
2007/01/16 ©2007, Masaharu Imai 11
データ線上の信号の例
0 0 1 1 0 0 0 1
D7 D6 D5 D4 D3 D2 D1 D0
データ
D7D6D5D4D3D2D1D0
スタートビット ストップビット
00110001
スペース (H)
マーク (L)
データビット
![Page 12: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/12.jpg)
2007/01/16 ©2007, Masaharu Imai 12
パラメータのまとめ
パラメータ 値
ビットレート(bps, baud)
300, 600, 1200, 2400, 4800, 9600, 19.2K, 38.4K, 57.6K, 115.2K など
データ長 7 bit または 8 bit
パリティ 偶数/奇数/なし
スタートビット 1 bit
ストップビット 1 bit, 1.5 bit または 2 bit
![Page 13: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/13.jpg)
2007/01/16 ©2007, Masaharu Imai 13
内容
RS232Cの仕様
Dsub 9ピンコネクタ
パリティの生成とチェック
データの送受信手順
クロック生成
VHDLでの記述例
![Page 14: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/14.jpg)
2007/01/16 ©2007, Masaharu Imai 14
9ピンDsubインタフェース
9ピンDsubコネクタ(オス)
ピン番号と信号名の対応
12345
6789
ピン番号 信号名
1 CD
端末側通信可能
ホスト側通信可能
2 RD3 TD (SD)4 DTR5 GND6 DSR7 RTS8 CTS9 RI
![Page 15: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/15.jpg)
2007/01/16 ©2007, Masaharu Imai 15
DTEとDCEの接続(ストレート接続)
DTE(端末)
TD
RD
RTS
CTS
CD
DTR
DSR
RI
GND
3
2
7
8
1
4
6
9
5
DCE(ホスト,モデム)
TD
RD
RTS
CTS
CD
DTR
DSR
RI
GND
3
2
7
8
1
4
6
9
5
![Page 16: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/16.jpg)
2007/01/16 ©2007, Masaharu Imai 16
DTEとDTEの接続(クロス/リバース接続)
DTE(端末)
TD
RD
RTS
CTS
CD
DTR
DSR
RI
GND
3
2
7
8
1
4
6
9
5
DTE(端末)
TD
RD
RTS
CTS
CD
DTR
DSR
RI
GND
3
2
7
8
1
4
6
9
5(OPEN)
![Page 17: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/17.jpg)
2007/01/16 ©2007, Masaharu Imai 17
内容
RS232Cの仕様
Dsub 9ピンコネクタ
パリティの生成とチェック
データの送受信手順
クロック生成
VHDLでの記述例
![Page 18: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/18.jpg)
2007/01/16 ©2007, Masaharu Imai 18
パリティ・ビット
データ中の ‘1’ の個数が偶数または奇数になる
ように調整するためのビット
偶数パリティ“0110001” (31H) ⇒ “10110001” (B1H)奇数パリティ“0110001” (31H) ⇒ “00110001” (31H)
RS232Cでは、データ長が7ビットの場合に付け
ることができる
![Page 19: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/19.jpg)
2007/01/16 ©2007, Masaharu Imai 19
パリティ生成回路
d[0]d[1]
d[2]d[3]
d[4]d[5]
d[6]o_eb
eboddddd
ddp
_]6[]5[]4[]3[]2[
]1[]0[
⊕⊕⊕⊕⊕⊕⊕=
![Page 20: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/20.jpg)
2007/01/16 ©2007, Masaharu Imai 20
パリティ検査回路
d[0]d[1]
d[2]d[3]
d[4]d[5]
d[6]d[7]
]7[]6[]5[]4[]3[]2[
]1[]0[_
dddddd
ddebo
⊕⊕⊕⊕⊕⊕⊕=
![Page 21: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/21.jpg)
2007/01/16 ©2007, Masaharu Imai 21
内容
RS232Cの仕様
Dsub 9ピンコネクタ
パリティの生成とチェック
データの送受信手順
クロック生成
VHDLでの記述例
![Page 22: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/22.jpg)
2007/01/16 ©2007, Masaharu Imai 22
データ線上の信号の例
0 0 1 1 0 0 0 1
D7 D6 D5 D4 D3 D2 D1 D0
データ
D7D6D5D4D3D2D1D0
スタートビット ストップビット
00110001
スペース (H)
マーク (L)
データビット
![Page 23: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/23.jpg)
2007/01/16 ©2007, Masaharu Imai 23
データの送信手順(DTE側)
1. RTS(送信要求)をHにする。
2. CTS(送信可)がHになるまで待つ。
3. スタートビットを送信する。
4. データのLSBから順に送信する。
5. ストップビットを送信する。
6. 3~5を繰り返す。
7. RTSをLにする。
8. CTSがLになるのを待つ。
9. 終了
![Page 24: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/24.jpg)
2007/01/16 ©2007, Masaharu Imai 24
データの受信手順(DCE側)
1. 受信が可能な状態でRTS(送信要求)がHになったら,CTS(送信可)をHにする。
2. スタートビットを受信する。
3. データのLSBから順に受信する。
4. ストップビットを受信する。
5. 2~4を繰り返す。
6. RTSがLになったら,CTSをLにする。
7. 終了
![Page 25: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/25.jpg)
2007/01/16 ©2007, Masaharu Imai 25
データのサンプリング
STA D0 D1 D2 D3 D4 D5 D6 D7 STOスペース
マーク
T/16 T/2 T T T T T T T T T
T T, 1.5T, 2T
T/2
![Page 26: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/26.jpg)
2007/01/16 ©2007, Masaharu Imai 26
データのサンプリング手順
1. T/16 時間ごとにデータをサンプリングして,ス
タートビットを見つける。
2. T/2 時間後にスタート・ビットを確認する。
スタート・ビットに一致しなければエラー
3. T 時間ごとにデータをサンプリングする。
7点または8点4. T 時間後にストップ・ビットを確認する。
ストップ・ビットに一致しなければエラー
![Page 27: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/27.jpg)
2007/01/16 ©2007, Masaharu Imai 27
送信モジュール・コントローラの状態遷移
start = ‘1’
start = ‘0’ & done_s = ‘1’
done_s = ‘0’done_s = ‘1’
IDLE:sent <= ‘1’
SEND_0:sent <= ‘0’
SEND_1:start_s <= ‘1’
SEND_2:start_s <= ‘0’
![Page 28: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/28.jpg)
2007/01/16 ©2007, Masaharu Imai 28
送信モジュールの状態遷移
IDLE:done <= ‘1’rts <= ‘0’txd <= STOP_BIT
SEND_RDY:done <= ‘0’rts <= ‘1’
SEND_START_B:txd <= START_BITbit_pos := 0
SEND_DATA:txd <= d_in(bit_pos)bit_pos := bit_pos+1
SEND_STOP_B:txd <= STOP_BIT
start_s = ‘1’
cts = ‘1’
bit_pos = 8
![Page 29: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/29.jpg)
2007/01/16 ©2007, Masaharu Imai 29
内容
RS232Cの仕様
Dsub 9ピンコネクタ
パリティの生成とチェック
データの送受信手順
クロック生成
VHDLでの記述例
![Page 30: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/30.jpg)
2007/01/16 ©2007, Masaharu Imai 30
通信に必要なクロック周波数
通信速度 R (bps) クロック周波数 (R x 16) (kHz)300 4.8 = 9.6 / 2600 9.6 = 19.2 / 2
1,200 19.2 = 38.4 / 22,400 38.4 = 76.8 / 24,800 76.8 = 153.6 / 29,600 153.6 = 307.2 / 2
19,200 307.2 = 614.4 / 238,400 614.4 = 1843.2 / 357,600 921.6 = 1843.2 / 2
115,200 1843.2
![Page 31: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/31.jpg)
2007/01/16 ©2007, Masaharu Imai 31
RS-232C用のクロック生成について
基本クロックを33 MHzとする
基本クロックをカウンタを用いて分周する
38.4 kbps以外は、すぐ上の通信速度に必要なクロックを2分周すれば得られる
38.4 kbpsの場合は、115.2 kbpsに必要なクロックを3進カウンタで分周すれば良い。デューティ比が1:2になる
が、単相同期回路であれば実用上差し支えない。
最初に9進カウンタで分周する
33,000 / (1,843.2 x 2) = 8.9518 ≒ 9
![Page 32: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/32.jpg)
2007/01/16 ©2007, Masaharu Imai 32
RS-232C用のクロック生成回路
256進カウンタ
33 MHz
3進カウンタ
4進カウンタ
9進カウンタ
1833,3 kHz, 916.7 kHz
611.1 kHz, 305.6 kHz, 152.8 kHz, 76.4 kHz, ..., 4.8 k Hz
3,666.7 kHz
1,222.2 kHz (デューティ比 2:1)
![Page 33: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/33.jpg)
2007/01/16 ©2007, Masaharu Imai 33
クロック生成回路の誤差の評価
bps 必要なクロック(kHz)
生成されたクロック(kHz) 誤差(%)
300 4.8 4.774 0.54%600 9.6 9.549 0.54%
1,200 19.2 19.097 0.54%2,400 38.4 38.194 0.54%4,800 76.8 76.389 0.54%9,600 153.6 152.778 0.54%
19,200 307.2 305.556 0.54%38,400 614.4 611.111 0.54%57,600 921.6 916.667 0.54%115,200 1843.2 1833.333 0.54%
![Page 34: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/34.jpg)
2007/01/16 ©2007, Masaharu Imai 34
VHDLでの記述例
汎用カウンタ
クロック生成回路
RS232Cデータ送信回路
RS232Cデータ受信回路
![Page 35: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/35.jpg)
2007/01/16 ©2007, Masaharu Imai 35
汎用カウンタの記述(1)---- File : counter.vhd-- Author : Masaharu Imai-- Date : 2004/02/24-- Version : 1.1-- Abstract : generic n bit counter-- Modification History:-- Date By Version Change Description-- =================================================-- 2004/02/21 MI 1.0 Original-- 2004/02/24 MI 1.1 MAX_VAL was added-- =================================================--
![Page 36: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/36.jpg)
2007/01/16 ©2007, Masaharu Imai 36
汎用カウンタの記述(2)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity counter isgeneric( NBIT: natural := 16; MAX_VAL: natural := 0 );port( clock: in std_logic;
reset: in std_logic;count:out std_logic_vector( NBIT-1 downto 0 );carry: out std_logic );
end entity counter;
![Page 37: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/37.jpg)
2007/01/16 ©2007, Masaharu Imai 37
汎用カウンタの記述(3)architecture behavior of counter isbegin
process( clock, reset )variable count_val: std_logic_vector( NBIT-1 downto 0 );variable carry_val: std_logic;
beginif reset = '1' then
count_val := ( others => '0' );carry_val := '0';
elsif clock'event and clock = '1' thencount_val := count_val + 1;if count_val = MAX_VAL then
count_val := ( others => '0' );carry_val := '1';
![Page 38: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/38.jpg)
2007/01/16 ©2007, Masaharu Imai 38
汎用カウンタの記述(4)else
carry_val := '0';end if;
end if;count <= count_val;carry <= carry_val;
end process;
end architecture behavior;
![Page 39: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/39.jpg)
2007/01/16 ©2007, Masaharu Imai 39
RS232C用クロック生成回路の記述(1)---- File : rs232c_clk_gen.vhd-- Author : Masaharu Imai-- Date : 2005/05/09-- Version : 1.2-- Abstract : Clock generator for RS232C ---- clk_out(9): 4.8 kHz for 300 bps-- clk_out(8): 9.6 kHz for 600 bps-- clk_out(7): 19.2 kHz for 1.2 kbps-- clk_out(6): 38.4 kHz for 2.4 kbps-- clk_out(5): 76.8 kHz for 4.8 kbps-- clk_out(4): 153.6 kHz for 9.6 kbps-- clk_out(3): 307.2 kHz for 19.2 kbps-- clk_out(2): 614.4 kHz for 38.4 kbps
![Page 40: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/40.jpg)
2007/01/16 ©2007, Masaharu Imai 40
RS232C用クロック生成回路の記述(2)-- clk_out(1): 921.6 kHz for 57.6 kbps-- clk_out(0):1843.2 kHz for 115.2 kbps---- Modification History:-- Date By Version Change Description-- =================================================-- 2004/11/06 MI 1.0 Original-- 2004/12/23 MI 1.1 Bug Fixed-- 2005/05/09 MI 1.2 Clock port renamed-- =================================================--
![Page 41: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/41.jpg)
2007/01/16 ©2007, Masaharu Imai 41
RS232C用クロック生成回路の記述(3)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity rs232c_clk_gen isport( clk_33MHz: in std_logic;
reset: in std_logic;clk_out: out std_logic_vector( 9 downto 0 ) );
end entity rs232c_clk_gen;
![Page 42: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/42.jpg)
2007/01/16 ©2007, Masaharu Imai 42
RS232C用クロック生成回路の記述(4)architecture structure of rs232c_clk_gen is
component counter isgeneric( NBIT: natural := 16; MAX_VAL: natural := 0 );port( clock: in std_logic;
reset: in std_logic;count:out std_logic_vector( NBIT-1 downto 0 );carry: out std_logic );
end component counter;
signal count_1: std_logic_vector( 3 downto 0 );signal count_2: std_logic_vector( 1 downto 0 );signal count_3: std_logic_vector( 1 downto 0 );signal count_4: std_logic_vector( 7 downto 0 );
![Page 43: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/43.jpg)
2007/01/16 ©2007, Masaharu Imai 43
RS232C用クロック生成回路の記述(5)signal carry_1: std_logic;signal carry_2: std_logic;signal carry_3: std_logic;signal carry_4: std_logic;
begin
CNT_1: counter generic map( -- First Base Clock 33 MHz / 9NBIT => 4, MAX_VAL => 9 )
port map(clock => clk_33MHz,reset => reset,count => count_1,carry => carry_1 );
![Page 44: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/44.jpg)
2007/01/16 ©2007, Masaharu Imai 44
RS232C用クロック生成回路の記述(6)CNT_2: counter generic map( -- 1843.2 kHz and 921.6 K Hz
NBIT => 2, MAX_VAL => 0)port map(
clock => carry_1,reset => reset,count => count_2,carry => carry_2 );
CNT_3: counter generic map( -- Second Base Clock NBIT => 2, MAX_VAL => 3)
port map(clock => carry_1,reset => reset,count => count_3,carry => carry_3 );
![Page 45: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/45.jpg)
2007/01/16 ©2007, Masaharu Imai 45
RS232C用クロック生成回路の記述(7)CNT_4: counter generic map( -- 4.8 kHz to 614.4 kHz
NBIT => 8, MAX_VAL => 0)port map(
clock => carry_3,reset => reset,count => count_4,carry => carry_4 );
clk_out <= count_4 & count_2;
end architecture structure;
![Page 46: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/46.jpg)
2007/01/16 ©2007, Masaharu Imai 46
RS232Cデータ送信回路(1)---- File : SEND.vhd-- Author : Masaharu Imai-- Date : 2004/10/15-- Version : 1.0-- Abstract : RS232C 送受信回路(4線式)Version 1-- 送信のみ,データ長: 8 bit,ストップビット 1 bit-- Modification History:-- Date By Version Change Description-- ================================================-- 2004/10/15 MI 1.0 Original-- ================================================--
![Page 47: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/47.jpg)
2007/01/16 ©2007, Masaharu Imai 47
RS232Cデータ送信回路(2)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity send isport( clock: in std_logic;
reset: in std_logic;start: in std_logic;done: out std_logic;d_in: in std_logic_vector( 7 downto 0 );cts: in std_logic;rts:out std_logic;txd: out std_logic );
end entity send;
![Page 48: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/48.jpg)
2007/01/16 ©2007, Masaharu Imai 48
RS232Cデータ送信回路(3)architecture behavior of send is
constant START_BIT: std_logic := '1';constant STOP_BIT: std_logic := '0';signal clk_16: std_logic;
begin
CLK_DIV: process ( clock, reset )variable clk_16v: std_logic;variable cnt_8: natural range 0 to 7;
beginif reset = '1' then
clk_16v := '0';cnt_8 := 0;
![Page 49: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/49.jpg)
2007/01/16 ©2007, Masaharu Imai 49
RS232Cデータ送信回路(4)elsif clock'event and clock = '1' then
if cnt_8 = 7 thenclk_16v := not clk_16v;cnt_8 := 0;
elsecnt_8 := cnt_8 + 1;
end if;end if;clk_16 <= clk_16v;
end process CLK_DIV;
![Page 50: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/50.jpg)
2007/01/16 ©2007, Masaharu Imai 50
RS232Cデータ送信回路(5)SEND_DATA: process ( clk_16, reset, start, d_in, cts )
type status_t is ( IDLE, SEND_RDY, SEND_START_B, SEND_DATA,SEND_STOP_B );
variable done_s: std_logic;variable status: status_t;variable bit_pos: natural range 0 to 8;
beginif reset = '1' then
status := IDLE;done <= '1';rts <= '0';txd <= STOP_BIT;
![Page 51: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/51.jpg)
2007/01/16 ©2007, Masaharu Imai 51
RS232Cデータ送信回路(6)elsif clk_16'event and clk_16 = '1' then
case status iswhen IDLE => -- Wait until start = '1'
done <= '1';rts <= '0';txd <= STOP_BIT; if start = '1' then
status := SEND_RDY;end if;
when SEND_RDY => -- Wait until cts = '1'done <= '0';rts <= '1';if cts = '1' then
status := SEND_START_B;end if;
![Page 52: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/52.jpg)
2007/01/16 ©2007, Masaharu Imai 52
RS232Cデータ送信回路(7)when SEND_START_B => -- Send START BIT
txd <= START_BIT;bit_pos := 0;status := SEND_DATA;
when SEND_DATA => -- Send data bittxd <= d_in( bit_pos );bit_pos := bit_pos + 1;if bit_pos = 8 then
status := SEND_STOP_B;end if;
when SEND_STOP_B => -- Send STOP BITtxd <= STOP_BIT;status := IDLE;
end case;end if;
![Page 53: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/53.jpg)
2007/01/16 ©2007, Masaharu Imai 53
RS232Cデータ送信回路(8)end process SEND_DATA;
end architecture behavior;
![Page 54: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/54.jpg)
2007/01/16 ©2007, Masaharu Imai 54
RS232Cデータ受信回路(1)---- File : RECEIVE.vhd-- Author : Masaharu Imai-- Date : 2004/10/15-- Version : 1.0-- Abstract : RS232C 送受信回路(4線式)Version 1-- 受信のみ,データ長: 8 bit,ストップビット 1 bit-- Modification History:-- Date By Version Change Description-- =================================================-- 2004/10/15 MI 1.0 Original-- =================================================--
![Page 55: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/55.jpg)
2007/01/16 ©2007, Masaharu Imai 55
RS232Cデータ受信回路(2)library ieee;use ieee.std_logic_1164.all;
entity receive isport( clock: in std_logic;
reset: in std_logic;done: out std_logic;stat: out std_logic;cts: in std_logic;rxd: in std_logic;rts:out std_logic;d_out:out std_logic_vector( 7 downto 0 ) );
end entity receive;
![Page 56: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/56.jpg)
2007/01/16 ©2007, Masaharu Imai 56
RS232Cデータ受信回路(3)architecture behavior of receive is
constant START_BIT: std_logic := '1';constant STOP_BIT: std_logic := '0';
begin
REC_DATA: process ( clock, reset )type status_t is ( IDLE, REC_RDY,
REC_STB_0, REC_STB_1,REC_DATA_0, REC_DATA_1,REC_SPB_0, REC_SPB_1,SKIP_SPB_0, SKIP_SPB_1 );
variable status: status_t;variable count: natural range 0 to 15;variable bit_pos: natural range 0 to 8;
![Page 57: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/57.jpg)
2007/01/16 ©2007, Masaharu Imai 57
RS232Cデータ受信回路(4)begin
if reset = '1' thendone <= '1';stat <= '1'; status := IDLE;
elsif clock'event and clock = '1' thencase status iswhen IDLE => -- Idle
done <= '1';rts <= '0';if cts = '1' then
status := REC_RDY;end if;
![Page 58: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/58.jpg)
2007/01/16 ©2007, Masaharu Imai 58
RS232Cデータ受信回路(5)when REC_RDY => -- Wait START Bit
rts <= '1';count := 7;bit_pos := 0;if cts = '0' then
status := IDLE;elsif rxd = START_BIT then
status := REC_STB_0;end if;
when REC_STB_0 => -- Wait for 1+7 clocksdone <= '0';count := count - 1;if count = 0 then
status := REC_STB_1;end if;
![Page 59: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/59.jpg)
2007/01/16 ©2007, Masaharu Imai 59
RS232Cデータ受信回路(6)when REC_STB_1 => -- Confirm START_BIT
count := 15;if rxd = START_BIT then
status := REC_DATA_0; -- OKelse
status := REC_RDY; -- Errorend if;
when REC_DATA_0 => -- Wait for 1+15 clockscount := count - 1;if count = 0 then
status := REC_DATA_1;end if;
![Page 60: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/60.jpg)
2007/01/16 ©2007, Masaharu Imai 60
RS232Cデータ受信回路(7)when REC_DATA_1 => -- Receive data
d_out( bit_pos ) <= rxd;bit_pos := bit_pos + 1;count := 15; if bit_pos = 8 then
status := REC_SPB_0;else
status := REC_DATA_0;end if;
when REC_SPB_0 => -- Wait for 1+15 clockscount := count - 1;if count = 0 then
status := REC_SPB_1;end if;
![Page 61: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/61.jpg)
2007/01/16 ©2007, Masaharu Imai 61
RS232Cデータ受信回路(8)when REC_SPB_1 => -- Confirm STOP_BIT
if rxd = STOP_BIT thenstat <= '1'; -- OK
elsestat <= '0'; -- Error
end if;count := 7;status := SKIP_SPB_0;
when SKIP_SPB_0 =>count := count - 1;if count = 0 then
status := SKIP_SPB_1;end if;
![Page 62: 第10章シリアル通信制御回路imai/class/DIGITAL/PDF...VHDLでの記述例 2007/01/16 ©2007, Masaharu Imai 18 パリティ・ビット データ中の‘1’ の個数が偶数または奇数になる](https://reader034.vdocuments.net/reader034/viewer/2022042211/5eb2845658acf705883d6a0c/html5/thumbnails/62.jpg)
2007/01/16 ©2007, Masaharu Imai 62
RS232Cデータ受信回路(9)when SKIP_SPB_1 =>
done <= '1';if cts = '1' then -- Continue
status := REC_RDY;else
status := IDLE;end if;
end case;end if;
end process REC_DATA;
end architecture behavior;