# Basic Examples

# Simple Adder

This example assigns the outputs A and B as the sum and difference of the inputs A and B.

Output A is Input A + Input B;

Output B is Input A - Input B;

Open in Moku Compile View on GitHub

# Interlaced Adder

This example re-examines the Adder example and performs sample interlacing on the operation. Interlacing is a technique where multiple samples are processed simultaneously to have an effective higher sampling rate. When implementing interlacing, there are two key changes to the code:

  1. The wrapper name changes from CustomInstrument (or CustomWrapper) to CustomInstrumentInterlaced. This is also set in the build configuration for correct synthesis.

  2. The input and output ports change from signed 16-bit integers, to an array of signed 16-bit integers. The size of the array depends on the interlacing factor dictated by the hardware and number of slots in Multi-Instrument Mode.

For example, to synthesize the Adder code for a 2-Slot Moku:Go configuration, an interlacing factor of 4 is used. Meaning, the Moku:Go will process 4 samples simultaneously at the 31.25 MHz Moku:Go clock rate, effectively increasing the sampling rate up to 125 MSa/s. The code can then be written as:

In the above example, each sample is written explicitly. For ease of writing HDL code with interlaced inputs/outputs, loops (using generate functionality) can be used to create multiple instances of adder logic in the above example. Each instance will be implemented as a separate physical hardware and would operate on different samples of the systems.

Open in Moku Compile View on GitHub

# Voltage limiter

This example uses the clip function from the Moku Library to limit the output signal to a set range. The upper limit of Output A is set by Control0, the lower limit of Output A is set by Control1. The upper limit of Output B is set by Control2, the lower limit of Output B is set by Control3.

Open in Moku Compile View on GitHub

# DSP

This example instantiates a DSP block using the ScaleOffset wrapper. The Moku.Support.ScaleOffset entity conveniently packages a DSP block with all the settings configured to compute the common Z = X * Scale + Offset operation, with the output properly clipped to prevent under/overflow.

# Getting Started

# Signals and Settings

Port Use
Control0 Scale A
Control1 Offset A
Control2 Scale B
Control3 Offset B
Output A Scaled and Offset Input A
Output B Scaled and Offset Input B
Open in Moku Compile View on GitHub