# DAC DAC121S101 Pmod Controller (VHDL)

**URL:** <https://forum.digikey.com/t/dac-dac121s101-pmod-controller-vhdl/13031>\
**Category:** Logic Design\
**Tags:** development-boards-kits-programmers, evaluation-boards, digilent-inc, tech-tips\
**Created:** [March 25, 2021, 7:39pm UTC](https://forum.digikey.com/t/dac-dac121s101-pmod-controller-vhdl/13031 "2021-03-25T19:39:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_1767](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@Scott\_1767](https://forum.digikey.com/u/Scott_1767)\
**Post date:** [March 25, 2021, 7:39pm UTC](https://forum.digikey.com/t/dac-dac121s101-pmod-controller-vhdl/13031/1 "2021-03-25T19:39:12Z")

</div>

[Logic Home](https://forum.digikey.com/t/logic-home-table-of-contents/12507)

 

# Code Downloads

DAC DAC121S101 Pmod Controller (top level file): [pmod\_dac121S101.vhd](https://forum.digikey.com/uploads/short-url/tf2rJgkiLQpXJyiXNb70vDrYxT4.vhd) (8.3 KB)

SPI Master with Dual MOSI (must be included in project): [spi\_master\_dual\_mosi.vhd](https://forum.digikey.com/uploads/short-url/6WgJYv0zskLdfO5ZTrVWQ6eV4DB.vhd) (9.7 KB)

# Features

- VHDL source code of a streamlined interface to Digilent’s [Pmod DA2](https://www.digikey.com/en/products/detail/digilent-inc/410-113/3902804?s=N4IgTCBcDaIIxgBwDYC0cAMGyoHIBEQBdAXyA) (Pmod for Texas Instruments [DAC121S101](https://www.digikey.com/en/products/filter/data-acquisition-digital-to-analog-converters-dac/701?s=N4IgTCBcDaICIEEDCBGMKDKKAMKQF0BfIA) digital-to-analog converters)
- Simultaneously controls both of the Pmod’s two 12-bit DACs using simple parallel interfaces
- Handles all serial communication with the DAC Pmod
- Configurable system clock rate

# Introduction

This details a VHDL component that handles interfacing to Digilent’s Pmod DA2 for DAC121S101, shown in Figure 1. Figure 2 illustrates a typical example of this DAC Pmod Controller integrated into a system. As shown, the DAC Pmod Controller connects to the Pmod ports and executes transactions to set the DAC outputs. Data is latched in on simple parallel interfaces which can be connected to user logic or to input ports on the FPGA.

 ![PmodDA2](https://global.discourse-cdn.com/digikey/original/2X/5/54133aa57b74917bc7a341d8e443b472437c16d4.jpeg)

**Figure 1.** Digilent Pmod DA2 for DAC121S101

 ![block_diagram](https://global.discourse-cdn.com/digikey/original/2X/7/7c2f4fed2c5000d7d0f9ca9097e512618cda7945.jpeg)

**Figure 2.** Example Implementation

# Background

The Pmod DA2 provides two 12-bit Texas Instruments DAC121S101 digital-to-analog converters. The converters use the provided supply voltage as the voltage reference and have on-chip amplifiers that allow rail-to-rail output swings. They are controlled via a serial interface that can operate at up to 30 MHz.

# Theory of Operation

The DAC Pmod Controller uses a simple state machine and a modified version of the SPI Master component available on eewiki to control the DAC Pmod.

## State Machine

The design uses the state machine depicted in Figure 3 to implement its operation. Upon start-up the component immediately enters the _start_ state. It remains in this state for 100us to ensure the Pmod has ample time to power-up. It then proceeds to the _pause_ state. Here, it ensures at least 20ns elapse between transactions with the DACs. At that point, it deasserts the _busy_ signal to indicate that the DAC Pmod Controller is ready for a new transaction with the DAC Pmod and proceeds to the _ready_ state. It waits in the _ready_ state until the _dac\_tx\_ena_ enable signal is asserted, when it latches in the data for the new transaction and advances to the _send\_data_ state. In this state, it executes the transaction with the Pmod and then returns to the _pause_ state. Although not shown, resetting the component at any time returns it to the _start_ state.

 ![state_diagram](https://global.discourse-cdn.com/digikey/original/2X/f/ffe1d413f3fe821b1ec96d30598ff490441d6e28.jpeg)

**Figure 3.** State Diagram

## SPI Master

During the _send\_data_ state, the state machine controls an SPI Master component to communicate with the DACs on the Pmod. The SPI Master used in this design is a modified version of the popular SPI Master documented and available [here](https://www.digikey.com/eewiki/pages/viewpage.action?pageId=4096096). This modified version duplicates the MOSI logic in the original to provide two separate MOSI outputs (_mosi\_0_ and _mosi\_1_). The output MOSI data is taken from the two parallel inputs _tx\_data\_0_ and _tx\_data\_1_, respectively. In this manner, the SPI Master can communicate independent data with two separate slave devices simultaneously using a single SPI bus.

The SPI Master is configured with CPOL = 0 and CPHA = 1 to meet the requirements of the DAC121S101 converters.

# Configuring the Clock

The clocking of this DAC Pmod Controller is configured by assigning values to the GENERIC parameters _clk\_freq_ and _spi\_clk\_div_, defined in the ENTITY. The _clk\_freq_ parameter must be assigned the frequency of the system clock provided on the _clk_ input port in MHz. Equation 1 defines how the _spi\_clk\_div_ value is calculated.

![equation_1](https://global.discourse-cdn.com/digikey/original/2X/7/7f5b2a97ab7b0cda9957ac757ff7c5b40c15fae3.jpeg)

where _fclk_ is the frequency of the provided system clock in MHz.

For example, the default value specified in the code is _spi\_clk\_div_ = 1. This is arrived at because the component was developed and tested using a system clock of 50 MHz. 50/60 = 0.83, rounded up is 1. Any _clk\_freq_ ≤ 60 MHz results in the default _spi\_clk\_div_ = 1.

Equation 2 defines the serial clock frequency _fsclk_ that results.

 ![equation_2](https://global.discourse-cdn.com/digikey/original/2X/d/d3456cda801064f5c643136ff9fbdb7cf72fe7c6.jpeg)

This calculation keeps the serial clock below the DAC’s maximum specified communication frequency of 30 MHz. The fastest communication occurs when the input clock frequency (in MHz) is an integer multiple of 60.

# Transactions

The DAC Pmod Controller indicates its availability on its _busy_ output. When the _busy_ signal is ‘0’, the Controller is ready to accept transactions to send to the DAC Pmod. Asserting the _dac\_tx\_ena_ input latches in the current values on _dac\_data\_a_ and _dac\_data\_b_. Once latched, the Controller asserts the busy signal to indicate that a transaction is in progress, so it is not currently available. When the transaction is complete, it again deasserts the _busy_ signal to indicate that it’s ready to accept another request.

## Example Transaction

Figure 4 illustrates an example transaction. The _busy_ signal is ‘0’. The user logic then presents the data “100110011001” to write to DAC A and “010110110011” to write to DAC B. The Controller asserts the _busy_ signal, indicating the request is latched in, at which point the user logic can deassert the _dac\_tx\_ena_ signal. The Controller sends the serial communication to the DAC Pmod, then deasserts _busy_ when complete. Later, the user logic initiates a new transaction to write “010110010001” to DAC A and “101100111110” to DAC B.

If the _dac\_tx\_ena_ signal is not deasserted, a new transaction request is latched in and begins 20ns after the Controller becomes available.

 ![example_transaction](https://global.discourse-cdn.com/digikey/original/2X/8/8eb22fb6d25b7cc5d88f9dfe26efc5b495ad3bf1.jpeg)

**Figure 4.** Transaction Example

# Port Descriptions

Table 1 describes the DAC Pmod Controller’s ports.

**Table 1.** Port Descriptions

 ![port_descriptions](https://global.discourse-cdn.com/digikey/original/3X/d/4/d4aa5b619847bed55b00731bf8d10d0743e7aba7.jpeg)

# Connections

This Pmod has a 6-pin connector, J1. Table 2 provides the pinout for this connector. The DAC Pmod Controller’s ports need to be assigned to the FPGA pins that are routed to this connector as listed.

**Table 2.** DAC Pmod Pinout and Connections to DAC Pmod Controller

 ![connections](https://global.discourse-cdn.com/digikey/original/3X/8/e/8e5cd671312e5b97fb5978f19da592a2e18fad59.jpeg)

# Reset

The _reset\_n_ input port must have a logic high for the DAC Pmod Controller component to operate. A low logic level on this port asynchronously resets the component. During reset, the component aborts the current transaction with the DAC Pmod and sets the _busy_ output high to indicate it is not available. Once released from reset, the DAC Pmod Controller restarts operation.

# Conclusion

This DAC Pmod Controller is a programmable logic component that interfaces to Digilent’s Pmod DA2 for DAC121S101 converters. It simultaneously controls the Pmod’s 2 converters based on user inputs provided on simple parallel interfaces.

# Related Topics

[SPI Master (VHDL)](https://www.digikey.com/eewiki/pages/viewpage.action?pageId=4096096)
