In SX Microcontrollers, SX/B Compiler and SX-Key Tool, PJMonty wrote: Bean, Cool idea. However, I [i]think[/i] it's easier do than you think it is. Imagine that you have a theoretical 3 bit DAC, but treat it as a DAC that can only output up to the highest binary value. This would mean from %000 to %100. Now, imagine that you simply wanted to double the output range of this DAC using your method. We want to turn 0-4 into 0-8. Divide 8 by 4 and you get 2. Now suppose you want to generate the value for 7. Well, 7/2 = 3.5, thus we toggle equally between 3 (%011) and 4 (%100). All other values follow suit, e.g. 5/2 = 2.5, so toggle between 2 and 3. Now lets increase the output range further. Lets turn 0-4 into 0-16. 16/4 = 4, so there are 4 in between steps, so our PWM rate is now 4X. To output 15, do 15/4 = 3.75. We need to toggle between 3 and 4, only we output the value 4 three times and 3 once. To output 14, we have 14 / 4 = 3.5. This means output 3 twice and 4 twice. 13 /4 = 3.25, so output 13 three times and 14 once. 12 / 4 = 3, so simply output 3 all four times. This approach will scale up to your 256 levels just fine. The key is to "throw away" some of the DAC's potential resolution in favor of making the math simple. Remember, even though we talk about 8 bit DACs having 256 levels, zero is a legitimate value and thus the top end is 255, not 256. By treating the DAC as if it has a top value equal to the highest binary power, we get to do simple bit shift division, yet still get all the output values we want. I think you can also simplify this in that the pattern will repeat itself for all the values in between any two real numbers. In other words, for our 0-16 output level DAC (which can be capped at 0-15 via software if you want), we found the following pattern for the values 12 - 15: 15 = 4 (3X) and 3 (1X) 14 = 4 (2X) and 3 (2X) 13 = 4 (1X) and 3 (3X) 12 = 4 (4X) and 3 (0X) Now lets look at the pattern for 8 - 11 11 = 3 (3X) and 2 (1X) 10 = 3 (2X) and 2 (2X) 09 = 3 (1X) and 2 (3X) 08 = 3 (4X) and 2 (0X) It's identical, except instead of toggling between 4 and 3, we toggle between 3 and 2. This pattern will continue all the way to the bottom. In other words, you can make a simple lookup table for the inbetween values and it applies to any two actual DAC numbers. Thanks, PeterM ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=366927#m366963 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)