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]; }