- AI 10ms마다 누적하여 최근 10개 데이터의 합을 return
- Labview에서는 /10 하여 평균값 사용 필요
main
Changwoo Park 1 year ago
parent 657ff89288
commit cb520a2ffe

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

@ -34,6 +34,7 @@ int Size_AI = 16;
int Values_DI; // digit values to a number
int Values_AI[16];
int Recent_AI[16][10];
/* ---------- I2C (Analog Output, DAC) ---------- */
// Addresses
@ -62,6 +63,40 @@ unsigned long timeoutPeriod = 5000; // 이더넷 타임아웃 시간 (5초)
bool State_eth = false;
HardwareSerial* Serials[] = {&Serial1, &Serial2};
const int BUFF_SIZE = 1024;
char Buff_Eth_Rd[BUFF_SIZE] = {0};
char Buff_485_1_Wr[BUFF_SIZE] = {0};
char Buff_485_1_Rd[BUFF_SIZE] = {0};
char Buff_485_2_Wr[BUFF_SIZE] = {0};
char Buff_485_2_Rd[BUFF_SIZE] = {0};
String latest_sent_msg;
int numOf485 = 0;
int returnTime = 0;
/* ---------- RS485 ---------- */
// 485 CH 1
bool Wait_485_1;
int Wait_485_1_cnt;
int RS485_1_Addr[2] = {0,0};
bool RS485_1_Rcv_PV[2] = {false, false};
bool RS485_1_Rcv_SV[2] = {false, false};
int RS485_1_Rcv_size = 8;
int RS485_1_Values_PV[8*2];
int RS485_1_Values_SV[8*2];
// 485 CH 2
bool Wait_485_2;
int Wait_485_2_cnt;
int RS485_2_Addr[2];
bool RS485_2_Rcv_PV[2];
bool RS485_2_Rcv_SV[2];
int RS485_2_Rcv_size = 8;
int RS485_2_Values_PV[8*2];
int RS485_2_Values_SV[8*2];
//Processes
String Prcss_ALL_Read();

@ -10,49 +10,6 @@
String IdeSerial; // for 485_0
HardwareSerial* Serials[] = {&Serial1, &Serial2};
const int BUFF_SIZE = 512;
char Buff_Eth_Rd[BUFF_SIZE] = {0};
char Buff_485_1_Wr[BUFF_SIZE] = {0};
char Buff_485_1_Rd[BUFF_SIZE] = {0};
char Buff_485_2_Wr[BUFF_SIZE] = {0};
char Buff_485_2_Rd[BUFF_SIZE] = {0};
String latest_sent_msg;
int numOf485 = 0;
int returnTime = 0;
// ---------- 485
bool Wait_485_1;
int Wait_485_1_cnt;
int RS485_1_Addr[2] = {0,0};
bool RS485_1_Rcv_PV[2] = {false, false};
bool RS485_1_Rcv_SV[2] = {false, false};
int RS485_1_Rcv_size = 8;
int RS485_1_Values_PV[8*2];
int RS485_1_Values_SV[8*2];
bool Wait_485_2;
int Wait_485_2_cnt;
int RS485_2_Addr[2];
bool RS485_2_Rcv_PV[2];
bool RS485_2_Rcv_SV[2];
int RS485_2_Rcv_size = 8;
int RS485_2_Values_PV[8*2];
int RS485_2_Values_SV[8*2];
//bool rcv_10_PV = true;
//int Size_PV = 8;
//int Values_10_PV[8];
//bool rcv_10_SV = true;
//int Size_SV = 8;
//int Values_10_SV[8];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
@ -111,6 +68,7 @@ void loop() {
// If data read
if(message != ""){
cmd = demuxCMD(message, &cmdData);
//Serial.println(">> " + message);
message = "";
//Serial.println(cmd);

@ -14,6 +14,11 @@ void read_analog(){
for(i = 0 ; i < Size_AI ; i++){
Values_AI[i] = analogRead(AiPin[i]);
for(int j = 0; j < 9; j++) {
Recent_AI[i][j] = Recent_AI[i][j + 1];
}
Recent_AI[i][9] = Values_AI[i];
}
}

@ -6,6 +6,8 @@ const int MC9_CH[] = {1000, 1008, 1016, 1024, 1100, 1108, 1116, 1124};
void setupMC9_1(int i, int data){
RS485_1_Addr[i] = data;
Serial.println("MC9 No."+ String(i) + " 's address set as " + String(data));
}
String msg_MC9_PV(int addr){

@ -1,6 +1,6 @@
void Periodic_run(){
if(T_10ms){
read_analog();
T_10ms = false;
}
if(T_20ms){
@ -11,7 +11,7 @@ void Periodic_run(){
}
if(T_50ms){
// Read Arduino Inputs
read_analog();
read_digital();
T_50ms = false;
}

@ -3,8 +3,14 @@ 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++) {
sum_AI += Recent_AI[i][j];
}
char formattedNumber[5]; // 4자리 숫자 + 널 종료 문자
sprintf(formattedNumber, "%04X", Values_AI[i]); // 4자리로 고정된 형식의 문자열 생성
//sprintf(formattedNumber, "%04X", Values_AI[i]); // 4자리로 고정된 형식의 문자열 생성
sprintf(formattedNumber, "%04X", sum_AI); // 4자리로 고정된 형식의 문자열 생성
str += formattedNumber; // 형식화된 문자열 추가
str += ',';
}
@ -114,7 +120,7 @@ String Prcss_AT_Write(bool onOff){
String Prcss_RngAO(unsigned int data[], int dataSize){
String str = "RngAO!:";
int rng = 0;
int d = 20;
int d = 10;
for(int i=0 ; i<dataSize ; i++){
if(i+1 < dataSize){
rng = (data[i] > data[i+1]) ? data[i] : data[i+1];

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save