<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DAC 10 Bit data buffer in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/DAC-10-Bit-data-buffer/m-p/1381583#M47254</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As the following void GenerateMultiTone (struct wave *t), there is complex shifting operation, I suppose that the long output&amp;nbsp; variable has&amp;nbsp; 25 valid bits, that is why there is 10 bits right shift operation so that it matches with the DAC format:&lt;/P&gt;
&lt;P&gt;DAC-&amp;gt;DACR = ((output &amp;gt;&amp;gt; 10) &amp;amp; 0xFFC0) + 0x8000; // make unsigned and output to DAC&lt;/P&gt;
&lt;P&gt;Pls debug the code step by step so that you can see the valid bits of the variables.&lt;/P&gt;
&lt;P&gt;Hope it can help you&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;XiangJun Rong&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xiangjun_rong_0-1638757484315.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/164096i40D25A47E8F063BD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xiangjun_rong_0-1638757484315.png" alt="xiangjun_rong_0-1638757484315.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;void GenerateMultiTone (struct wave *t) &lt;BR /&gt;{&lt;BR /&gt;long y;&lt;BR /&gt;unsigned char i;&lt;BR /&gt;unsigned char env_weights;&lt;BR /&gt;output = 0; // clear output accumulator &lt;BR /&gt;for (i=0;i&amp;lt;5;i++) // cycle through the 5 structures in the array&lt;BR /&gt;{&lt;BR /&gt;y = ((t-&amp;gt;coef *(long long)(t-&amp;gt;y1)&amp;gt;&amp;gt;14)) - t-&amp;gt;y2; // Goertzel Calculation&lt;BR /&gt;t-&amp;gt;y2 = t-&amp;gt;y1; // store for next time&lt;BR /&gt;t-&amp;gt;y1 = y; // store for next time&lt;BR /&gt;env_weights = envelope * ToneWeights[i]&amp;gt;&amp;gt;8;&lt;BR /&gt;output += ((t-&amp;gt;y1* env_weights)&amp;gt;&amp;gt;8); // sum fundamental and harmonics&lt;BR /&gt;t++; // increment structure pointer&lt;BR /&gt;}&lt;BR /&gt;DAC-&amp;gt;DACR = ((output &amp;gt;&amp;gt; 10) &amp;amp; 0xFFC0) + 0x8000; // make unsigned and output to DAC&lt;BR /&gt;if ((output &amp;gt;= 0)&amp;amp;&amp;amp; (output_old &amp;lt;= 0)) // zero crossing detect&lt;BR /&gt;{&lt;BR /&gt;if (envelope_off &amp;amp;&amp;amp; (note_on==0))&lt;BR /&gt;{&lt;BR /&gt;envelope_on = 0; // sychronizes turn off with zero cross&lt;BR /&gt;envelope_off = 0; // reset envelope flag &lt;BR /&gt;}&lt;BR /&gt;} &lt;BR /&gt;output_old = output;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 02:26:09 GMT</pubDate>
    <dc:creator>xiangjun_rong</dc:creator>
    <dc:date>2021-12-06T02:26:09Z</dc:date>
    <item>
      <title>DAC 10 Bit data buffer</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/DAC-10-Bit-data-buffer/m-p/1381312#M47237</link>
      <description>&lt;P&gt;I have come across a piece of code on NXP website (ZIP file attched) which has been written for an LPC1700 micro controllers.&lt;/P&gt;&lt;P&gt;the software is very simple and aims to generate Audible medical alarms.&amp;nbsp;&lt;/P&gt;&lt;P&gt;These micros family have a 10 bit DAC which means data buffer is 10 bit wide and can't take any value greater than 0x400.&lt;/P&gt;&lt;P&gt;looking at the code, file multi_tone_gen.c --&amp;gt; GenerateMultiTone (struct wave *t) ;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DAC-&amp;gt;DACR = ((output &amp;gt;&amp;gt; 10) &amp;amp; 0xFFC0) + 0x8000;&amp;nbsp; // make unsigned and output to DAC&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the code the input to&amp;nbsp; DAC buffer is always greater than 0x400.&amp;nbsp;&lt;/P&gt;&lt;P&gt;what am I missing here, am I just supposed to scale it down?&lt;/P&gt;&lt;P&gt;Note that I have ported this code into a PIC32 micro with 10 bit DAC module. it sounds the right melodies but it is not smooth. there is a roughness in the sound. when I scale down the input to the DAC buffer and lower it down to less than 0x400, the sounds get improved but still has that roughness in it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea what I am doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 14:46:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/DAC-10-Bit-data-buffer/m-p/1381312#M47237</guid>
      <dc:creator>_ZZ_</dc:creator>
      <dc:date>2021-12-03T14:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: DAC 10 Bit data buffer</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/DAC-10-Bit-data-buffer/m-p/1381583#M47254</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As the following void GenerateMultiTone (struct wave *t), there is complex shifting operation, I suppose that the long output&amp;nbsp; variable has&amp;nbsp; 25 valid bits, that is why there is 10 bits right shift operation so that it matches with the DAC format:&lt;/P&gt;
&lt;P&gt;DAC-&amp;gt;DACR = ((output &amp;gt;&amp;gt; 10) &amp;amp; 0xFFC0) + 0x8000; // make unsigned and output to DAC&lt;/P&gt;
&lt;P&gt;Pls debug the code step by step so that you can see the valid bits of the variables.&lt;/P&gt;
&lt;P&gt;Hope it can help you&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;XiangJun Rong&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xiangjun_rong_0-1638757484315.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/164096i40D25A47E8F063BD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xiangjun_rong_0-1638757484315.png" alt="xiangjun_rong_0-1638757484315.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;void GenerateMultiTone (struct wave *t) &lt;BR /&gt;{&lt;BR /&gt;long y;&lt;BR /&gt;unsigned char i;&lt;BR /&gt;unsigned char env_weights;&lt;BR /&gt;output = 0; // clear output accumulator &lt;BR /&gt;for (i=0;i&amp;lt;5;i++) // cycle through the 5 structures in the array&lt;BR /&gt;{&lt;BR /&gt;y = ((t-&amp;gt;coef *(long long)(t-&amp;gt;y1)&amp;gt;&amp;gt;14)) - t-&amp;gt;y2; // Goertzel Calculation&lt;BR /&gt;t-&amp;gt;y2 = t-&amp;gt;y1; // store for next time&lt;BR /&gt;t-&amp;gt;y1 = y; // store for next time&lt;BR /&gt;env_weights = envelope * ToneWeights[i]&amp;gt;&amp;gt;8;&lt;BR /&gt;output += ((t-&amp;gt;y1* env_weights)&amp;gt;&amp;gt;8); // sum fundamental and harmonics&lt;BR /&gt;t++; // increment structure pointer&lt;BR /&gt;}&lt;BR /&gt;DAC-&amp;gt;DACR = ((output &amp;gt;&amp;gt; 10) &amp;amp; 0xFFC0) + 0x8000; // make unsigned and output to DAC&lt;BR /&gt;if ((output &amp;gt;= 0)&amp;amp;&amp;amp; (output_old &amp;lt;= 0)) // zero crossing detect&lt;BR /&gt;{&lt;BR /&gt;if (envelope_off &amp;amp;&amp;amp; (note_on==0))&lt;BR /&gt;{&lt;BR /&gt;envelope_on = 0; // sychronizes turn off with zero cross&lt;BR /&gt;envelope_off = 0; // reset envelope flag &lt;BR /&gt;}&lt;BR /&gt;} &lt;BR /&gt;output_old = output;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 02:26:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/DAC-10-Bit-data-buffer/m-p/1381583#M47254</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2021-12-06T02:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: DAC 10 Bit data buffer</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/DAC-10-Bit-data-buffer/m-p/1383373#M47316</link>
      <description>&lt;P&gt;even after that line of complex shifting the final input to the DAC buffer is still larger than 0x400&lt;/P&gt;&lt;P&gt;when I divide that value by 0x64 then the sound gets much smoother. However, still there is slight roughness in it&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DAC-&amp;gt;DACR = (&amp;nbsp; (((output &amp;gt;&amp;gt; 10) &amp;amp; 0xFFC0) + 0x8000) / 0x64&amp;nbsp; );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 11:12:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/DAC-10-Bit-data-buffer/m-p/1383373#M47316</guid>
      <dc:creator>_ZZ_</dc:creator>
      <dc:date>2021-12-08T11:12:11Z</dc:date>
    </item>
  </channel>
</rss>

