In short: HW-685 board malfunctions everytime Arduino #2 board is connected to PC via USB and 4-20mA generated with XTR105 IC drops everytime Arduino #2 DAC is connected to Arduino #1 via analog port.
Hello there,
I've been trying to interface an Arduino Due with industrial equipments and controllers that mainly communicate with analog 4-20mA.
The main idea is to, for example, develop a PID controller on simulink, generate C/C++ code, upload it to the Arduino Due and connect it to a real industrial process that uses 4-20mA as input and as feedback from a transmitter. This DUE should be able to send 4-20mA proportional to the virtual PID output and read an analog voltage proportional to the 4-20mA feedback from the transmitter.
Or, I could develop a mathematical model of an industrial process on simulink, upload it to the DUE in order to control it in real time with a physical controller, using the same methods.
Or even use two arduino DUEs, one with a PID controller and the other with an industrial process, both simulated in real time and one controlling the other.
For that, the DUEs should have at least two types of signal converter circuits:
1) Voltage to Current: Since i'm using the DUEs DACs, i should convert 0.55-2.75V to 4-20mA.
2) Current to Voltage: The DUE's input voltage range it 0-3.3V, so, i need to convert 4-20mA to 0-3.3V.
I'm working with two solutions for these circuits. For circuit 1 I'm using the IC XTR105 to generate the current and for circuit 2 i'm using the HW-685 board. Both are actually working well (isolated) so far.
The problem is, since I don't have any industrial equipment in my house and my university is closed due to COVID, it is hard to test the whole thing with everything working at the same time. I'm having to test it using the last example that I gave (two DUEs, one acting as a controller and the other as a process). I'm trying to use every circuit and I know that when using two Arduino DUEs, using all of that voltage to current and then current to voltage is definetely not needed, but since I will need all of this for the industrial equipment, I'm trying to make sure everything is working properly.
Please, refer to the attachment "test_circuit.png" to better understand the following part.
Since I'm trying to test the analog communication, I'm not uploading any C/C++ controller code to the board, Instead, I'm using a potentiometer to generate a virtual 4-20 scale and taking that and writing in the DAC0 of Arduino #1. This gives me a 0.55-2.75V as an ouput for Arduino #1.
Using the XTR105 circuit I can generate 4-20mA proportional to this 0.55-2.75V scale. But for that, I need to power the IC with an external DC power supply higher than 9V.
The output current from the XTR105 would be connected to, let's say, a valve that is restraining the flow of a liquid to fill a tank up. And a level transmitter would output 4-20mA proportional to the liquid level. I would take this output scale and hook it to the HW-685 board that converts it to 0-3.3V, making it possible to close the loop with the DUE.
But, since I don't have none of this equipment at home, I'm trying to send this output current directly to the HW-685 board and hooking the output voltage to another DUE (Arduino #2).
My first test would be to take a look at the serial monitor of Arduino #2 to see if I'm reading 0-4095 if I use AnalogReadResolution(12) (0-4095 would be proportional to the output 0-3.3V from HW-685). But here, the first problem arrives: as you can see, I need to power up the second Arduino with an external power supply to provide enough voltage for the HW-685 board (through Vin port). It seems like it is working, but whenever I connect the USB cable to the PC (in order to check the serial monitor), the HW-685 stops working properly (the output voltage of the board drops) as if there is some problem with the supply voltage. I can't understand why this is happening since the Vin port should provide the highest voltage that the board is receiving (external power supply in this case). I'm suspecting the board is with some kind of problem and needs to be replaced, so I bought two more DUEs and I'm waiting for them to arrive to test it.
To keep the tests going, I connected a LED to Arduino #2 and i'm varying it brightness with the HW-685 output voltage. This is to get some kind of visual feedback of the way Arduino #2 is interpreting the converter board output.
Since I need to understand if the feedback loop works (have a signal from Arduino #2, proportional to the signal from Arduino #1, returning to Arduino #1), I'm connecting DAC1 of Arduino #2 to Arduino #1 to check its serial monitor. At the end, I was expecting to turn potentiometer in Arduino #1 and see the voltage coming form Arduino #2 varying proportionally. But here comes the second problem: whenever I connect the GND from Arduino #2 to Arduino #1, the 4-20mA current output from the XTR105 circuit drops. It seems like something is consuming this current, but I can't see what. I'm even able to see a variable scale in the serial monitor, but it is not correct since the current from xtr105 scale drops (I'm able to see the current via power suppler display).
If someone needs to check the XTR105 circuit, please refer to the attachment "xtr105.png"
Below, I'm putting the codes from Arduinos #1 and #2. I understand there are a lot of thing that are not necessary in this codes like the conversion from 0-4095 to 4-20 and then the backwards conversion, but I was expecting it to work even with these kind of things.
ARDUINO #01 CODE:
int pot = A0;
void setup() {
Serial.begin(9600);
pinMode(pot,INPUT);
pinMode(A9,INPUT);
pinMode(DAC0, OUTPUT);
}
void loop() {
analogReadResolution(12);
analogWriteResolution(12);
EnviaSinal(DAC0, LeSinal(pot, 0));
Serial.println(analogRead(A9));
}
float EnviaSinal(int pino_escrita, float entrada){
//Função que escalona o sinal de 4-20 para 0-4095 (0-3.3V) e escreve no pino_escrita
//que deve ser um dos DACS (0.55-2.75V)
float sinal = (4095.0/16.0)*(entrada - 20.0) + 4095.0;
analogWrite(pino_escrita, sinal);
}
float LeSinal (int pino_leitura, float offset){
//Função que le o sinal de 0-4095 (0-3.3V) e escaolona para 4-20
float sinal = (analogRead(pino_leitura) - 4095.0)*(16.0/4095.0) + 20.0;
if (sinal < 3.95) {sinal = 4.0;}
if (sinal > 19.95) {sinal = 20.0;}
return sinal + offset;
}
ARDUINO #02 CODE:
void setup() {
Serial.begin(9600);
pinMode(A8,INPUT);
pinMode(2, OUTPUT);
pinMode(DAC1, OUTPUT);
}
void loop() {
analogReadResolution(12);
analogWriteResolution(12);
analogWrite(2, analogRead(A8));
analogWrite(DAC1, analogRead(A8));
}
I kindly ask for advices on these problems and I'm open to suggestions and critics on the solutions I'm implementing.
wiring_V2.pdf (109 KB)