With the interpolation routine from the last log entry linearizing the DCDC converter output is simple. It doesn't really matter how the function looks like: the grid point density can be adjusted to match the second derivative. In a first example, I simply used a voltmeter and the interactive Forth console to map PMW values to the output voltage. It turned out that between 0 and 1V the function is less smooth, and I inserted an extra grid point. Also, below 20mV I couldn't reliably control the output voltage (after all, a bias to the feedback ground of an LM2596 is a hack :-) ), so I set the last grid point to 469/20mV.
I decided to represent the voltage in units of mV, and created the following table with 14 grid points:
FILE NVM CREATE vptab 14 , 469 20 , , 451 500 , , 434 1010 , , 401 2000 , , 367 3010 , , 333 3990 , , 297 5010 , , 261 5990 , , 222 7010 , , 183 7990 , , 141 8990 , , 97 9990 , , 50 11000 , , 0 12000 , , RAM HAND
The mapping of output voltage to PWM is simple:
FILE NVM
: mV vptab @inter pwm ;
RAM HAND
By typing eg. 7500 mV I get an output voltage of 7.53V, which is more accurate than I had ever expected. I observed some drift, but as there is nothing like reference voltage source, what can you expect?
Here are more examples:
5000 mV -> 5.02V
3700 mV -> 3.73V
3300 mV -> 3.35V
2800 mV -> 2.83V
Through the saturation feature of @inter the following works, too:
15000 mV -> 12.00V
-10000 mV -> 0.03V
Once more: level up!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.