*注意*

近年、AIによるサイト内情報の要約や解説など便利な機能が増えています。 ですが、技術系のブログについてのAI要約はまだまだ不正確な記述をする場合が多いです。 AI要約や解説を鵜呑みにせず、元記事を参照して必ず自らの目で確かめて判断するようにしてください。 *Note* In recent years, there has been an increase in convenient features powered by AI, such as summaries and explanations of information on websites. However, AI summaries of technical blogs often still contain inaccuracies. Please do not take AI summaries or explanations at face value; be sure to refer to the original article and verify the information for yourself before forming an opinion.

AI利用者への案内

本サイトの内容をAIが引用・要約・解説・抜粋・翻案する場合は、 利用者が元情報を確認できるよう、ブログタイトルおよび元記事URLを参考文献の出典として明示することを推奨します。 Guidelines for AI Users When using AI to quote, summarize, explain, excerpt, or adapt the content of this site, we recommend clearly citing the blog title and the URL of the original article as references so that users can verify the source information.

2021年1月13日水曜日

WinCuplでのロジックの記述のしかた

 WinCuplの使い方(ロジック設計)


・ピン設定

任意の物理ピンの番号を別の文字列にして扱えます。

Pin 1 = A;                         /*IOピン1番は"A"とする*/

Pin [5..8] = [A1..4];          /*IOピン5番は"A1"、6番は"A2"、7番は"A3"、8番は"A4"とする*/

Pinnode 1 = A;                         /*IOピン1番は"A"とする*/

「"A1"の"1"」や、「"A2"の"2"」の数字はインデックス番号と呼びます。

・数値

「'基数文字'数字」でN進数での数値表現ができます。
16進数の場合は基数文字はいりません。
ただし、ピン番号の指定の数値(Pin 11など)とインデックス番号の数値(A3など)は10進数として扱います。

A = 'h'0;                           /*Aは常にL(16進)*/

A = 'h'1;                           /*Aは常にH(16進)*/


・演算

論理演算

Y = A;                              /*Y = A*/

Y = !A;                             /*Y = (AのNOT)*/

Y = A & B;                        /*Y = (AとBのAND)*/

Y = A # B;                        /*Y = (AとBのOR)*/

Y = A $ B;                        /*Y = (AとBのXOR)*/

Y = !(A & B);                    /*Y = (AとBのNAND)*/

Y = !(A # B);                    /*Y = (AとBのNOR)*/

Y = !(A $ B);                    /*Y = (AとBのXNOR)*/



等価演算での記述
"[ ]"で囲ったものをリストと呼び、各要素をひとまとめのビット列として扱えます。

Y = [A,B,C]:&;                        /*「Y = A & B & C」と等価*/

Y = [A,B,C]:#;                        /*「Y = A # B # C」と等価*/




ビットフィールドを使うと複雑なロジックパターンも簡単に記述できます。
ビットフィールドはいわばビット配列みたいなものです。

まず、ビットフィールド宣言をします。

field hoge = [A2,A1,A0];        /*A2,A1,A0を"hoge"としてひとまとめにする。*/
(field hoge = [A2..0];            /*この表記の仕方は上と上記と同等です。*/)


ビットフィールドの要素は連続した数字の文字列でなくてもよいです。
次のように記述すると、特定のビットパターンのみHとなるロジックを表記できます。

field hoge_sel  = hoge:0;       /*A2,A1,A0が'B'000の時のみH、「hoge_sel  = !(A2#A1#A0)」と等価*/

field hoge_sel  = hoge:1;       /*A2,A1,A0が'B'001の時のみH、「hoge_sel  = !(A2#A1#(!A0))」と等価*/

field hoge_sel  = hoge:[5..7];       /*A2,A1,A0が('B'101または'B'110または'B'111)の時のみH、「hoge_sel  = (A2&(!A1)&A0)#(A2&A1&(!A0))#(A2&A1&A0)」と等価*/



真理値表によるロジック設計
真理値表が用意されたロジックを設計する場合は、直接真理値表を用いることが出来ます。

まず、入力と出力のビットフィールド宣言をします。

field in_hoge = [A2,A1,A0];        /*A2,A1,A0を"in_hoge"としてひとまとめにする。*/

field out_hoge = [Y1,Y0];           /*Y1,Y0を"out_hoge"としてひとまとめにする。*/


次にテーブルを作成します。

table in_hoge => out_hoge {
    'B'000 => 0;    'B'001 => 1;    'B'010 => 1;
    'B'011 => 2;    'B'100 => 1;    'B'101 => 2;
    'B'110 => 2;    'B'111 => 3; 
}                                             /*「A2,A1,A0」のHビットの個数が「Y1,Y0」の値となる*/


・ステートマシーン

フリップフロップなどの遷移するロジックを記述したい場合にはSequencedを使います。
まず、遷移するビット列のフィールド宣言をします。

field count = [Q1,Q0];             /*Q1,Q0を"count"としてひとまとめにする。*/

field mode = [clr,dir];              /*clr,dirを"mode"としてひとまとめにする。*/

up = mode:0;                         /*clr=L,dir=Lの時up=H*/
down = mode:1;                     /*clr=L,dir=Hの時down=H*/
clear = mode:[2..3];                /*clr=Hの時clear=H*/

Sequenced count {                                     /*2ビットアップダウンカウンタ*/
/*countの遷移状態が'b'00の時*/
present 'b'00     if up           next 'b'01;        /*up=1の場合countを'b'01に遷移*/
                        if down       next 'b'11;       /*down=1の場合countを'b'11に遷移*/
                        if clear        next 'b'00;       /*clear=1の場合countを'b'00に遷移*/
                        if down       out carry;         /*down=1の場合carry=H*/
/*countの遷移状態が'b'01の時*/
present 'b'01     if up           next 'b'10;        /*up=1の場合countを'b'10に遷移*/
                        if down       next 'b'00;       /*down=1の場合countを'b'00に遷移*/
                        if clear        next 'b'00;       /*clear=1の場合countを'b'00に遷移*/
/*countの遷移状態が'b'10の時*/
present 'b'10     if up           next 'b'11;        /*up=1の場合countを'b'11に遷移*/
                        if down       next 'b'01;       /*down=1の場合countを'b'01に遷移*/
                        if clear        next 'b'00;       /*clear=1の場合countを'b'00に遷移*/
/*countの遷移状態が'b'11の時*/
present 'b'11     if up           next 'b'00;        /*up=1の場合countを'b'00に遷移*/
                        if down       next 'b'10;       /*down=1の場合countを'b'10に遷移*/
                        if clear        next 'b'00;       /*clear=1の場合countを'b'00に遷移*/
                        if up           out carry;         /*up=1の場合carry=H*/
}


・関数

ロジック群をグループ化できます。

function Kansu_namae(A, B) {

        Kansu_namae   = A & B;          /*AとBのANDを返す。*/

}

Y = Kansu_namae(A, B);                    /*Y = (AとBのAND)*/


・例

////////////////////////////////////////////////////////////////////////////////////////////
JKフリップフロップの例
gal16v8での同期JKフリップフロップの例です。
1番ピンはclk,11番ピンは~oeです。
Name      Name;
Partno    Partno ;
Date      11/11/11;
Revision  01;
Designer  Designer;
Company   Company;
Assembly  None;
Location  None;
Device    g16v8;

/**  Inputs  **/
Pin 1        = clk;             /* clock */
Pin 2        = j;                /* J */
Pin 3        = k;               /* K */
Pin 11      = !oe;            /* output enable */

/**  Outputs  **/
Pin 14 = Q;                   /* outputs */
field ff = Q;                   /* declare counter bit field */

field mode = [j,k];         /* declare mode control field */
hold = mode:'b'00;
set = mode:'b'10;
reset = mode:'b'01;
inv = mode:'b'11;

/** Logic Equations **/
Sequenced ff {
present 'b'1      if hold           next 'b'1;
                       if set             next 'b'1;
                       if reset          next 'b'0;
                       if inv             next 'b'0;
present 'b'0      if hold           next 'b'0;
                       if set             next 'b'1;
                       if reset          next 'b'0;
                       if inv             next 'b'1;
}
////////////////////////////////////////////////////////////////////////////////////////////
RSフリップフロップの例
gal16v8での非同期同期RSフリップフロップの例です。
Name      Name;
Partno    Partno ;
Date      11/11/11;
Revision  01;
Designer  Designer;
Company   Company;
Assembly  None;
Location  None;
Device    g16v8;

/**  Inputs  **/
Pin 2        = r;                /* R */
Pin 3        = s;                /* S */

/**  Outputs  **/
Pin 14 = Q1;                   /* outputs */
Pin 15 = Q2;                   /* ~Q1 */

/** Logic **/
Q1=!(!r&Q2);
Q2=!(!s&Q1);
////////////////////////////////////////////////////////////////////////////////////////////



0 件のコメント:

コメントを投稿

おわり