There are several ways to do it, but I would probably go for something like this;
The upper 4-bits for DAC channel A, with 2x gain, with A active, will remain constant. So create a constant like ASel CON 4096. This would be the following in 16-bit binary: %0001000000000000.
The lower 12-bits, with the 2 least significant bits ignored, + ASel would be your value to send to the DAC to adjust the channel A output.
Just use a word variable. Load your word variable with any value from 0 to 1023, then shift this left x 2 so the 2 LSBs are 0, then add the ASel constant for the value to shiftout.
Say your word var is ChanA, and it's = 501. ChanA = (ChanA << 2) + ASel.
501d = %0000000111110101. Shifted left x 2 it's %0000011111010100. When you add the ASel constant, it ends up being %0001011111010100.




Bookmarks