DAC smartpin use for dummies - Edit: Answered by the awesome forum folks!
I've looked, so far in vain, for a very simple code sample that shows, for example, how to set a pin to 1.65 volts. There is a massive amount of demo code for DAC use in the context of much larger code for VGA, HDMI, etc. but this is buried too deep in the overall flow for me to figure it out. Any language (though I would prefer FlexC) would be fine to help me understand how to perform this very likely simple task. I'm sure it's just a matter of wrpin, wxpin, wypin and maybe rdpin or something similar. Inline asm,pasm would be perfect - I can get into mailbox use, etc., after that. Baby steps.
Mike R...

Comments
The good news is its just a one liner, use WRPIN to set with your chosen dac (there are 4 impedances/ranges, P_DAC_124R_3V etc), ORed with an 8 bit value shifted left 8 bits
I'm about to run some dac tests this morning, will post working line for you
[deleted]
Actually wrong, the range is 0 to $FF00 ($FF01 to $FFFF are clamped down to $FF00)
Fine. You show him how to use the DACs.
Sorry if I came across as rude, just wanted to point it out the peculiarity (especially since the object you posted also doesn't account for it)
Here is a simple FlexC example to set a voltage of 1.65 V on two pins. One with the raw, built in 8 bit DAC, the other with smartpin dithering to 16 bit resolution, and with two different drive strength.
enum {_clkfreq = 180000000}; // pins: #define DAC8 24 #define DAC16 26 void main() { int daval; daval = 0xFF00 * 1650 / 3300; // 16bit dac value for voltage in mV // 8 bit DAC _pinl(DAC8); // make pin an output _wrpin(DAC8, P_DAC_124R_3V + (daval & 0xFF00)); // 8bit value in bits 15..8 // 16 bit DAC _pinstart(DAC16, P_DAC_DITHER_PWM + P_DAC_990R_3V + P_OE, 256, 0); // init smartpin _wypin(DAC16, daval); // write value while(1) ; // keep cog alive }Andy
I don't know either, but perhaps this can help you decipher it until someone else chimes in.
This is from Chip's VGA driver
wrpin dacmode_s,av_base_pin 'enable 123-ohm 3.3V dac mode in pin +0 xor av_base_pin,#2<<6|1 'enable 75-ohm 2.0V dac mode in pins +1..3 wrpin dacmode_c,av_base_pin ..... dacmode_s long %0000_0000_000_1011000000000_01_00000_0 'hsync is 123-ohm, 3.3V dacmode_c long %0000_0000_000_1011100000000_01_00000_0 'R/G/B are 75-ohm, 2.0V[deleted]
Easy up Jon,
Wuerfel may have been brief/curt but it wasn't intentionally so. He was pointing that detail out because it was something mentioned/discovered a year or so back. I vaguely remember it coming up. It's about the dither algorythm flatlining at $ff00 because there is no $10000 step to dither up to.
For sure that is an error of 0.4%, I don't think that matters much, if you think of the accuracy of the 3.3V supply.
But I'm still not sure if a value of $FF at the DAC results in
3.3Voutput or3.3V / 256 * 255. From Chips description of the DAC, I think all 255 resistors are connected to high, so it's 3.3V.Andy
Yes, DAC is rail (0) to rail (255). And yes, the numerical error of the dither is very small. And of course is easy to numerically correct when known about.
In case you didn't get running already, here's some tested PNUT asm code
mov dacval, #85 'dac value to output, 0 to 255 shl dacval, #8 'move mode and value bits up 8 as required by docs or dacval, dacmode2 'insert DAC mode bits wrpin dacval, #dacpin 'write DAC mode and value to pin drvh #dacpin 'enable nxtdac jmp #nxtdac dacval long 0 'temp register to construct output word incl DAC mode, value dacmode2 long %00010110_00000000_00000000 'dac mode 3v3 124RCould also use SETDACS. eg:
dat org wrpin dacmode2, #0 'config DAC mode on pin 0 dirh #0 'enable DAC on pin 0 mov dacval, #85 'dac value to output, 0 to 255 setdacs dacval nxtdac jmp #nxtdac dacval long 0 dacmode2 long %00010100_00000000_01_000000 'cog-dac mode, 3v3, 990R, cog 0PS: SETDACS uses the same DAC path as the streamer. So same pin config as used for VGA output for example.
Just to quantify this, on the 990R DAC, level 0 can be to about 3~4mV up from GIO, and similar for level 255 vs VIO. Most of the time that's not going to matter. Its proportionately better on the 124R dac, at around 0.64mV
A lot of this stuff is built into TAQOZ and if you wanted to use pin 8 and output 1,856 mV then all you need to do is say so:
8 PIN 1,856 mVUnlike all those stand-alone "demos" where you need to download it to try out stuff, with TAQOZ you just use it and interact with it, even combining it with other operations. Many "demos" are simply type and go from the console. For instance, there is no "WAV player demo" with TAQOZ since it is part of the the multimedia functions.
My sincere thanks to all of you for your quick and correct guidance. Due to the clues in all of the presented info I've been able to work backwards from a simple working example and am now much more comfortable in my understanding on how the smartpins work in DAC mode. You guys are great!
It's a pity there is no rule to first test how to reach what you want using TAQOS before moving forward to a more common approach like C. Every C-Programmer should be forced know inherently it's better to write a short abstract in TAQOS first to show in short what he want to verbosely express in the following. Hope to force myself ;-)
@ErNa , thanks for for striking out "be forced". I forced myself to program in Forth for six months, and I don't think I would want to be forced to do that again.
I am satisfied with programming in C, Pasm and Spin on the P2.
One must program with Forth, not in Forth. Use the Forth, don't force it, and may the Forth be with you.
My head really hurts every time I try to convert a program to Forth. It's possible, but it's hard work and it's ugly.
This was happening with Pacman but I stopped, stood back and looked at it and decided to approach it a completely different way. The way of the Forth. Now I scan whichever bitmap is supplied at the start of the level and identify objects from a key table and have immediate fun making Pacman move and munch while I interactively and incrementally give Inky, Blinky, Pinky and Clyde their personalities as well too etc.
I find if I'm not having fun, it's because I'm doing it the wrong way. Fun is it's own reward.
We also have these examples from Chip, which have not yet become P2 Quick Bytes.
Ken Gracey
As I thought about the wording I realized that I do not intend to program forth but I stop programming and start talking to my computer in a very formal way. I use words already known or those I coin myself and use the technology I use for cooking: mis a place and then act. In those days I loved my HP45 and as the majority stuck with the brackets of TI I felt a voice in the wilderness. I hope to show useful words and more and more users see follow the TAQOS path..... Unhappily I was too early to start with UNIX/LINUX and on the other hand the TRANSPUTER turned out to be a desaster. But that changed with the Propeller as the limited resources of Parallax prevented them to change things on the fly..