In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: Alex, the simplest DAC you can realize with the SX is a PWM output, filtered by an RC low-pass. The 8-bit code looks like this: [code] add DACAcc, DACVal movb DACOut, C [/code] But these instructions inside a loop, or have them periodically executed by an ISR. The output signal (without the filter) will be a square wave with a duty cycle from 0 up to almost 100%, depending on the contents of DACVal. With the filter, the voltage across the capaitor will be from 0 to almost 5 Volts. If you like, you can expand this into a 16-bit version like this: [code] add DACAccL, DACValL mov w, #1 snc add DACAccH, w add DACAccH, DACValH movb DACOut, C [/code] Two bytes are here used for DACAcc and for DACVal. When the addition of DACAccL and DACValL overflows, i.e. when carry is set, you need to increment DACAccH by one. You can't use addb DACAccH, c, or inc DACAccH to achieve this because both instructions don't set the carry in case they cause an overflow in DACAccH. This is why I use w to add 1 to DACAccH when c is set. If this version is good enough for your project depends on the response time you need, and the 16-bit version is a lot slower than the 8-bit version but you might give it a try. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=242012#m242719 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)