not sure I I understood well what u trying to do... are using using only the MCP4725 or the interface boad on that link?
you are doing 2 actions here:
(1)set pressure
(2) output current
The second is pretty straight forward especially if you get round trying the current transmitter example that's on the webpage.
For (1) I'm assuming that the arduino sets the pressure measurement as a 4-20mA current... so for example with pressure range of 0-20bars, based on the current transmitter example, to get the 4-20mA range, 0bar == 290 and 20bar == 1500.
You can map for voltage range using the 'map' function OR write your own y=mx + c function.
RUE:
I casted the float value into 4 bytes, as you can see in the code below:
float p= 9.2047
union {
byte p Inbytes[4];
}myunion
Not with that code you didn’t. The float variable ‘p’ is totally distinct from the byte array ‘p’ in the union. No connection whatsoever. You’re also missing a ‘;’ after ‘myunion’.
I am still a little bit confused so I'll try to summarize the steps and please, correct me if I made some mistake.
1)Measure pressure from 0 to 20bar(float values)
2)Map the pressure values(0-20bar) to voltage value (0-5V). Could I do this with float?
3) Write the value to DAC
4)Obtain the value in mA
I am still a little bit confused so I'll try to summarize the steps and please, correct me if I made some mistake.
1)Measure pressure from 0 to 20bar(float values)
2)Map the pressure values(0-20bar) to voltage value (0-5V). Could I do this with float?
3) Write the value to DAC
4)Obtain the value in mA
Ok... I'm afraid I'm gonna have to reply with more questions!
1)Measure pressure from 0 to 20bar(float values) -> HOW is your are arduino reading pressure (analog voltage, pulses, SPI...)? surely not by pressing on it!
2)Map the pressure values(0-20bar) to voltage value (0-5V). Could I do this with float? -> why are you so focused on this point; yes you can using y=mx+c but its irrelevant for now... (1) will really dictate how to get the data to the DAC
for (3) and (4) are mentioned there is already an example on that link you posted explain what values to send to the DAC to get a 4-20mA output
No problem, for me it is important to clearly understand
sherzaad:
1)Measure pressure from 0 to 20bar(float values) -> HOW is your are arduino reading pressure (analog voltage, pulses, SPI...)? surely not by pressing on it!
Sorry, I measure the pressure using a pressure sensor.
The communication between Arduino and the sensor is via RS485 half duplex and the protocol is Modbus RTU. I read directly the pressure values from the UART.
2)Map the pressure values(0-20bar) to voltage value (0-5V). Could I do this with float? -> why are you so focused on this point; yes you can using y=mx+c but its irrelevant for now... (1) will really dictate how to get the data to the DAC
My sensor measures from 0-20bar. How can I pass the sensor output to the DAC and get the final mA signal?
So you read the the pressure sensor with UART... good... next question if for example the pressure is 1.23bar, what is the UART data read? what does the datasheet say about the data stucture of the UART data; is it a float number that you receive as 4 bytes? if it an integer value? is it ASCII characters?
sorry to be a pain but asking all those qestions coz as I said that will dictate know to convert/pass that value to the 4-20mA current transmitter.
Which part are you having issues with? Sending the value to the DAC or scaling to the DAC value?
How to send the value is in the example you posted already.
As for scaling, think in terms of percent of range. What percent of the pressure range is you desired setpoint? The range is 0-20 bar, your setpoint 9.02. 9.02/20.0= 45.1%. From the example you linked for the device, the range is 290-1500 or 1210. So 45.1% of 1210 is 545. Since the range starts at 290, add 290 to that result, 835. Send 835 to the DAC (see the example you linked already).
The actual complete formula is
DAC Output = (Setpoint - Setpoint minimum)/(Setpoint maximum - Setpoint minimum) * (Output Maximum - Output Minimum) + Output Minimum
For your example that becomes:
(9.02 - 0) / (20 - 0) * (1500 - 290) + 290 = 835
RUE:
I read from sensor two information pressure and temperature.
Each info is 4bytes stored in an array of [4].
Pfinal is the info to pass to the DAC.
Here you are the code I am using to read sensor.
//Shift and Cast pressure to float
unsigned long temp1 = (unsigned long) readRegs[0] << 16 | readRegs[1];
p = (float)&temp1;
I really can't figure out how to pass pfinal to DAC of the board transmitter and get the mA transformation.
What adwsystems is what I have told you right at the very start in more words and added an example for your understanding.
I am however now concerned about how you are retrieving the float value for pressure and temperature; did you test that code to see whether or not you are getting the RIGHT values?
(using one of those sensors by any chance? DCT 531 Modbus RTU RS485 Pressure Sensor)
If you are getting the right values ignore what I say next!
coz "Each info is 4bytes stored in an array of [4]" NOT TRUE! Each info2 (temp1 and temp2) is 2 bytes long ie they are float16 (2 bytes) not the typical float which is 4 bytes(float32).
I dont expect that you are getting the right pressure value with this casting: "p = (float)&temp1;"
you need to get you input readings right before applying what both I and adwsystems said on how to use that value to set your 4-20mA transmitter