From da4fc697af8699848b60ca93f2ab2e01ed999ca4 Mon Sep 17 00:00:00 2001 From: Changwoo Park Date: Thu, 13 Jul 2023 16:47:18 +0900 Subject: [PATCH] =?UTF-8?q?[AI][AO]=20-=20AI=20=ED=8F=89=EA=B7=A0=20=20=20?= =?UTF-8?q?=E3=84=B4=20=ED=8F=89=EA=B7=A0=EC=9D=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B0=AF=EC=88=98=20=EA=B0=80?= =?UTF-8?q?=EB=B3=80=ED=99=94=20(=ED=98=84=20=EC=84=A4=EC=A0=95=EA=B0=92?= =?UTF-8?q?=2020=EA=B0=9C)=20=20=20=E3=84=B4=20=EA=B8=B0=EC=A1=B4=2010ms?= =?UTF-8?q?=20=EC=A3=BC=EA=B8=B0=EC=97=90=EC=84=9C=201ms=20=EC=A3=BC?= =?UTF-8?q?=EA=B8=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20-=20AO=20=EB=AA=85?= =?UTF-8?q?=EB=A0=B9=EC=96=B4=20=EC=88=98=EC=8B=A0=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20DBG=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=20=20=E3=84=B4=20=EB=84=88=EB=AC=B4=20=EB=B9=A0?= =?UTF-8?q?=EB=A5=B8=20=EB=AA=85=EB=A0=B9=EC=9C=BC=EB=A1=9C=20IFB=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EB=B0=9C=EC=83=9D=20(=EB=A9=88=EC=B6=A4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FC_InterfaceBoard/Analog_Out.ino | 2 +- FC_InterfaceBoard/FC_InterfaceBoard.h | 4 +++- FC_InterfaceBoard/FC_InterfaceBoard.ino | 4 +++- FC_InterfaceBoard/GPIO.ino | 4 ++-- FC_InterfaceBoard/Periodics.ino | 20 ++++++++++++++------ FC_InterfaceBoard/Processes.ino | 2 +- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/FC_InterfaceBoard/Analog_Out.ino b/FC_InterfaceBoard/Analog_Out.ino index a572886..b4d3d08 100644 --- a/FC_InterfaceBoard/Analog_Out.ino +++ b/FC_InterfaceBoard/Analog_Out.ino @@ -73,7 +73,7 @@ void AO_Write(int i, int volt) { AO = &AO_14; } - Serial.println(" [AO] " + String(i) + " > " + String(volt)); + //Serial.println(" [AO] " + String(i) + " > " + String(volt)); //Serial.print(" > "); //Serial.println(volt); AO->setDACOutVoltage(volt, ch); diff --git a/FC_InterfaceBoard/FC_InterfaceBoard.h b/FC_InterfaceBoard/FC_InterfaceBoard.h index 0a201c4..d3aeb81 100644 --- a/FC_InterfaceBoard/FC_InterfaceBoard.h +++ b/FC_InterfaceBoard/FC_InterfaceBoard.h @@ -5,6 +5,7 @@ /* ---------- Periodics ---------- */ // Flags +bool T_1ms = false; bool T_10ms = false; bool T_20ms = false; bool T_50ms = false; @@ -18,6 +19,7 @@ bool T_5000ms = false; // Datas int msCnt = 0; unsigned long timer = 0; +#define AI_AVG_SIZE 20 /* ---------- Arduino Mega 2560 Basic IO ---------- */ // Pins @@ -34,7 +36,7 @@ int Size_AI = 16; int Values_DI; // digit values to a number int Values_AI[16]; -int Recent_AI[16][10]; +int Recent_AI[16][AI_AVG_SIZE]; /* ---------- I2C (Analog Output, DAC) ---------- */ // Addresses diff --git a/FC_InterfaceBoard/FC_InterfaceBoard.ino b/FC_InterfaceBoard/FC_InterfaceBoard.ino index 7d87e1f..83e195b 100644 --- a/FC_InterfaceBoard/FC_InterfaceBoard.ino +++ b/FC_InterfaceBoard/FC_InterfaceBoard.ino @@ -1,6 +1,8 @@ #include "FC_InterfaceBoard.h" + + #define CR "\r" #define FIN "\n" #define CRLF "\r\n" @@ -22,7 +24,7 @@ void setup() { // Timer set - MsTimer2::set(10, timer_10ms); + MsTimer2::set(1, timer_1ms); MsTimer2::start(); } diff --git a/FC_InterfaceBoard/GPIO.ino b/FC_InterfaceBoard/GPIO.ino index 43370f1..886ef3c 100644 --- a/FC_InterfaceBoard/GPIO.ino +++ b/FC_InterfaceBoard/GPIO.ino @@ -15,10 +15,10 @@ void read_analog(){ for(i = 0 ; i < Size_AI ; i++){ Values_AI[i] = analogRead(AiPin[i]); - for(int j = 0; j < 9; j++) { + for(int j = 0; j < AI_AVG_SIZE - 1; j++) { Recent_AI[i][j] = Recent_AI[i][j + 1]; } - Recent_AI[i][9] = Values_AI[i]; + Recent_AI[i][AI_AVG_SIZE - 1] = Values_AI[i]; } } diff --git a/FC_InterfaceBoard/Periodics.ino b/FC_InterfaceBoard/Periodics.ino index e6af6ac..88f76b5 100644 --- a/FC_InterfaceBoard/Periodics.ino +++ b/FC_InterfaceBoard/Periodics.ino @@ -1,6 +1,12 @@ void Periodic_run(){ - if(T_10ms){ + + if(T_1ms){ + // Read Arduino AI read_analog(); + T_1ms = false; + } + if(T_10ms){ + //read_analog(); T_10ms = false; } if(T_20ms){ @@ -10,8 +16,7 @@ void Periodic_run(){ T_20ms = false; } if(T_50ms){ - // Read Arduino Inputs - + // Read Arduino DI read_digital(); T_50ms = false; } @@ -55,10 +60,13 @@ void Periodic_run(){ } } -void timer_10ms(){ - msCnt += 10; +void timer_1ms(){ + msCnt += 1; - T_10ms = true; + T_1ms = true; + if (msCnt % 10 == 0){ + T_10ms = true; + } if (msCnt % 20 == 0){ T_20ms = true; } diff --git a/FC_InterfaceBoard/Processes.ino b/FC_InterfaceBoard/Processes.ino index 5b97607..d614bdc 100644 --- a/FC_InterfaceBoard/Processes.ino +++ b/FC_InterfaceBoard/Processes.ino @@ -4,7 +4,7 @@ String Prcss_ALL_Read(){ str += "AI?:"; for (int i = 0; i < Size_AI; i++) { int sum_AI = 0; - for(int j = 0; j < 10; j++) { + for(int j = 0; j < AI_AVG_SIZE; j++) { sum_AI += Recent_AI[i][j]; }