DAC smartpin use for dummies - Edit: Answered by the awesome forum folks!
pmrobert
Posts: 673
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.
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
[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.3V
output 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
Could also use SETDACS. eg:
PS: 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 mV
Unlike 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..