Adding a DAC to the MSP432 Launchpad

The MSP432 Launchpad features quite a powerful low energy processor (the MSP432P401R).  This should make it ideal for a little DSP but for one problem: there is no DAC.  I decided that I should remedy this by adding an SPI DAC in the form of a TLV5618A. This 12-bit IC has two DAC outputs and can be driven at a speed sufficient for some pretty decent audio.  Wiring is as shown below:

wiring

Code was developed in Energia – an experience that left me wondering about the completeness and documentation of the MSP432 port to this environment.

 

#include <SPI.h>
#include <msp432.h>
#define SS_PIN 17
void setup()
{
  // put your setup code here, to run once:
  pinMode(SS_PIN,OUTPUT);
  pinMode(15,OUTPUT); // MOSI
  pinMode(7,OUTPUT); // SCK
  SPI.setModule(EUSCI_B0_MODULE);
  SPI.setDataMode(SPI_MODE1);
  SPI.setBitOrder(MSBFIRST);   //
  SPI.setClockDivider(SPI_CLOCK_DIV2); // DIV2 = 8MHz, DIV4 = 4MHz, DIV8 = 2MHz etc. (from measurement)
}
void writeDACA(int Value)
{
  Value=Value & 0xfff;
  Value = Value | 0xc000; // Write DAC A
  digitalWrite(SS_PIN,LOW);
  SPI.transfer( (Value >> 8) & 0xff);
  SPI.transfer( Value  & 0xff);
  digitalWrite(SS_PIN,HIGH);
}
int i=0;
void loop()
{
  // put your main code here, to run repeatedly:
  while(1)
  {
    writeDACA(i);
    i++;
    if (i > 0xfff)
      i = 0;
  }

}

This produces the following output waveform:

waveform

This is a little noisy but more to the point : SLOW!  The pair of SPI writes are taking more than 70 microseconds which makes me wonder about the efficiency of the underlying libraries.  I hope to remedy this in a later post (Edit: you can read about this here: https://ioprog.com/2016/07/02/speedier-dacs-with-the-msp432-launchpad/)

5 thoughts on “Adding a DAC to the MSP432 Launchpad

  1. Abraham Munguia March 1, 2017 / 5:22 am

    Any chance to improve the performance yet? 🙂

    Like

    • fduignan March 1, 2017 / 7:01 am

      Did you read the follow up article “Speedier DACs with the MSP432 Launchpad”?

      Like

  2. Gopal May 9, 2017 / 5:16 am

    what does the SS_pin in the code also can you comment and explain the code for me??

    Like

    • fduignan May 9, 2017 / 8:19 am

      The SS_PIN is a “Slave Select” pin. You need to drive this low to signal the beginning of an SPI transaction. You bring it high when the transfer is complete. The setup function configures this pin as an output (along with a few others). It also sets up the USCI (USART) hardware to operate as an SPI Master with a clock speed of 8MHz.
      The DAC in question is a 12-bit one. The function writeDACA begins by zeroing any bits in the desired output value after bit 11 as the higher bits are for control purposes. It then sets the two MSB’s to indicate that it intends to write to DACA (see page 11 in http://www.ti.com/lit/ds/slas230h/slas230h.pdf) The SPI transaction is then started by dropping the SS_PIN to logic 0. The most significant byte of the 16 bit output value is transferred first followed by the least significant byte. Finally the SS_Pin is raised to logic 1 to signal the end of the SPI transaction.
      The main simply calls on writeDACA to write out an sawtooth waveform with the DAC.
      A faster version of the code (with more comments) is available here:
      https://ioprog.com/2016/07/02/speedier-dacs-with-the-msp432-launchpad/

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s