Simple DIY MIDI-to-CV Translator Box
for use with monophonic analog modular sound synthesizers

Another DIY project blog by M.J. Bauer

___
front & rear view
___

Index

Overview

PWM 'DAC' Filter Design

Circuit Design

PCB and Enclosure

Assembly (incl. mod's)

Firmware

User Guide

Performance


Instalment 1 -- Overview

There are other DIY MIDI-CV designs to be found and commercial products available at reasonable prices, so why would I design and build my own? The primary reason is that I want a device which is compatible with my EWI MIDI controller (REMI 2) which plugs into a MIDI IN socket (DIN-5) modified to supply 5V DC power to the EWI controller. This arrangement is called "Power-over-MIDI". There are other features I want in the device as well, not all of which are provided in other designs.

But most of all, I like tinkering and making things. I don't care if I'm "reinventing the wheel".

Here is my list of requirements (preliminary specification) for the device:

  • Powered by 6 ~ 9V DC (5mm barrel jack) or 5V via USB cable
  • Classic MIDI IN connector (DIN-5) with "Power-over-MIDI" (5V output)
  • USB-MIDI connectivity - responds to USB-MIDI messages
  • MIDI THRU/OUT connector (jumper-selectable THRU or OUT function)
  • Four control voltage (CV) outputs, 0 to 5V range
  • Pitch CV OUT has 12-bit resolution (or higher)
  • GATE output (5V logic) responds to Note-On and Note-Off messages
  • Self-test/calibrate function initiated by button on front panel
  • Toggle switches (at least 3) to select various modes of operation
  • LED status enunciators (Power, Gate, Fault, etc)
  • Very low cost

Provision of USB-MIDI comm's capability will allow the device to connect directly to a computer, enabling software app's (e.g. DAW or MIDI sequencer) to control modular analog synth's. Provision of a classic MIDI IN (DIN-5) connector allows any old MIDI keyboard or EWI MIDI controller to be plugged in.

Pro Micro clone

A low-end 8-bit micro-controller with at least one high-resolution PWM output pin will suffice. Using PWM for D/A conversion saves the cost and complexity of an external SPI DAC and S&H circuits. However, the PWM signals will need to be filtered.

I chose a Sparkfun "Pro Micro" module (5V/16MHz version) based on the ATmega32U4 MCU. Real cheap Pro Micro clones are readily available on AliExpress. The Pro Micro module has 3 PWM pins capable of 12-bit resolution and another PWM pin giving 10-bit resolution. Plus, the ATmega32U4 MCU has on-chip USB to provide the USB-MIDI capability.

Initially, I plan to develop the firmware with "Microchip/Atmel Studio for AVR and SAM devices" because it is a more professional IDE than Arduino and I am familiar with it.
Further down the track, I will attempt to migrate the program to Arduino because it is very popular among hobbyists. There is an Arduino MIDI code library available for the Pro Micro module, which could save me the effort of coding the low-level USB-MIDI peripheral driver functions.

These sketches show what I have in mind for the front and rear panels...

MIDI-CV front panel sketch

The front panel (above) has 3 mini toggle switches to select modes of operation. The firmware can be customized to suit any particular requirements, of course, but this arrangement functions as follows:

Switch #3 selects the "base note", i.e. the MIDI note number corresponding to 0.0V on the Pitch CV output. The 2 options are note 36 (C2) or note 48 (C3) to suit instruments covering the Tenor, Alto (Treble) and Soprano ranges.

Switch #2 selects either 1 volt/octave or 0.5 volt/octave for the Pitch CV output. When 0.5 V/octave is selected, switch #1 setting is ignored and the "base note" is set to 12 (C0) or whatever else may be hard-coded in the firmware. The maximum CV output level is 5 volts, so the range is limited to 5 octaves when 1V/oct is selected.

Switch #1 selects the MIDI message type associated with CV output #4 to suit the type of MIDI controller plugged in. An EWI controller (e.g. Akai 4000s, REMI 2, etc) sends Breath Pressure messages (CC2), whereas a MIDI keyboard may send Expression (CC11) or Channel Volume (CC07) messages. In any case, output CV4 would most likely be patched to a VCA control input on the synth to control the audio amplitude.

Also on the front panel is a push-button switch. Its main function is to initiate a self-test/calibrate routine to check and adjust the CV outputs' volts-per-octave transfer characteristic. Another button function sets the MIDI channel number and Omni On/Off mode.  If the button is pressed within 3 seconds following power-on, the toggle switches select 1 of 8 options encoded as a 3-bit binary number;  i.e. 000 = Omni On,  001 = channel 1 (Omni Off), 010 = channel 2 (Omni Off), 011 = channel 3, etc.

The 2 LEDs indicate the device status in the current mode of operation.  (Details TBA.)

MIDI-CV rear panel sketch

The rear panel has a 5-pin DIN socket which can function either as 'MIDI THRU' or 'MIDI OUT', selected by a hardware jumper. In 'MIDI OUT' mode, the transmitter is driven from the MCU (UART TX pin), so the firmware gets to decide what messages are sent, on what channel and when.  (Details TBA.)

A 'Gate' output (5V logic) and four CV outputs are provided on the rear panel using 3.5mm TS (mono) phone sockets. If you're patching into a Moog 'System 55' modular synth (for example), you'll need adapter cables with a 3.5mm plug at one end and a 1/4 inch phone plug at the other end.

The four CV outputs are nominally 'Pitch', 'Velocity', 'Modulation' and 'Expression' to suit MIDI messages commonly implemented by MIDI controllers, including EWI's of course. You might want to substitute After-Touch for Expression on CV4, if you are using a keyboard which supports After-Touch.

The yellow 'GATE' LED illuminates while the Gate output is asserted (High).

I'm not sure yet how to handle Pitch Bend messages.  What do commercial MIDI-to-CV devices do with Pitch Bend data?  Do they provide a separate CV output, or is the Pitch CV output level adjusted according to the amount of bend (data in the Pitch Bend message)?  For my purposes, I would choose the latter.


Instalment 2 -- PWM 'DAC' Filter Design

In this instalment I begin with a look at MCU I/O pin allocation. Does the Pro Micro have enough I/O for the application? Next I explain the trade-offs between PWM resolution, carrier frequency and filter response time. We'll see if the ATmega32U4 can meet the specified performance requirements.

This image shows the MCU pin allocation. All required signals are catered for, without a single spare I/O pin!

mcu pin alloc

What if there were not enough I/O pins?  An easy solution would be to use an I2C I/O port expander, assuming only digital I/O's were needed.  Adding analog inputs gets messy... that would involve a multiplexer. When a design crosses that line, it's often better to choose an MCU module with more I/O.

Four analog inputs (A0..A3) will be used to measure the voltages on the CV outputs, in the self-test and calibration routine. The ADC can be configured to use the MCU's internal precision reference (2.56V) to measure the supply voltage (Vcc) on ADC8 (pin 4) via a 5:2 divider.

PWM Resolution and Filter Response

The CV output used to control synth oscillator frequency (pitch) needs to have high resolution. 16 bits would be ideal, but using a modest 8-bit MCU with a CPU clock frequency of 16MHz, a PWM resolution of 16 bits (1/64K) would allow a maximum PWM frequency of (16MHz / 64K) = 250Hz. This is way too low because the response time would be too long.

Using PWM to make a D/A converter (DAC) requires the PWM "carrier" frequency to be eliminated. Practical (i.e. simple) low-pass filter circuits using a single op-amp are limited to 3rd-order designs, giving a roll-off slope of -60 decibels per decade. The attenuated PWM signal amplitude should be no greater than 1 LSb (least significant bit) of the DAC output at full scale.

The PWM filter time-constant, i.e. reciprocal of the cut-off frequency, is a fair measure of the response time, i.e. the time it takes for the CV output voltage to respond to changes in the DAC digital value (PWM duty).
In reality, the "settling time" or time it takes for the output voltage to settle within an acceptable tolerance, is much longer than the filter time-constant... maybe 5 to 10 times longer. 
For the Pitch CV output, a response time up to about 2.5ms could be tolerated (with some compromise which I will explain later). The corresponding filter cut-off frequency is therefore 1000/2.5 = 400Hz.

So let's try for 12-bit resolution, which would be quite acceptable for the intended end-user application. The DAC LSb is about 1/4000th of full-scale, corresponding to a filter attenuation of 52dB. This is achievable with a 3rd-order filter, but what about the response time?  With MCU timer clock freq = 16MHz, the PWM frequency is (16MHz / 4000) = 4kHz. For a third-order low-pass filter, 60dB attenuation occurs about one decade higher than the cut-off frequency, so Fc = (4kHz / 10) = 400Hz. This corresponds to a time-constant of 2.5ms which is in the right ball park.

It's time to design a filter. 

From the foregoing theory, we know that the filter should have a cut-off frequency of 400Hz or higher and an attenuation of at least 52 decibels at the PWM frequency, 4kHz. I chose a 3rd-order filter comprising a 1st-order stage cascaded with a 2nd-order Sallen-Key configuration. You can find more theory here:

Second-order low-pass filters

To verify the filter design, I ran a simulation in LT-spice. The circuit is shown below. Normally the first stage would consist of only a resistor (R1) and capacitor (C3). However, to obtain the desired Butterworth filter characteristic, the pass-band gain, Av = 1.6. At high values of PWM duty, the op-amp output would clip at the +5V supply. To allow the full 5V output range, the PWM signal input to the filter must be scaled by a factor of 1/1.6. This is achieved by adding a resistor (R7) to form a voltage divider. But placing a resistor in parallel with capacitor C3 alters the filter frequency response, reducing the roll-off slope from -60dB per decade to -52dB/decade. Fortunately, this still meets the design criteria, as can be seen from the Bode plot.

LPF circuit

The composite 3rd-order filter frequency response is the solid magenta (pink) trace. The output amplitude at 4kHz is almost exactly -52dB, as required. The dotted trace is the phase shift curve which is of no great significance in this application. The green traces are for the first stage of the filter, taken from the high side of capacitor C3. Note that the pass-band amplitude is lower than that of the composite output due to the action of the voltage divider, R1 & R7 at the input. 

LPF plot

Apart from verifying that it works as expected, another benefit of simulating a circuit before you build it is  you can fiddle with component values to see how critical they are to the circuit's operation. For example, the filter pass-band gain is set by resistors R5 and R6. To obtain the optimal (flat) response, the gain (Av) should be 1.6 which means R6 should be 20k. I found that using the more common value of 22k made negligible difference to the filter response. Likewise, using 100nF for C3 made only a small change to the attenuation at 4kHz, i.e. 49dB instead of 52dB.

The Pro Micro module provides 3 PWM pins capable of 12-bit resolution at 4kHz and another PWM pin giving 10-bit resolution at 16kHz. It would be possible to implement two more CV outputs with 12-bit resolution, but the other 3 CV outputs are not as critical as the Pitch output, CV1.  Hence, in the interests of simplicity, I decided to make CV2, CV3 and CV4 all 10-bit resolution at 16kHz. Also, the response time of these 3 CV outputs is not as critical as CV1, so their filters can be a simple 1st-order RC circuit. 

Let's do the math again. A 10-bit DAC has LS bit = 1/1000th of full-scale.  As noted earlier, the PWM filter attenuation should be a similar value.  If we choose a CV response time of 5ms, the filter cut-off frequency is 200Hz. A 1st-order filter has a roll-off slope of -20dB per decade.  Between 200Hz and 16kHz is roughly 2 decades, so we can expect an attenuation of about 40dB at 16kHz. 40dB represents 1/1000th of the pass-band output amplitude, so once again, conveniently, the design criteria have been met.


Instalment 3 -- Circuit Design

Contrary to an earlier decision to power the device from 5V via the USB port only, I have added an option to power it from an external DC supply with 9 volts regulated output. Using a supply voltage of at least 6V allows the Pro-Micro's on-board 5V LDO regulator IC to function, thereby providing a cleaner and more precise +5V line. For convenience to perform a firmware update, the device can still be powered from the USB port alone, but the CV outputs will not work.

Part 1 of the schematic below comprises the Pro-Micro MCU module (A1), the 9V DC supply jack (J1), and the PWM filters for the CV outputs (explained in the previous instalment). 

Note that the circuit has been revised since the original blog post.

schem p1 (mods)

Provision of a reset button is highly recommended because the MCU bootloader firmware can execute differently depending on whether a power-on reset occurs or the reset button is pressed.

The numbers in brackets beside MCU signal names are pin designators printed on the Pro-Micro module. These designators are a legacy from the Arduino pin labeling scheme which makes little sense in any other context. However, the Arduino pin labels may assist in wiring up the circuit board.

Part 2 of the schematic follows...

schem p2

Resistors R11 and R12 form a precision 5:2 voltage divider to measure Vcc using the MCU internal precision reference (Vref = 2.56V). These resistors should be within 0.1% of their rated value, but it is not necessary to buy resistors with a 0.1% tolerance. It's OK to use ordinary 1% metal film resistors and check their values with a multimeter. It's not the absolute values, it's the ratio (3/2) that needs to be accurate.

Pin PE6 of the MCU drives the GATE logic output. The pin is set Low to turn on transistor Q1 which asserts the GATE signal (High = +5V).  R14 ensures Q1 is off when pin PE6 is high-Z, i.e. when the MCU is reset.

The MIDI IN (receiver) circuit shown above is unusual. It was designed primarily to accept a REMI 2 EWI (MIDI wind controller). Thus, the circuit differs from a normal MIDI IN receiver in a couple of ways...

1. There is no opto-isolator! This means that a common (GND) connection is required between the attached MIDI controller and the MIDI-CV box. Pin 2 of the DIN5 socket is wired to GND for this purpose. (Pin 2 of a MIDI IN socket is normally not connected.)

2. The MIDI IN socket provides 5V power to the attached MIDI controller. This was implemented to power a REMI 2, but may also be used to power any MIDI device compatible with the Arduino "Power-over-MIDI" scheme (where DIN-5 socket pin1 = +5V, pin3 = GND).

If you prefer to have a standard MIDI IN connection, use the circuit shown below, without +5V and GND wired to the DIN socket (pins 1 & 3). Alternatively, the 6N138 opto (U3) may be omitted, in which case bridge U3 pads 3 & 6, use 2k2 for R26 and wire DIN socket pin 2 to GND. R25, D1 and R27 can be omitted also. If a PCB design is produced, it will accommodate the "preferred" MIDI IN circuit shown here.

MIDI IN circuit (v2)

Preferred MIDI IN receiver circuit using opto-coupler

The MIDI THRU/OUT transmitter circuit is unremarkable. Jumper P2 selects between MIDI THRU and MIDI OUT operation. I have not yet contemplated any specific function for the firmware-driven MIDI OUT option.


Instalment 4

I am excited to announce that a Synth-DIY fan and regular correspondent, Jean-Pierre Meyer (in France), has designed a PCB for the MIDI-CV project. The board has all thru-hole components to make it easier for those not skilled in SMT assembly. Here is a picture of the final layout...

PCB overlay (v1.4)

Be sure to notify me if you are interested in obtaining a board.  Ordering details here

The PCB was designed to fit into a plastic "Jiffy Box", size 130 x 68 x 44 mm, sold by Jaycar (in Australia at least) in light-grey or black, priced at AU$5.50. 

Jiffy box

I found another suitable box on AliExpress. This type is available in black, grey or (cool) blue.

AliX box 

Below is a rough sketch of the proposed internal layout of the box, viewed from the under-side. The lid attaches to the bottom. The PCB is mounted on the top panel of the box on 6mm long spacers, held in place with machine screws. The board can be easily removed and replaced for rework, if required.

The DIN connectors, toggle switches, LEDs and push-button are mounted on the box panels, wired to the board via SIL headers. This arrangement, contrary to using PCB-mounted parts, allows various alternative enclosures. It also allows more flexiblity for makers to rearrange the front panel layout as desired.

box layout 


Instalment 5 -- Assembly

Download the Parts List and start to source parts while waiting for your PCB to be delivered.

An assembled circuit board is shown here. Apart from the Pro Micro MCU, a couple of dual op-amps and a few connectors, there's not much in it... except quite a lot of resistors (but they're cheap). You can use smaller resistors (1/4W or 1/8W) if you prefer. The tolerance rating is not critical, except for R11 and R12 which should be 1% metal film types. The board was not really designed for 1/2W resistors, but they fit OK. Take care not to stress the resistors when bending their leads.

As noted before, there is an option to omit the opto-coupler (U3) from the MIDI IN circuit. If you choose this option, be sure to wire pin 2 of the MIDI IN socket to GND. Other modifications are noted in the picture. Pins 1 and 3 of the DIN5 socket should be left unconnected, except if your MIDI controller uses "Power-over-MIDI" (e.g. the "REMI 2" EWI controller).

assembled PCB (alt.)

I used cheap pin-headers made by breaking up a 40-pin strip. Likewise, the matching "plugs" were made from a 40-way socket strip... the same as used for the MCU module "socket". You can use more elegant polarized SIL pin-headers and plugs if you prefer. There is no RESET button on the board shown above because I did not have one of the right type. However, I recommend to fit a RESET button.

A few wire harnesses need to be made to connect the DIN5 sockets, LEDs and switches to the PCB. The LEDs were soldered onto a little piece of perf-board. Note that toggle switch S1 is in the rightmost position, S2 in the middle and S3 to the left. The push-button is designated 'S4' on the schematic.

When the circuit board is complete, measure the positions of the jacks along the rear panel, and the USB socket on the LH side. Cut holes in the enclosure to fit all parts which poke through the panels. 

The circuit board is mounted in the enclosure (Jiffy Box) on 6mm stand-offs (spacers). Only 2 mounting points are needed, near the 2 rounded corners of the PCB, because the 3.5mm CV-out jacks will hold the board in place on the opposite side (against the rear panel).

I recommend to fix the 6mm stand-offs in place using hot-melt glue. Otherwise, they are a pain to keep in place while inserting the mounting screws. The LED board also may be fixed in place with hot-melt glue. If you're using the "standard" enclosure (Jiffy Box), the assembled device should look something like this...

internal view

Jiffy Box with bottom cover removed

Labels on the front and rear panels shown in the picture at the top of the page may look OK, but I must admit they are not real! I cheated... the labels were added with an image editor, Windows Paint.

Labeling of switches, connectors, etc, on the front and rear panels may be done with a label-maker of the type that works with self-adhesive transparent film tapes. Another method which I often use is to draw panel decals using Windows Paint (or Paint-Shop Pro), print actual size in colour on paper, cover with transparent adhesive film (e.g. bookbinding film), cut holes for switches, sockets, etc, then glue it onto the panel. When I get around to creating panel decals, I will post a link to an image file to download.


<!> PCB and circuit mod's 

The PCB (v1.6) has signal RXD1 (U3 pin6) routed to pin2 (centre pin) of jumper header P2. However, U3 pin6 should be routed to pin1 of P2. Break the track which connects to R18 (47k) on the top side of the PCB. Solder a wire from U3 pin6 to P2 pin1 (under-side). Also, there is a "track link" bridging pins 1 & 2 of P2 (top-side) which must be cut if the MIDI OUT option is selected.

The circuit was revised to overcome a limitation of the original op-amp chosen, MCP602. Although the MCP602 output voltage range is spec'd as "rail-to-rail", the common-mode input voltage range only goes as high as Vdd minus 1.2V, meaning the output voltage could not go higher than about 3.6V in this filter configuration. A higher Vdd would fix the problem, but the MCP602 maximum supply voltage is 5.5V, so this device is not suitable.

The simplest work-around was to substitute a different op-amp, LM358, which is pin-compatible, dirt cheap, allows common-mode input voltage down to 0V, and will operate at a higher supply voltage. The schematic and parts list have been amended accordingly.

The circuit revision requires a couple of minor hacks to the PCB v1.6, as shown in the pics below. Cut tracks where indicated by red ellipses and solder wire links on the under-side.

Resistor R6 should be 18k (marked 22k on PCB v1.6). The original value (22k) did not provide enough gain to compensate for the filter input voltage divider (R1, R7). See picture for location of R6.

PCB v1.6 mods top

PCB v1.6 mods bottom

The circuit revision means that the MIDI-CV box needs to be powered from a PSU with a 9V regulated output, although it will function properly down to 7.5V. It's probably best not to go higher than 9V, becuase the Pro Micro on-board 5V linear LDO regulator IC is feeble. It is rated at 500mA output, but that's assuming it has an effective heat sink and with input voltage is as low as practical, e.g. 6V. 

The device can still be powered via USB for firmware loading.


Firmware

Download the Firmware pack here

A hex object file is included so you can program the device without needing to re-build the firmware. The board can be programmed via the USB port without needing Microchip/Atmel Studio (IDE) and without a hardware programming tool. Proceed as follows...

The Pro Micro board has a flash-resident AVR bootloader. A Windows application called “AVRdude” communicates with the bootloader via USB to program firmware into the MCU flash memory.

Hence you need to download some files to run "avrdude" on Windows. The best place to download the files is GitHub, here: https://github.com/mariusgreuel/avrdude/releases. There should be 3 distribution files: “avrdude.exe”, “avrdude.conf” and “avrdude.pdb”. Copy these files to a new folder named “AVRdude” on your PC local drive, in the “root directory” (C:\).

Connect your board to a USB port on your PC. Open Windows “Device Manager” utility and click on “Ports (COM & LPT)”. Immediately after you apply power or reset the MCU, you should see the board’s USB-serial device listed. Note the number of the associated “COM” port.  Be aware that the COM port number may change from time to time.  Always check the allocated COM port after re-connecting the board to your PC.

Copy the hex file "MIDI-to-CV-translator-v1.0.hex" into the folder "C:\AVRdude".

Open Windows Command Prompt, then enter the command...

cd \AVRdude

Windows should respond with...

C:\AVRdude>

Type the command given below (or copy and paste it) all on one line at the prompt. Replace "COM9" with the actual COM port number shown in Device Manager. Wait until you restart the Pro Micro bootloader (reset the MCU) then press [Enter] to execute the command...

avrdude.exe -C avrdude.conf -v -V -p atmega32u4 -cavr109 -P COM9 -b 57600 -D -U
flash:w:"
MIDI-to-CV-translator-v1.0.hex":i

You can enter the command first and then reset the MCU, if you prefer, because avrdude will keep trying to establish comm's with the bootloader, indefinitely.

If all goes well, avrdude will report success.

Note: When AVRdude finishes the firmware loading process, it may be necessary to remove the USB cable, then re-apply power to the device to start the user program.
_____

To modify or extend the program...

The firmware download package includes source code, libraries and all project files needed to build the program using Microchip/Atmel Studio IDE for AVR and SAM Devices. Download and install the app.

Create a project folder on your Windows PC local drive named "MIDI-to-CV-translator". The "solution" file expects this name exactly. Copy all the files from the distribution pack, "MIDI-to-CV-firmware-pack.ZIP" to your project folder.  If Atmel Studio is already open, close it.

Double-click the file "MIDI-to-CV-translator.atsln" in the project folder.  Atmel Studio will open the "solution" (project).  Check that all required "components" (files) are present and in the correct place, as can be verified in the "Solution Explorer" pane (see screen-shot below)...

Solution Exp sshot

To view/edit a source file, click the file-name in the Solution Explorer pane.

When you're done editing the source code, assuming everything is correct, click 'Build Solution'.

If the build was successful, a hex object file "MIDI-to-CV-translator.hex" will be placed in the project sub-folder "..\Debug". To program the board, you have a choice between two options. Probably the easiest method is to proceed as above using AVRdude stand-alone from Windows Command Prompt.

Another option is to create a "software programming tool" in Atmel Studio. This method allows you to program the board directly from within Atmel Studio. Proceed as instructed in the linked document, here...

How to program the Pro-Micro board via USB using Atmel Studio IDE

Additonal notes on Pro Micro USB bootloader variants

Some Pro Micro boards have the Sparkfun (modified) bootloader installed. This behaves a little differently compared with the "normal" Arduino Micro/Leonardo bootloader. To enter bootloader mode (and remain in the bootloader for 10 seconds) press RESET twice in quick succession. Otherwise, a reset should start the user application program.

In case of the Arduino Micro/Leonardo bootloader (installed in most Pro Micro clones), the MCU enters bootloader mode immediately on power-up (and/or reset) and remains in bootloader mode for 10 seconds. After 10 seconds, the bootloader tries to start the user application program, if any is loaded.

...

Firmware Releases

Version 1.0  (August-2024) 

Preliminary release which implements most of the specified functional requirements. Version 1.0 is built using Microchip/Atmel Studio IDE. This version does not support MIDI message input via USB. A future firmware variant will have the code migrated to Arduino IDE to support this feature.

Also, v1.0 doesn't support MIDI OUT, except that the UART which transmits via the MIDI OUT port sends diagnostic data to a PC terminal app via a serial adapter. Set jumper P2 for the 'MIDI THRU' option until such time as a firmware revision supports MIDI OUT. I welcome suggestions for any possible usage of MIDI OUT.

A future release will also implement more functionality to be initiated by the 'CAL/TEST' button; for example, to generate a sequence of "notes" for test and demo purposes.

...


User Guide

The default MIDI IN configuration is Omni-ON, meaning that the device will respond to incoming messages addressed to any MIDI channel. 

To change the configuration, power down the device and set the 3 toggle switches to select the required MIDI IN mode and channel (1..7) as in the table below. (Switch position 0 = down/closed, 1 = up/open.)  

Press and hold the CAL/TEST button, power up the device, then release the button. The configuration is saved in non-volatile memory (EEPROM), but it will be defaulted whenever the firmware is updated.

SWITCHESOmni ModeMIDI Channel
0-0-0ONX
0-0-1Off1
0-1-0Off2
0-1-1Off3
1-0-0Off4
1-0-1Off5
1-1-0Off6
1-1-1Off7

Self-test/Calibration

Every time the device is powered up normally, it will perform a self-test and calibration routine. This takes less than a second. If a fault is detected, the red "error" LED will remain lit. Otherwise, the green LED will illuminate indicating that the unit was calibrated successfully.

GATE output function

The GATE signal (5V logic output) is intended to control one or more "ADSR" envelope generators in the attached synthesizer. The leading edge of the GATE signal triggers the "Attack" segment of the EG which progresses automatically through the Decay and Sustain segments. When the GATE signal is negated (Low) the Release segment of the EG should activate.

This MIDI-to-CV Translator is designed for use with monophonic analog synth's. As such, it complies with the MIDI 1.0 Specification (v4.2 1995) with regard to "Legato" operation, as follows:

If a MIDI Note-On message is received while the GATE signal is negated (Low), i.e. while there is no note keyed, then the GATE output will be asserted (set High) and the Pitch CV output will be set according to the MIDI note number received. The Velocity CV output will also be set according to the MIDI data value. This should cause any gated EG(s) on the attached synth to enter the Attack phase.

If a MIDI Note-Off message is received and the MIDI note number is the same as the note last keyed, then the GATE signal will be negated (set Low) if it is not already negated. The same response is executed if a MIDI Note-On message is received with Velocity value zero. (This is equivalent to Note-Off.)

If a MIDI Note-On message is received while the GATE signal is already asserted (High), i.e. while a note is playing, then the GATE output will remain asserted (High). However, the Pitch CV output will be updated according to the new MIDI note number received. This action would normally result in a pitch change (and maybe a velocity adjustment) without the connected EG(s) re-attacking... This is a Legato note change.

Legato mode is compatible with glissando/portamento functions which may be supported by your synth.

Legato mode on/off setting

The MIDI controller may send a Control Change 68 ("Legato Foot-Switch") message to disable or enable legato. A data value of 64 or higher represents "Legato On"; a value 63 or lower represents "Legato Off". The Legato on/off setting is "remembered", i.e. the setting is persistent across power-downs.

When Legato mode is turned off, the GATE output functions as follows:

If a MIDI Note-On message is received while the GATE signal is already asserted (High), i.e. while a note is keyed, then the GATE output will be negated (set Low) momentarily. After a short delay (5 milliseconds), the GATE output will be re-asserted (set High) and the Pitch CV output will be updated according to the new MIDI note number received. Likewise, the Velocity CV output will be updated.

Otherwise, the device behaves the same as in Legato mode.

Pitch CV Output

The Pitch CV output signal is updated whenever a MIDI Note-On message is received. The range of notes corresponding to the full-scale output voltage (+5.0V) depends of a couple of front-panel switches. The range is obviously limited to 5 octaves when 1V/oct is selected.

Switch S3 selects the "base note", i.e. the MIDI note number corresponding to 0.0V on the Pitch CV output. The 2 options are note 36 (C2) or note 48 (C3) to suit instruments covering the Tenor, Alto (Treble) and Soprano ranges.

Switch S2 selects either 1 volt/octave or 0.5 volt/octave for the Pitch CV output. When 0.5 V/octave is selected, switch S3 is ignored and the "base note" is set to 12 (C0).

Velocity CV Output

The Velocity CV output signal is updated whenever a MIDI Note-On or Note-Off message is received. Full-scale output (+5.0V) corresponds to a velocity data value of 127. The MIDI-CV device does not perform any transfer function, e.g. exponential, on the data value. This should be a function of any synth module(s) using velocity as a control input.

Modulation CV Output

The Modulation output (CV3) responds to MIDI Control Change 01 and 33 ("Modulation wheel/lever") messages. The data value may be 7 bits (CC01) or 14 bits (CC01:CC33) where CC01 provides the high-order 7 bits (MSB) and CC33 provides the low-order 7 bits (LSB). In any case, a data value of 127 (MSB only) or 16,383 (14-bit data value) corresponds to full scale, i.e. +5.0V output on CV3. Note that Modulation data is unipolar, ranging from zero to full-scale. 

Expression CV Output

The "Expression" output (CV4) responds to either MIDI Control Change 02 ("Breath Pressure") or Control Change 11 ("Expression Pedal") messages, depending on switch S1 position. The data value may be 7 bits (CC02 or CC11, high-order byte only), or 14 bits where CC34 or CC43 provides the low-order 7 bits (LSB)

In any case, a data value of 127 (MSB only) or 16,383 (14-bit data value) corresponds to full scale, i.e. +5.0V output on CV4. Expression data is unipolar, ranging from zero to full-scale. The MIDI-CV device does not perform any transfer function, e.g. exponential, on the data value. This should be a function of any synth module(s) using CV4 as a control input.

Pitch Bend

MIDI Pitch Bend messages, when received, adjust the Pitch CV output voltage according to the Pitch Bend message data value (14 bits) and a "Pitch Bend Sensitivity" parameter. Pitch Bend data is unipolar (unsigned) ranging from 0 to 16K (0x3FFF). Pitch-bend controls typically have a "centre zero" mechanical design, so that a bend value of 8K (0x2000) represents zero change in pitch. The full-scale data value (16K) corresponds to the extreme limit of movement of the control in the forward direction.

The actual change in pitch corresponding to the full-scale data value in a Pitch Bend message is determined by a parameter called the "Pitch Bend Sensitivity" (aka "Pitch Bend Range"). This parameter may have units of cents (1/100 semitone) or semitones. A MIDI message exists to set the "Pitch Bend Sensitivity". Actually, two messages are required: Control Change 100 ("Registered Parameter") with data value of 0 (defined as "Pitch Bend Sensitivity"), followed by a Control Change 6 (Data Entry) with data value representing the required sensitivity in semitones.

For example, to set the Pitch Bend Range (sensitivity) to one octave, the data value in the CC6 message would be 12 (semitones). The firmware "default" value for Pitch Bend Range is 2 (semitones). The Pitch Bend Range parameter value is "remembered", i.e. the setting is persistent across power-downs.


Instalment 7

Performance and Design Improvements

With regard to CV output voltage range, linearity and noise, the MIDI-CV box meets my expectations, although the amount of residual PWM carrier on the CV1 output is a little higher than I would prefer. However, most synth VCO's would be unaffected by this amount of noise, I guess.

The PWM "noise" is most likely due to poor performance of the active low-pass filter, which could be improved by using a better op-amp than the crappy old LM358. I'll try to find a suitable alternative which is readily available and not too expensive.

The 'scope shots below show the CV outputs' noise performance. The yellow traces are the PWM signals at MCU pins OC3A and OC1A. The blue traces are the CV outputs, AC-coupled to the 'scope. On the left is CV1 which has a noise amplitude of about 20mVp-p (~7mV RMS). The vertical scale is 100mV per division. On the right is CV2 with a noise amplitude less than 6mVp-p (~2mV RMS). The vertical scale is 20mV per division.

scope shots

I haven't tested the response time of the Pitch CV1 output yet. This will require additional code in my "MIDI Device Tester" which I will get around to... eventually. I didn't imagine there would be so much work in developing (and testing) such a simple MIDI-CV converter. I'm confident that the filter response will be acceptable, as predicted by the theory in an earlier installment.

Nevertheless, things went a little astray with the method of calibration of the CV1 output. The ADC uses AVCC (+5V) as a reference voltage. If AVCC is in error, then CV1 will be in error, of course. However, if AVCC can be measured accurately, then all other ADC readings can be corrected. No problem, I thought... I'll use the ADC internal reference (2.56V) to measure AVCC via a 5:2 voltage divider feeding into pin ADC8.

But there was a problem with this idea... I assumed naively that the ADC internal reference would have a precision consistent with taking readings with a 10-bit ADC, i.e. around 0.1%. When I got ADC readings which were very inconsistent, i.e. wrong, I was convinced that I had made a mistake in the ADC driver code. 

To cut a long story short, I eventually discovered a relevant characteristic of the ADC in the ATmega32u4 data-sheet that I had previously overlooked. The error in the internal reference voltage can be up 6% FFS (and I don't mean "Full Scale"!!). Conclusion: The ATmega32u4 ADC internal reference is useless!

ADC int ref spec

There are two alternative calibration methods which I will outline, one of which requires a small modification to the circuit. This method allows an "automatic" calibration routine to be performed by the firmware. The second method requires no hardware modification, but a (simple) manual calibration procedure is required.

The first method uses an external precision reference device, e.g. LM4040-N (2.5V ±0.1%). Unfortunately, the AREF pin on the MCU is not easily accessible on the Pro Micro board, but the external reference can be wired to pin ADC8 instead. The firmware measures the voltage on ADC8. Since the actual ADC reference is AVCC (+5V), any error in the reading of ADC8 can be used to calculate the true voltage on AVCC, which in turn can be used to correct all other ADC readings.

The second method, which needs no modification to the hardware, is to use the front-panel switches and button to perform a manual calibration. This method requires a voltmeter to be connected to the CV1 output. I'll elaborate later when I figure out the details and write the code to implement the
calibration procedure.

Finally, rest assured that this MIDI-CV Translator performs quite well without compensation for error in the ADC reference. The Pro Micro on-board 5V LDO regulator is reasonably accurate... in fact much more accurate than the ATmega32u4 internal reference!  Most synth VCO's have a "fine tune" control, so any error in the CV1 output voltage can be compensated by tuning the VCO frequency. Vintage synth VCO's required frequent calibration and tuning to obtain anything near "concert pitch" from their analog keyboards.

___


How to obtain a circuit board

Bare (unpopulated) PCB's are available for purchase from the author. PCB cost price is only $3, but postage outside Australia is quite expensive. For example, to send a parcel (up to 250g) to the USA costs US$13. However, to send an ordinary letter (same size and weight) costs only US$3. Go figure!

When you order a PCB, please indicate if you want to take the risk to have it sent in a plain "letter" envelope. I will mark the envelope "PRINTED MATTER ONLY" - which is true - it's a PRINTED circuit board! This will reduce the postage cost, but the PCB might not be delivered, if it gets intercepted by customs. Total price for one PCB including postage in a plain envelope: $6 (USD). Otherwise, see table below for pricing:

DestinationPCB price
incl. postage
AUA$5.00
US$16.00
UK£15.00
EU€17.00

For all other destinations, please send me an email inquiry.

If you want an enclosure of the same type used to build the prototype (Jiffy Box), this can be included in your order for the same postage charge. Add US$7.00 to the PCB price listed in the table.

To order, send email to the address below. Please include your country, state, zip code, etc.
Outside Australia, the only payment method I can accept is PayPal. Details will be given on the invoice.

Note: PCB v1.6 will be supplied with modifications (track cuts) already done.

Download Gerber files for PCB fab here if you want to get your own PCB(s) made.

Kindly notify me if you intend to get a quantity of PCBs made and wish to share any surplus with other makers in your country. I will then forward the buyers' email and postal addresses to you for delivery.
___


Thanks for taking an interest in this project. I hope the design suits your requirements. Otherwise, perhaps you will get some ideas for your own design. Feel free to send comments and queries, either post on the Synth-DIY Facebook group (search for my posts), or email direct to me.

Other projects by MJB that you might be interested in:

'Rifficator' - MIDI Melody & Riff Creator

'REMI 2' - EWI MIDI Controller

'REMI  Synth' - Monophonic digital synth  (based on PIC32 MCU)



Send email enquiries, comments, suggestions, PCB orders, etc, to...

link to email address

Last update: 31-AUG-2024

MJB's Home Page

___