@@ -28,14 +28,23 @@ The library is experimental as not all functionality is tested with hardware.
2828
2929Check datasheet for all details.
3030
31- The AD7390 has a Vref input which can be set to any voltage between 0 and Vdd (2.7 .. 5.5 Volt.
32- This allows the output to vary between 0 volt and approx. Vref -1 LSB.
31+ The AD7390 has a Vref input which can be set to any voltage between 0 and Vdd = 2.7 .. 5.5 Volt.
32+ This allows the output to vary between 0 volt and approx. Vref -1 LSB.
33+ The AD7390 can do this in 4096 levels, the AD7391 has 1024 levels.
34+
3335See datasheet page 8.
3436
35- The device does not support reading the set value, so the library caches the
36- last value set to provide this.
37- Furthermore the library provides a "percentage" functions to set and get the output
38- in a range from 0 to 100.0 %.
37+ The device does not support reading back the set value, so the library caches the
38+ last value set to mimic this functionality.
39+
40+ Furthermore the library provides "percentage" wrapper functions to set and get the
41+ output in a range from 0 to 100.0 %. Note that setPercentage() will round to the
42+ nearest valid integer value.
43+
44+ Finally the library provides "voltage" wrapper functions to set and get the
45+ output in a range from 0 to Vref. Note that setVoltage() will round to the nearest
46+ valid integer value. Be aware that the actual Vref must be set by setRefVoltage()
47+ and kept in sync with the actual voltage to have the voltage functions work correctly.
3948
4049As always feedback is welcome.
4150
@@ -72,7 +81,26 @@ Mainly other DAC libraries.
7281
7382## Performance
7483
75- TODO
84+ Times in microseconds per 1000 calls.
85+
86+ | mode | function | UNO R3 | ESP32 | notes |
87+ | :------:| :----------------| :--------:| :-------:| :--------|
88+ | HW-SPI | setValue | 15404 | |
89+ | HW-SPI | getValue | 884 | | cached value
90+ | HW-SPI | setPercentage | 93764 | |
91+ | | | | |
92+ | SW-SPI | setValue | 204332 | |
93+ | SW-SPI | getValue | 884 | | cached value
94+ | SW-SPI | setPercentage | 282692 | |
95+
96+
97+ Note: 15404 micros for 1000 calls, means the max update speed
98+ is in the order of 60k calls per second in theory.
99+ In practice one needs to calculate values or read them from some source,
100+ or do other tasks. So actual speeds depends on your project.
101+
102+ The setPercentage and setVoltage functions have additional overhead
103+ due to the use of float math.
76104
77105
78106## Interface
@@ -108,12 +136,31 @@ Returns false if value > maxValue.
108136
109137### Percentage
110138
139+ Wrapper functions.
140+
111141- ** bool setPercentage(float percentage)** sets the value of the DAC as percentage 0..100.
112142Note the actual value set gets rounded.
113143Returns false if percentage < 0 or > 100.
114144- ** float getPercentage()** returns the percentage set, calculated from the value.
115145The percentage can differ a small bit from the percentage set.
116146
147+ ### Voltage
148+
149+ Wrapper functions.
150+
151+ Before calling ** setVoltage()** one must set the reference voltage correctly,
152+ otherwise the functions do not work.
153+ The user is responsible to keep ** setRefVoltage()** in sync with the actual Vref.
154+
155+ - ** bool setRefVoltage(float volts)** set Reference Voltage of Vref pin.
156+ Returns false if volts is out of range 0..5.5 Volt.
157+ - ** float getRefVoltage()** return last set Reference Voltage, default 0.
158+ - ** bool setVoltage(float volts)** sets the value of the DAC as a voltage 0..Vref.
159+ Note the actual value set gets rounded.
160+ Returns false if volts is out of range 0..Vref.
161+ - ** float getVoltage()** returns the voltage set, calculated from the value.
162+ The voltage can differ a small bit from the voltage set.
163+
117164### Hardware SPI
118165
119166To be used only if one needs a specific speed for hardware SPI.
@@ -137,16 +184,24 @@ Has no effect on software SPI.
137184
138185#### Should
139186
140- - add reference voltage functions. (See .h)
141187- extend unit tests
142- - add examples
143188
144189#### Could
145190
191+ - ** getLastUpdate()** track millis
192+ - if new value == cached value skip
193+ - optimize AVR SW SPI
194+ - optimize float math setPercentage() and setVoltage()
195+ - calculate and cache the conversion Pfactor and Vfactor. (8 bytes)
196+ - remove range test as setValue() does this?
197+ - test SW-SPI with 0x0800 mask (clock only 12 bits does that work).
198+ - add examples
146199
147200#### Wont
148201
149-
202+ - build in low pass filter (too complex)
203+ - should percentage and voltage API clip or fail if out of range?
204+ - fail seems safest.
150205
151206## Support
152207
0 commit comments