<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Maple DAC PT8211</title>
		<link>http://forums.leaflabs.com/topic.php?id=49773</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:04:19 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=49773" rel="self" type="application/rss+xml" />

		<item>
			<title>modmoiuoiu on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773#post-105730</link>
			<pubDate>Thu, 30 Apr 2015 23:40:38 +0000</pubDate>
			<dc:creator>modmoiuoiu</dc:creator>
			<guid isPermaLink="false">105730@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;can I kindly ask for the code using SPI.h... thanks a lot... &#60;/p&#62;
&#60;p&#62;Dat = is pin 3, Ws = 2, Clk = 1, TL = 7 on pt8211 not on micro-controller..&#60;/p&#62;
&#60;p&#62;datasheet for pt8211 is not very much documented... just the basics... &#60;/p&#62;
&#60;p&#62;can you also help with connections of those 4 pins on pt8211... &#60;/p&#62;
&#60;p&#62;thanks... I want to use it to control L9110s  ...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773&amp;page=2#post-104757</link>
			<pubDate>Fri, 11 Oct 2013 03:10:54 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">104757@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;pyrohaz - is their a capacitor, connected as a low-pass filter, on the output of the DAC shown in the oscilloscope picture at&#60;br /&#62;
&#60;a href=&#34;http://s747.photobucket.com/user/hazmatazz/media/P1010478.jpg.html&#34; rel=&#34;nofollow&#34;&#62;http://s747.photobucket.com/user/hazmatazz/media/P1010478.jpg.html&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;That weird stepping might be an artefact of the DAC, and might be removed with a low-pass filter. The datasheet should give more info.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773&amp;page=2#post-104749</link>
			<pubDate>Thu, 10 Oct 2013 17:37:56 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">104749@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I had a go at setting up the SPI using the spi.h functions but couldn't seem to get it to function correctly! Using the code at the top of this page also seems to produce the same kind of up/down stepped effect though too which is a bit of a shame! I think I'll just have to look into the data sheet a bit more and see if I can find any tricks!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773&amp;page=2#post-92841</link>
			<pubDate>Tue, 08 Oct 2013 10:21:04 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">92841@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;pyrohaz -what happens if the code does everything more slowly, slower SPI, longer delay between values?&#60;br /&#62;
What happens with your earlier 'bit banging' program (at the start of this thread)? &#60;/p&#62;
&#60;p&#62;I don't think this is the issue, but the RM0008 manual does say the DFF bit should only be set when SPI is disabled. That would mean only 8 bits of data are being sent, but I don't think the oscilloscope picture would look like it does.  That should also show up in the frequency of the sawtooth being way too high.&#60;/p&#62;
&#60;p&#62;What is:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;GPIOA_BASE-&#38;gt;BSRR = 1&#38;lt;&#38;lt;8;
GPIOA_BASE-&#38;gt;BRR = 1&#38;lt;&#38;lt;8;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;intended to do? It is quite a rapid toggle of a pin, potentially as fast as one cycle at 36MHz, which might be a bit too quick for that chip. It would be much slower if it were simply two digitalWrites, HIGH then LOW. Might that be too slow?&#60;/p&#62;
&#60;p&#62;It could be made slower by doing something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;GPIOA_BASE-&#38;gt;BSRR = 1&#38;lt;&#38;lt;8;
GPIOA_BASE-&#38;gt;BSRR = 1&#38;lt;&#38;lt;8;
GPIOA_BASE-&#38;gt;BSRR = 1&#38;lt;&#38;lt;8;
GPIOA_BASE-&#38;gt;BRR = 1&#38;lt;&#38;lt;8;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Tiny point, if A were defined as an int16, it would wrap within 16 bits naturally:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;int16 A = 0;
void loop(){
  GPIOA_BASE-&#38;gt;BSRR = 1&#38;lt;&#38;lt;8;
  GPIOA_BASE-&#38;gt;BRR = 1&#38;lt;&#38;lt;8;

  SPI2_BASE-&#38;gt;DR = A;
  A++;

  delayMicroseconds(1);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;That is a little sneaky, so would certainly need a comment, and it is very specific, hence you might want to ignore it completely.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773&amp;page=2#post-92596</link>
			<pubDate>Tue, 08 Oct 2013 09:10:25 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">92596@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Unfortunately, i'm back! I've whipped up a really dirty program to produce a sawtooth wave using this dac and I seem to be getting some pretty dodgy results. I've heard the saying monotonic before when it comes to DAC's though i'm not 100% sure on the meaning. if it is what I think it is, this DAC doesn't seem to do a particularly good job of being monotonic!&#60;/p&#62;
&#60;p&#62;I think that a picture explains better than 1000 words so here it is.&#60;br /&#62;
&#60;a href=&#34;http://i747.photobucket.com/albums/xx118/hazmatazz/P1010478.jpg&#34; rel=&#34;nofollow&#34;&#62;http://i747.photobucket.com/albums/xx118/hazmatazz/P1010478.jpg&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Sorry for the picture quality though it displays what is happening pretty well.&#60;/p&#62;
&#60;p&#62;The code to produce this is:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;spi.h&#38;gt;
HardwareSPI S(2);
int A = -32767;

void setup(){
  S.begin(SPI_18MHZ, MSBFIRST, SPI_MODE_0);
  SPI2_BASE-&#38;gt;CR1 &#124;= SPI_CR1_DFF_16_BIT;
  pinMode(27, OUTPUT);
}

void loop(){
  GPIOA_BASE-&#38;gt;BSRR = 1&#38;lt;&#38;lt;8;
  GPIOA_BASE-&#38;gt;BRR = 1&#38;lt;&#38;lt;8;

  SPI2_BASE-&#38;gt;DR = A;
  A++;
  if(A&#38;gt;32767){
    A = -32767;
    //A = 0;
  }
  delayMicroseconds(1);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I know its ugly and dirty code, its only to test this problem as the output should be a linear ramp, not some crazy jumping.&#60;/p&#62;
&#60;p&#62;Any ideas?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773&amp;page=2#post-80677</link>
			<pubDate>Sun, 06 Oct 2013 09:14:46 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">80677@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thank you all for the help! I had never thought of using a shift operator in a for loop declaration, sweet idea! While it probably isn't a big deal, I assume that it is generally more efficient. Placing an int directly into the SPI register also seems to work, its somewhat weird how this works but I have no problem!&#60;/p&#62;
&#60;p&#62;After making a simple DDS piece of code up, the DAC works in all of its glory! Its a really nice dac actually, unless I shift out the data from shift register with every word select toggle, the same piece of data is written to both outputs!&#60;/p&#62;
&#60;p&#62;Nonetheless, thanks for the help as per!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773#post-75497</link>
			<pubDate>Sat, 05 Oct 2013 18:07:02 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">75497@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ala42 - I would have been more accurate if I'd written &#34;the '&#38;gt;&#38;gt;' operator &#60;em&#62;requires&#60;/em&#62; a positive shift count&#34;; &#34;takes&#34; was sloppy English. I'll correct that.&#60;/p&#62;
&#60;p&#62;To quote Microsoft (what higher authority is there?-)&#60;br /&#62;
&#34;The result is undefined if the right operand of a shift expression is negative&#34;&#60;/p&#62;
&#60;p&#62;So, IMHO, it is reasonable to consider using an unsigned shift-count value for '&#38;lt;&#38;lt;' or '&#38;gt;&#38;gt;'&#60;br /&#62;
I think the observation that it doesn't work, &#60;code&#62;w&#38;gt;=0&#60;/code&#62; will always be true, might plant a helpful memory in some folks minds.&#60;/p&#62;
&#60;p&#62;As I wrote, it is only a thought, and no big issue.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773#post-75343</link>
			<pubDate>Sat, 05 Oct 2013 17:22:08 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">75343@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#38;gt;I believe the '&#38;gt;&#38;gt;' operator takes an unsigned shift-count.&#60;br /&#62;
There is no problem with defining the loop variable as int.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773#post-73912</link>
			<pubDate>Sat, 05 Oct 2013 13:33:28 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">73912@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;pyrohaz - Thanks for bring us all up to date. Great progress!&#60;/p&#62;
&#60;p&#62;A couple of thoughts.&#60;/p&#62;
&#60;p&#62;AFAICT, data is clocked in on the rising edge of the clock ( &#60;a href=&#34;http://www.princeton.com.tw/Portals/0/Product/PT8211_7.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.princeton.com.tw/Portals/0/Product/PT8211_7.pdf&#60;/a&#62; )&#60;br /&#62;
So it might be clearer to bracket the 'set data pin' with the correct clock transition:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;// clock data in on the rising edge of the clock
    digitalWrite(Clk, LOW);
    digitalWrite(Dat, (datar&#38;gt;&#38;gt;w)&#38;amp;1);
    digitalWrite(Clk, HIGH);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The '&#38;gt;&#38;gt;' operator requires a positive (or unsigned) shift-count (its effect is undefined for negative shift-counts).&#60;br /&#62;
So I have occasionally declared 'w' to be unsigned, and tried something like:&#60;br /&#62;
  &#60;code&#62;for(uint16 w = 15; w&#38;gt;=0; w--){&#60;/code&#62;&#60;br /&#62;
of course, that does not work, it is an infinite loop because 'w' can never get less than 0, it is unsigned!-)&#60;/p&#62;
&#60;p&#62;So I sometimes do this:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;for(uint16 mask = 0x8000; mask; mask&#38;gt;&#38;gt;=1 ){
...
    digitalWrite(Dat, (datar &#38;amp; mask)!=0 ? 1 : 0);
...
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;It can reverse the direction fairly easily:&#60;br /&#62;
&#60;code&#62;for(uint16 mask = 0x0001; mask&#38;amp;0xFFFF; mask&#38;lt;&#38;lt;=1 ){ ... }&#60;/code&#62;&#60;br /&#62;
Or do a subset of bits:&#60;br /&#62;
&#60;code&#62;for(uint16 mask = 0x2000; mask&#38;amp;0x3FFC; mask&#38;gt;&#38;gt;=1 ){ ... }&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;I don't believe it is an issue, just a small thought.&#60;/p&#62;
&#60;p&#62;Edit: I noticed futurlec:&#60;br /&#62;
&#60;a href=&#34;http://www.futurlec.com/Others/PT8211pr.shtml&#34; rel=&#34;nofollow&#34;&#62;http://www.futurlec.com/Others/PT8211pr.shtml&#60;/a&#62;&#60;br /&#62;
are selling the PT8211 for $0.45 each!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773#post-72948</link>
			<pubDate>Sat, 05 Oct 2013 11:14:53 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">72948@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Arr damn! Sorry guys, i've been stupid again. Turns out, you can write a negative number to it (I assume its to do with the fact the number is a twos complement etc.) Sorry!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Maple DAC PT8211"</title>
			<link>http://forums.leaflabs.com/topic.php?id=49773#post-72863</link>
			<pubDate>Sat, 05 Oct 2013 11:02:02 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">72863@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey guys, back again i'm afraid!&#60;/p&#62;
&#60;p&#62;I've purchased a couple of PT8211's off ebay and they have recently arrived, they are a cheap as hell SPI 16bit dac. &#60;/p&#62;
&#60;p&#62;While it does work with SPI, i've written a quick sketch following the protocol for left and right channel writing. I completely understand how crap this piece of code is and it is extremely slow, its just so I can get used to the workings of the dac.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;const char Dat = 4, Ws = 5, Clk = 6, TL = 7;
int A, C;
boolean B = 0;
void setup(){
  pinMode(Ws, OUTPUT);
  pinMode(Clk, OUTPUT);
  pinMode(Dat, OUTPUT);
  pinMode(TL, OUTPUT);
}

void loop(){
  A+=1000;
  C-=2000;
  if(A&#38;gt;65535){
    A = 0;
    digitalWrite(TL, B);
    B^=1;
  }
  if(C&#38;lt;1){
    C = 65535;
  }
  SD(A, C);
}

void SD(unsigned short datal, unsigned short datar){
  digitalWrite(Ws, LOW);
  digitalWrite(Clk, HIGH);
  digitalWrite(Clk, LOW);

  for(int w = 15; w&#38;gt;-1; w--){
    digitalWrite(Dat, (datar&#38;gt;&#38;gt;w)&#38;amp;1);
    digitalWrite(Clk, LOW);
    digitalWrite(Clk, HIGH);
  }

  digitalWrite(Ws, HIGH);
  digitalWrite(Clk, HIGH);
  digitalWrite(Clk, LOW);

  for(int w = 15; w&#38;gt;-1; w--){
    digitalWrite(Dat, (datal&#38;gt;&#38;gt;w)&#38;amp;1);
    digitalWrite(Clk, LOW);
    digitalWrite(Clk, HIGH);
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Now, for once, I plugged it in and it worked first time - an utter rarity. The problem lies in how the dac is writing the output. I've included in the code, a pin toggle everytime A resets to 0 from 65536. What I would expect is that this pin would toggle on the downward slope of a sawtooth wave (i'll include a pic). What it does though is that the pin toggles directly in the centre of waveform. Could anyone give me any heads up to why this is?&#60;/p&#62;
&#60;p&#62;In my project, it will only be mono so I can use the SPI nss to set the channel.&#60;/p&#62;
&#60;p&#62;Picture:&#60;br /&#62;
&#60;a href=&#34;http://i747.photobucket.com/albums/xx118/hazmatazz/P1010476.jpg&#34; rel=&#34;nofollow&#34;&#62;http://i747.photobucket.com/albums/xx118/hazmatazz/P1010476.jpg&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Cheers!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
