- AI 평균
  ㄴ 평균을 위한 데이터 갯수 가변화 (현 설정값 20개)
  ㄴ 기존 10ms 주기에서 1ms 주기로 변경
- AO 명령어 수신에 대한 DBG 메시지 제거
  ㄴ 너무 빠른 명령으로 IFB 오류 발생 (멈춤)
main
Changwoo Park 1 year ago
parent cb520a2ffe
commit da4fc697af

@ -73,7 +73,7 @@ void AO_Write(int i, int volt) {
AO = &AO_14; AO = &AO_14;
} }
Serial.println(" [AO] " + String(i) + " > " + String(volt)); //Serial.println(" [AO] " + String(i) + " > " + String(volt));
//Serial.print(" > "); //Serial.print(" > ");
//Serial.println(volt); //Serial.println(volt);
AO->setDACOutVoltage(volt, ch); AO->setDACOutVoltage(volt, ch);

@ -5,6 +5,7 @@
/* ---------- Periodics ---------- */ /* ---------- Periodics ---------- */
// Flags // Flags
bool T_1ms = false;
bool T_10ms = false; bool T_10ms = false;
bool T_20ms = false; bool T_20ms = false;
bool T_50ms = false; bool T_50ms = false;
@ -18,6 +19,7 @@ bool T_5000ms = false;
// Datas // Datas
int msCnt = 0; int msCnt = 0;
unsigned long timer = 0; unsigned long timer = 0;
#define AI_AVG_SIZE 20
/* ---------- Arduino Mega 2560 Basic IO ---------- */ /* ---------- Arduino Mega 2560 Basic IO ---------- */
// Pins // Pins
@ -34,7 +36,7 @@ int Size_AI = 16;
int Values_DI; // digit values to a number int Values_DI; // digit values to a number
int Values_AI[16]; int Values_AI[16];
int Recent_AI[16][10]; int Recent_AI[16][AI_AVG_SIZE];
/* ---------- I2C (Analog Output, DAC) ---------- */ /* ---------- I2C (Analog Output, DAC) ---------- */
// Addresses // Addresses

@ -1,6 +1,8 @@
#include "FC_InterfaceBoard.h" #include "FC_InterfaceBoard.h"
#define CR "\r" #define CR "\r"
#define FIN "\n" #define FIN "\n"
#define CRLF "\r\n" #define CRLF "\r\n"
@ -22,7 +24,7 @@ void setup() {
// Timer set // Timer set
MsTimer2::set(10, timer_10ms); MsTimer2::set(1, timer_1ms);
MsTimer2::start(); MsTimer2::start();
} }

@ -15,10 +15,10 @@ void read_analog(){
for(i = 0 ; i < Size_AI ; i++){ for(i = 0 ; i < Size_AI ; i++){
Values_AI[i] = analogRead(AiPin[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][j] = Recent_AI[i][j + 1];
} }
Recent_AI[i][9] = Values_AI[i]; Recent_AI[i][AI_AVG_SIZE - 1] = Values_AI[i];
} }
} }

@ -1,6 +1,12 @@
void Periodic_run(){ void Periodic_run(){
if(T_10ms){
if(T_1ms){
// Read Arduino AI
read_analog(); read_analog();
T_1ms = false;
}
if(T_10ms){
//read_analog();
T_10ms = false; T_10ms = false;
} }
if(T_20ms){ if(T_20ms){
@ -10,8 +16,7 @@ void Periodic_run(){
T_20ms = false; T_20ms = false;
} }
if(T_50ms){ if(T_50ms){
// Read Arduino Inputs // Read Arduino DI
read_digital(); read_digital();
T_50ms = false; T_50ms = false;
} }
@ -55,10 +60,13 @@ void Periodic_run(){
} }
} }
void timer_10ms(){ void timer_1ms(){
msCnt += 10; msCnt += 1;
T_10ms = true; T_1ms = true;
if (msCnt % 10 == 0){
T_10ms = true;
}
if (msCnt % 20 == 0){ if (msCnt % 20 == 0){
T_20ms = true; T_20ms = true;
} }

@ -4,7 +4,7 @@ String Prcss_ALL_Read(){
str += "AI?:"; str += "AI?:";
for (int i = 0; i < Size_AI; i++) { for (int i = 0; i < Size_AI; i++) {
int sum_AI = 0; 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]; sum_AI += Recent_AI[i][j];
} }

Loading…
Cancel
Save