diff --git a/FC_InferfaceBoard/Analog_Out.ino b/FC_InferfaceBoard/Analog_Out.ino new file mode 100644 index 0000000..32f3d6b --- /dev/null +++ b/FC_InferfaceBoard/Analog_Out.ino @@ -0,0 +1,89 @@ +String AO_setup(int i, int Rng) { + + DFRobot_GP8403 AO; + bool needBegin = true; + bool needRng = true; + int twinRng = 0; + + if(i%2){ // Odd + twinRng = RngAO[i-1]; + }else{ // Even + twinRng = RngAO[i+1]; + } + + needBegin = (twinRng == 0); + + if(Rng > twinRng){ + needRng = true; + }else{ + needRng = false; + } + + if(i <= 1){ + AO = AO_0; + }else if(i <= 3){ + AO = AO_2; + }else if(i <= 5){ + AO = AO_4; + }else if(i <= 7){ + AO = AO_6; + }else if(i <= 9){ + AO = AO_8; + }else if(i <= 11){ + AO = AO_10; + }else if(i <= 13){ + AO = AO_12; + }else if(i <= 15){ + AO = AO_14; + } + + if(needBegin){ // If not begin yet + Serial.println("AO_0 init begin"); + while(AO.begin()!=0); + Serial.println("AO_0 init succeed"); + AO.setDACOutVoltage(0, 0); + AO.setDACOutVoltage(0, 1); + delay(20); + AO.store(); + } + if(needRng){ + if(Rng == 10){ + AO.setDACOutRange(AO.eOutputRange10V); + }else{ + AO.setDACOutRange(AO.eOutputRange5V); + } + } + RngAO[i] = Rng; +} + +String AO_Write(int i, int volt) { + + DFRobot_GP8403 AO; + int ch; + + if(i%2){ // Odd + ch = 1; + }else{ // Even + ch = 0; + } + + if(i <= 1){ + AO = AO_0; + }else if(i <= 3){ + AO = AO_2; + }else if(i <= 5){ + AO = AO_4; + }else if(i <= 7){ + AO = AO_6; + }else if(i <= 9){ + AO = AO_8; + }else if(i <= 11){ + AO = AO_10; + }else if(i <= 13){ + AO = AO_12; + }else if(i <= 15){ + AO = AO_14; + } + + AO.setDACOutVoltage(volt, ch); +} \ No newline at end of file diff --git a/FC_InferfaceBoard/FC_InferfaceBoard.ino b/FC_InferfaceBoard/FC_InferfaceBoard.ino index 8fe4c2b..62fb291 100644 --- a/FC_InferfaceBoard/FC_InferfaceBoard.ino +++ b/FC_InferfaceBoard/FC_InferfaceBoard.ino @@ -20,6 +20,7 @@ char Buff_485_Rd[BUFF_SIZE] = {0}; String latest_sent_msg; int numOf485 = 0; int returnTime = 0; + // ========== ========== Periodic Flags bool T_10ms = false; bool T_20ms = false; @@ -42,7 +43,7 @@ EthernetServer server(5025); EthernetServer web(80); unsigned long lastDataReceivedTime; -unsigned long timeoutPeriod = 5000; // 타임아웃 시간 (5초) +unsigned long timeoutPeriod = 5000; // 이더넷 타임아웃 시간 (5초) bool State_eth = false; @@ -54,16 +55,16 @@ int Wait_485_cnt; // ---------- I2C (Analog Output, DAC) DFRobot_GP8403 AO_0(&Wire,0x58); -DFRobot_GP8403 AO_1(&Wire,0x59); -DFRobot_GP8403 AO_2(&Wire,0x5A); -DFRobot_GP8403 AO_3(&Wire,0x5B); -DFRobot_GP8403 AO_4(&Wire,0x5C); -DFRobot_GP8403 AO_5(&Wire,0x5D); -DFRobot_GP8403 AO_6(&Wire,0x5E); -DFRobot_GP8403 AO_7(&Wire,0x5F); +DFRobot_GP8403 AO_2(&Wire,0x59); +DFRobot_GP8403 AO_4(&Wire,0x5A); +DFRobot_GP8403 AO_6(&Wire,0x5B); +DFRobot_GP8403 AO_8(&Wire,0x5C); +DFRobot_GP8403 AO_10(&Wire,0x5D); +DFRobot_GP8403 AO_12(&Wire,0x5E); +DFRobot_GP8403 AO_14(&Wire,0x5F); int voltOffset = 185; - +int RngAO[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // ========== ========== Processing // Read Datas @@ -100,7 +101,7 @@ void setup() { GPIO_setup(); //MC9_setup(); RS485_setup(); - GP8403_setup(); + //GP8403_setup(); // Timer set MsTimer2::set(10, timer_10ms); @@ -157,36 +158,54 @@ void loop() { if(cmd=="ALL?"){ client.print(Prcss_ALL_Read()); - }else if(cmd=="DO!"){ + } + // GPIO + else if(cmd=="DO!"){ dataSize = demuxNum(cmdData, data); client.print(Prcss_DO_Write(data, dataSize)); }else if(cmd=="DI?"){ client.print(Prcss_DI_Read()); - }else if(cmd=="AI?"){ - client.print(Prcss_AI_Read()); - }else if(cmd=="AO!"){ dataSize = demuxNum(cmdData, data); client.print(Prcss_AO_Write(data, dataSize)); - }else if(cmd=="PV?"){ - client.print(Prcss_PV_Read()); + }else if(cmd=="AI?"){ + client.print(Prcss_AI_Read()); + + } + // MC9 + else if(cmd=="SV!"){ + dataSize = demuxNum(cmdData, data); + client.print(Prcss_SV_Write(data, dataSize)); }else if(cmd=="SV?"){ client.print(Prcss_SV_Read()); - }else if(cmd=="SV!"){ - Serial.println(cmdData); - dataSize = demuxNum(cmdData, data); - client.print(Prcss_SV_Write(data, dataSize)); + }else if(cmd=="PV?"){ + client.print(Prcss_PV_Read()); }else if(cmd=="ATon!"){ client.print(Prcss_AT_Write(true)); + }else if(cmd=="AToff!"){ client.print(Prcss_AT_Write(false)); + } + // Init + else if(cmd=="State?"){ + + }else if(cmd=="RngAO!"){ + dataSize = demuxNum(cmdData, data); + client.print(Prcss_RngAO(data, dataSize)); + + }else if(cmd=="ChMC9!"){ + dataSize = demuxNum(cmdData, data); + //client.print(Prcss_ChMC9(data, dataSize)); + + } + //else if(cmd==""){ //} diff --git a/FC_InferfaceBoard/GP8403.ino b/FC_InferfaceBoard/GP8403.ino index af8a210..171499f 100644 --- a/FC_InferfaceBoard/GP8403.ino +++ b/FC_InferfaceBoard/GP8403.ino @@ -1,33 +1,5 @@ -void GP8403_setup() { - - while(AO_0.begin()!=0){ - Serial.println("AO_0 init error"); - delay(1000); - } - Serial.println("AO_0 init succeed"); - //Set DAC output range - AO_0.setDACOutRange(AO_0.eOutputRange5V); - //Set the output value for DAC channel 0, range 0-5000 - AO_0.setDACOutVoltage(0, 0); - delay(100); - //Store data in the chip - AO_0.store(); - - - while(AO_1.begin()!=0){ - Serial.println("AO_1 init error"); - delay(1000); - } - Serial.println("AO_1 init succeed"); - //Set DAC output range - AO_1.setDACOutRange(AO_0.eOutputRange10V); - //Set the output value for DAC channel 0, range 0-5000 - AO_1.setDACOutVoltage(0, 0); - delay(100); - //Store data in the chip - AO_1.store(); -} + DFRobot_GP8403::DFRobot_GP8403(TwoWire *pWire,uint8_t addr) { diff --git a/FC_InferfaceBoard/Processes.ino b/FC_InferfaceBoard/Processes.ino index 5f33a91..aa89f1f 100644 --- a/FC_InferfaceBoard/Processes.ino +++ b/FC_InferfaceBoard/Processes.ino @@ -93,26 +93,12 @@ String Prcss_AI_Read(){ String Prcss_AO_Write(unsigned int data[], int dataSize){ String str = "AO!:"; int t = millis(); - for(int i=0 ; i