Cypress Perform

Home > Cypress Developer Community > Blog Posts > The PSoC Hacker Blog > High Resolution Dithered DAC in PSoC 3


High Resolution Dithered DAC in PSoC 3
Nov 06, 2009
By M Ganesh Raaja

A couple of weeks ago, I had written about a method to implement a High Resolution DAC using two 8 bit DACs.  Recently I had a very interesting discussion with one of my colleagues and a good friend, a young and brilliant guy named Kannan.  He showed me how to implement a high resolution Dithered DAC using a single 8 bit DAC, an 8 bit Mux, a couple of Control Registers and a PWM.  It is amazing what you can do with the PSoC 3 hardware.

Dithering is a widely used technique in Digital Processing where a noise is intentionally introduced into a system to increase the resolution of the system.  Say we have an 8 bit DAC with a full scale value of 255mV.  Each count of the DAC represents 1mV.  What if we wanted an output of 1.25mV from the DAC.  Switch the DAC output between 1mv and 2mV keeping the output at 2mV 25% of the time and 1mV 75% of the time, the average value of the output would be 1.25mV.  For an output of 1.5mV, the DAC output should be maintained at 2mV for 50% of the time and 1mV 50% of the time.


Now let us see how this method can be implemented using the PSoC 3 hardware to create a 10 bit DAC.

Place an 8 bit voltage DAC.  Select 1.020V (4mV / bit) as the range.  Set the Data_Source to “DAC Bus” and Strobe_Mode to “External”.  The output of the DAC can now be controlled using an 8 bit data bus and the output will be updated on the rising edge of the Strobe input.

Place a Multiplexer from the Digital >> Logic category.  Set number of input terminals to 2 and terminal width to 8.  The multiplexer can now switch between two 8 bit data buses.  Place two control registers from the Digital >> Registers category.  Set the number of outputs to 8.  Connect the 8 bit data bus of the Control registers to the input of the Multiplexer. 

Place a PWM, with a period of 3 and compare type set to “Less than”.  The output of the PWM now can be controlled to 0%, 25% and 75% duty cycle.  Connect the output of the PWM to the control input of the Mux.  Use the same clock of the PWM as a strobe to the DAC.  The hardware is now ready.

In firmware, write the Most Significant 8 bits of the 10 bit DAC value to the ControlRegister0 and one count higher value to ControlRegister1.  Use the Least Significant 2 bits to update the PWM’s pulse width.  Now, the PWM switches the input of the DAC between the two 8 bit Control Register values and the average output of the DAC would be our 10 bit DAC result.  Use an external Low Pass filter to remove the switching frequency.  As the switching frequency is at 125KHz, a simple RC filter will do the trick.  Below is the code.

void main()
{
   uint16 DacValue;
   VDAC8_Start();
   PwmMsb_Start();
   Amplifier_Start();
   for(;;)
   {
      DacMsbReg0_Write(DacValue >> 2);
      DacMsbReg1_Write((DacValue >> 2) + 1);
      PwmMsb_WriteCompare((uint8)(DacValue & 0x03));
   }
}

The range of the DAC now is 0 to 1020 counts; each count representing 1mV, subject to some offset and gain error inherent in the 8 bit DAC.

Quoting my brilliant friend “I bet this cannot be implemented with any other controller out there in the market!!”

See full blog


Comments:
丁伟 wrote:
 M Ganesh Raaja:

Your method is  fantastic .

Can I ask  a question how this method can be implemented using the PSoC 3 hardware to create a 12 bit DAC?
Fri Mar 18 01:04:59 AM
graa wrote:
Simple.  Set the Period of PWM to 15 and the PWM is now a 4 bit PWM.  The code becomes:

DacMsbReg0_Write(DacValue >> 4);
DacMsbReg1_Write((DacValue >> 4) + 1);
PwmMsb_WriteCompare((uint8)(DacValue & 0x0F));

Regards,
Ganesh
Fri Mar 18 01:39:45 AM
Vanyaki wrote:
M 丁伟: Answer given by M Ganesh Raaja to you question is correct.   If you have  input signal in same range (12-bit ADC range) and then you want convert it to some output signal (8-bit DAC range) the period of PWM is 15. 
But if you have different input ADC and output DAC ranges (In my project i have input  12-bit ADC signal  range 0-2.048V, but output  8-bit DAC signal range must be  0-1.024V)  period of PWM can be >15 or <15. If input ADC is large then output DAC range then PWM period <15 (7,3 or 1) else PWM period >15 (31,63,...)
Regards, Ivan Grytsyk
Mon May 07 18:54:08 PM
You must be logged in to leave a comment. Login / Register
Like this item? Spread the news:  
Post this story on Digg.com Digg this   Share this on Facebook.com Facebook   Post this story on Digg.com LinkedIN   Add to Twitter Twitter  
ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: DWV; Secondary Owner: DSP; Sunset Date: 06/15/20