Firstly, let me say that I’ve learned a TON of things about embedded development from this community and after lurking in and out of the forums for some time, it’s now my turn to share some of the knowledge that I’ve acquired as a result.
This is also my first every write-up of any kind... so kindly let me know how I did!!!
Having a requirement for a 0-5V input to a 0-20mA output, I’ve arrived at the circuit contained within the attached .ZIP file (VtoI.png). This is by no means my final circuit (as there is always room for improvement) but it is what I’m using at the moment and it fills the need.
This circuit is comprised of two parts:
- The actual V to I converter (XTR111)
- The 12bit DAC (controlled via the NDP2’s SPI bus)
Let’s look at the first part:
The XTR111’s circuit is setup according to the device’s application notes. One minor change I’ve implemented is the ability to trim the output current so that at 0.000V input you’d get 0.000mA as well as being able to adjust the output to 20.000mA when the Vin pin has 5.000V applied it.
And the 2nd part:
The LTC1257 DAC is a 12bit device capable of outputting 0.000V to Vref volts (there is a limitation to this. Please refer to the device’s datasheet for complete details). The DAC itself requires a 12bit “WORD” in order to operate. A 12bit “WORD” in this case is the lower 3 nibbles of 2 bytes.
To set the DAC’s output to the desired voltage level, you need only do the following:
- Apply 5.000V to Vref (the more accurate your Vref voltage, the more accurate your output voltage will be).
- Use the following formula to calculate the desired output level (refer to the source code example for greater detail)
- 4095 * dacOutputVoltage / Vref
- Write the value to the device via the SPI bus.
In order to calibrate the 0-20mA output, you simply need to set the DAC’s output to 5.000V and adjust the trim pot to give you 20.000mA at the Iout output (use an ammeter connected directly between the Iout and Iout return terminals).
It’s a pretty simple setup. Took me a couple of hours of “noodling” to get it right.
I’ve attached the source code, related datasheets and a simple schematic in order to complete this example.
Hope you enjoy reading this (and prototyping it?) as much as I had going through the excersise.