Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TCD_BD_JIG by
Revision 1:40527b0f0dfa, committed 2014-10-29
- Comitter:
- katak
- Date:
- Wed Oct 29 11:43:42 2014 +0000
- Parent:
- 0:03dfcdd06518
- Commit message:
- 2014/10/29; IO,AD?????????; ??????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 29 02:52:51 2014 +0000 +++ b/main.cpp Wed Oct 29 11:43:42 2014 +0000 @@ -33,6 +33,12 @@ int trgADcmp(short ADdata, unsigned short ch); // ターゲット取得AD値比較処理 +unsigned short trgIO1check(unsigned short mode); // ターゲットIO1チェック処理 +unsigned short trgIO2check(unsigned short mode); // ターゲットIO2チェック処理 + +short trgADreq(unsigned short ch); // DA設定&ターゲットAD値リクエスト + + /* 定数宣言 */ // DA固定出力(0-2.5-5V) @@ -66,6 +72,12 @@ unsigned short cmpADch; +short SqchkNo; // シーケンシャルチェックstep +unsigned short SqTrgchkNo[5]; // シーケンシャルチェック時判定用ch設定 +unsigned short SqTrgDA[5]; // シーケンシャルチェック時DA値格納先(出力値) +short SqTrgAD[5]; // シーケンシャルチェック時AD値格納先 + + // pc-SIO char rx_buf_PC[50]; char rx_ch_PC; @@ -97,6 +109,9 @@ unsigned short flgCHKrun; unsigned short flgRxAD; +unsigned short flgSqADchk; + + /* 割込ハンドラ */ /* pc-SIO_受信 */ void isr_Rx_PC() @@ -171,6 +186,19 @@ /* DA出力初期化 */ da1.write_u16(0); flgRxAD = 0; // ターゲットAD受信フラグ + flgSqADchk = 0; // シーケンシャルチェックフラグ + + SqTrgDA[0] = 0; // 未使用 + SqTrgDA[1] = outDA0v0; // 0.0V + SqTrgDA[2] = outDA2v5; // 2.5V + SqTrgDA[3] = outDA5v0; // 5.0V + SqTrgDA[4] = outDA0v0; // 0.0V + + SqTrgchkNo[0] = 0; // 未使用 + SqTrgchkNo[1] = 1; // 0.0V + SqTrgchkNo[2] = 2; // 2.5V + SqTrgchkNo[3] = 3; // 5.0V + SqTrgchkNo[4] = 1; // 0.0V /* 起動出力 */ pc.printf("SIOpc test start \r"); @@ -189,7 +217,65 @@ /* AD値判定処理 */ if( flgRxAD == 1){ - trgADcmp(TrgAD, cmpADch); + if( flgSqADchk == 0 ){ + /* AD値 個別判定 */ + if( trgADcmp(TrgAD, cmpADch) == 0){ + // OK + sprintf(cbufstr,"OK,%05d\r",(int)TrgAD); + }else{ + // NG + sprintf(cbufstr,"NG,%05d\r",(int)TrgAD); + } + sio1.puts(cbufstr); + }else{ + /* AD値 シーケンシャル判定 */ + SqTrgAD[SqchkNo] = TrgAD; // 受信AD値保存 + if( trgADcmp(SqTrgAD[SqchkNo], SqTrgchkNo[SqchkNo]) == 0){ + // OK + switch(SqchkNo){ + case 1: + // 指令値2.5V設定&ターゲットモニタ値リクエスト + trgADreq(2); + SqchkNo++; + break; + case 2: + // 指令値5.0V設定&ターゲットモニタ値リクエスト + trgADreq(3); + SqchkNo++; + break; + case 3: + // 指令値0.0V設定&ターゲットモニタ値リクエスト + trgADreq(1); + SqchkNo++; + break; + case 4: + // シーケンシャル処理終了 + sprintf(cbufstr,"OK\r"); + sio1.puts(cbufstr); + for(i=1;i<=4;i++){ + sprintf(cbufstr,"%05d,%05d\r",(int)SqTrgDA[i],(int)SqTrgAD[i]); + sio1.puts(cbufstr); + } + flgSqADchk = 0; //シーケンシャルチェック終了 + SqchkNo = 0; //シーケンシャルチェックstepリセット + default: + // シーケンシャル処理終了 + flgSqADchk = 0; //シーケンシャルチェック終了 + SqchkNo = 0; //シーケンシャルチェックstepリセット + break; + } + }else{ + // NG + sprintf(cbufstr,"NG,%05d\r",(int)SqchkNo); + sio1.puts(cbufstr); + for(i=1;i<=SqchkNo;i++){ + sprintf(cbufstr,"%05d,%05d\r",(int)SqTrgDA[i],(int)SqTrgAD[i]); + sio1.puts(cbufstr); + } + flgSqADchk = 0; //シーケンシャルチェック終了 + SqchkNo = 0; //シーケンシャルチェックstepリセット + } + } } } } @@ -306,6 +392,21 @@ led4flic.attach(&flic,0.3); flgCHKrun = 1; sio2.puts("CHK\r"); + }else if(strcmp(cbufstr,cmdIOC) == 0){ + // コマンド可:IOC + if( trgIO1check(0) == 0){ // IO1 = OFF check + if( trgIO1check(1) == 0){ // IO1 = ON check + if( trgIO1check(0) == 0){ // IO1 = OFF check + if( trgIO2check(0) == 0){ // IO2 = OFF check + if( trgIO2check(1) == 0){ // IO2 = ON check + if( trgIO2check(0) == 0){ // IO2 = OFF check + sio1.puts("OK\r"); + }else sio1.puts("NG.6\r"); + }else sio1.puts("NG.5\r"); + }else sio1.puts("NG.4\r"); + }else sio1.puts("NG.3\r"); + }else sio1.puts("NG.2\r"); + }else sio1.puts("NG.1\r"); }else{ // コマンド不可 sio1.puts("CMD Error 3\r"); @@ -313,78 +414,55 @@ }else if( len == 6){ if(strcmp(cbufstr,cmdIO1) == 0){ // コマンド可:IO1 - sio1.puts("res IO1\r"); +// sio1.puts("res IO1\r"); if( rx_buf_SIO1[4] == '0' ){ - outRSTDRV = 1; - wait(0.5); - if( inDrvAlm == 1 ){ + if( trgIO1check(0) == 0){ sio1.puts("OK\r"); - }else{ - sio1.puts("NG\r"); - } + }else sio1.puts("NG\r"); }else if(rx_buf_SIO1[4] == '1'){ - outRSTDRV = 0; - wait(0.5); - if( inDrvAlm == 0 ){ + if( trgIO1check(1) == 0){ sio1.puts("OK\r"); - }else{ - sio1.puts("NG\r"); - } + }else sio1.puts("NG\r"); }else{ sio1.puts("Data Error cmdIO1\r"); } }else if(strcmp(cbufstr,cmdIO2) == 0){ // コマンド可:IO2 - sio1.puts("res IO2\r"); +// sio1.puts("res IO2\r"); if( rx_buf_SIO1[4] == '0' ){ - outPWMON = 1; - wait(0.5); - if( inReady == 1 ){ + if( trgIO2check(0) == 0){ sio1.puts("OK\r"); - }else{ - sio1.puts("NG\r"); - } + }else sio1.puts("NG\r"); }else if(rx_buf_SIO1[4] == '1'){ - outPWMON = 0; - wait(0.5); - if( inReady == 0 ){ + if( trgIO2check(1) == 0){ sio1.puts("OK\r"); - }else{ - sio1.puts("NG\r"); - } + }else sio1.puts("NG\r"); }else{ sio1.puts("Data Error cmdIO2\r"); } }else if(strcmp(cbufstr,cmdDAC) == 0){ // コマンド可:DAC - sio1.puts("res DAC\r"); +// sio1.puts("res DAC\r"); if(rx_buf_SIO1[4] == '1'){ - sprintf(cbufstr,"DAC,%05d\r",outDA0v0); - sio1.puts(cbufstr); - da1.write_u16(outDA0v0); - - wait(0.2); - sio2.puts("DAC\r"); -// pc.puts("DAC\r"); - cmpADch = 1; // 比較用chセット + // 指令値0.0V設定&ターゲットモニタ値リクエスト + trgADreq(1); }else if(rx_buf_SIO1[4] == '2'){ - sprintf(cbufstr,"DAC,%05d\r",outDA2v5); - sio1.puts(cbufstr); - da1.write_u16(outDA2v5); - - wait(0.2); - sio2.puts("DAC\r"); -// pc.puts("DAC\r"); - cmpADch = 2; // 比較用chセット + // 指令値2.5V設定&ターゲットモニタ値リクエスト + trgADreq(2); }else if(rx_buf_SIO1[4] == '3'){ - sprintf(cbufstr,"DAC,%05d\r",outDA5v0); - sio1.puts(cbufstr); - da1.write_u16(outDA5v0); - - wait(0.2); - sio2.puts("DAC\r"); -// pc.puts("DAC\r"); - cmpADch = 3; // 比較用chセット + // 指令値5.0V設定&ターゲットモニタ値リクエスト + trgADreq(3); + }else if(rx_buf_SIO1[4] == '4'){ + // 格納先リセット + for(i=0;i<=4;i++){ + SqTrgAD[i] = 0; + } + // シーケンシャルチェックフラグ = ON + flgSqADchk = 1; + // シーケンシャルチェックstep = 1 + SqchkNo = 1; + // 指令値0.0V設定&ターゲットモニタ値リクエスト + trgADreq(1); }else{ sio1.puts("Data Error cmdDAC\r"); } @@ -396,7 +474,8 @@ }else if( len == 10){ if(strcmp(cbufstr,cmdDAM) == 0){ // コマンド可:DAM - sio1.puts("res DAM\r"); +// sio1.puts("res DAM\r"); + sio1.puts("DAM\r"); strncpy(cbufstr,&rx_buf_SIO1[4],5); intdaout = atoi( cbufstr ); // DA出力設定 @@ -467,11 +546,72 @@ } +/* ターゲットIO1チェック処理 */ +/* 引数: */ +/* unsigned short mode :処理条件(0=OFF,1=ON) */ +/* 戻値: */ +/* unsigned short 0:OK,1:NG,2:mode error */ +/* */ +unsigned short trgIO1check(unsigned short mode) +{ + if( mode == 0 ){ + outRSTDRV = 1; + wait(0.5); + if( inDrvAlm == 1 ){ + return 0; + }else{ + return 1; + } + }else if( mode == 1){ + outRSTDRV = 0; + wait(0.5); + if( inDrvAlm == 0 ){ + return 0; + }else{ + return 1; + } + }else{ + return 2; + } +} + + +/* ターゲットIO2チェック処理 */ +/* 引数: */ +/* unsigned short mode :処理条件(0=OFF,1=ON) */ +/* 戻値: */ +/* unsigned short 0:OK,1:NG,2:mode error */ +/* */ +unsigned short trgIO2check(unsigned short mode) +{ + if( mode == 0 ){ + outPWMON = 1; + wait(0.5); + if( inReady == 1 ){ + return 0; + }else{ + return 1; + } + }else if( mode == 1){ + outPWMON = 0; + wait(0.5); + if( inReady == 0 ){ + return 0; + }else{ + return 1; + } + }else{ + return 2; + } +} + + /* ターゲットAD値判定処理 */ +/* 変数名:int trgADcmp(short ADdata, unsigned short ch) */ /* 引数: */ /* unsigned short ADdata :判定値(受信ADデータ) */ /* unsigned short ch :判定レンジ指定[1:0V0,2:2v5,3,5v0] */ -/* 戻値:int 1:OK, 0:NG */ +/* 戻値:int 0:OK, 1:NG */ /* */ int trgADcmp(short ADdata, unsigned short ch) { @@ -485,44 +625,79 @@ // 0V比較 if( ADdata >= AD0v0l && ADdata <= AD0v0h){ // OK - sprintf(cbufstr,"OK,%05d\r",(int)ADdata); - sio1.puts(cbufstr); - return 1; + return 0; }else{ // NG - sprintf(cbufstr,"NG,%05d\r",(int)ADdata); - sio1.puts(cbufstr); - return 0; + return 1; } }else if( ch == 2 ){ // 2V5比較 if( ADdata >= AD2v5l && ADdata <= AD2v5h){ // OK - sprintf(cbufstr,"OK,%05d\r",(int)ADdata); - sio1.puts(cbufstr); - return 1; + return 0; }else{ // NG - sprintf(cbufstr,"NG,%05d\r",(int)ADdata); - sio1.puts(cbufstr); - return 0; + return 1; } }else if( ch == 3 ){ // 5V0比較 if( ADdata >= AD5v0l && ADdata <= AD5v0h){ // OK - sprintf(cbufstr,"OK,%05d\r",(int)ADdata); - sio1.puts(cbufstr); - return 1; + return 0; }else{ // NG - sprintf(cbufstr,"NG,%05d\r",(int)ADdata); - sio1.puts(cbufstr); - return 0; + return 1; } }else{ // ch error sio1.puts("error ADch\r"); - return 0; + return 1; } } + + +/* ターゲットAD値出力設定&モニタ値リクエスト処理 */ +/* 変数名:short trgADreq(unsigned short ch) */ +/* 引数: */ +/* unsigned short ch :判定レンジ指定[1:0V0,2:2v5,3,5v0] */ +/* 戻値:short 0:OK, 1:NG */ +/* */ +short trgADreq(unsigned short ch) +{ + // DA 0.0V設定 + if( ch == 1 ){ +// sprintf(cbufstr,"DAC,%05d\r",outDA0v0); +// sio1.puts(cbufstr); + da1.write_u16(outDA0v0); + // DA 2.5V設定 + }else if( ch == 2 ){ +// sprintf(cbufstr,"DAC,%05d\r",outDA2v5); +// sio1.puts(cbufstr); + da1.write_u16(outDA2v5); + // DA 5.0V設定 + }else if( ch == 3 ){ +// sprintf(cbufstr,"DAC,%05d\r",outDA5v0); +// sio1.puts(cbufstr); + da1.write_u16(outDA5v0); + } + + // wait(0.2sec)後、trgAD値リクエスト + wait(0.2); + sio2.puts("DAC\r"); + + // DA 0.0V設定 + if( ch == 1 ){ + cmpADch = 1; // 比較用chセット + return 0; + // DA 2.5V設定 + }else if( ch == 2 ){ + cmpADch = 2; // 比較用chセット + return 0; + // DA 5.0V設定 + }else if( ch == 3 ){ + cmpADch = 3; // 比較用chセット + return 0; + }else{ + return 1; + } +} \ No newline at end of file