MIDI output for M-Audio EX-P expression pedal

The M-Audio EX-P expression pedal is a potentiometer volume control for music.It contains a 12 kohm potentiometer operated by the foot pedal, which stays in the position it is set to. The unit contains a 50 kohm potentiometer accessible from the side, which can fix the minimum volume level higher than zero, if desired. There is a switch on the bottom to select "M-Audio" and "other" as wiring option. The pedal price was about $30. Details of the pedal construction are shown in the links to the right.-->

I needed a MIDI expression pedal to control modules in a VST host connected to my digital piano when using it as an organ keyboard. I used an inexpensive microprocessor to convert the pedal pot position to a number and transmit it to the computer and the VST host. The pedal MIDI output is mixed in a MIDI combiner with the MIDI signals from the digital piano.

The microprocessor used is an Atmel AVR ATtiny24. It was programmed to read the pedal position as the voltage appearing on the pot wiper with 3.3 volts applied across the pot. The pot is turned 90 degrees by a lever connected to the pedal, which rotates through about 17 degrees. The wiper voltage goes full way from zero to 3.3 volts. The minimum voltage out can be raised by the pot on the side of the pedal, but this feature isn't needed for this application, since the range can be customized in the VST host.

The MIDI signal from the microprocessor is the volume control message, hexadecimal 0B,07,XX, where XX is a number from 00 to 7F, or 0 to 127 in decimal. That allows 128 distinct volume levels. Since volume control action is logarithmic, the resolution is more than adequate, providing fractional dB control.

Some steps were taken in software to secure a smooth control action. The conversion is pretty fast, which is important so that the MIDI updates will follow the physical position of the pedal, rather than presenting large instantaneous changes after catching up. By the same toboggan, we don't want to flood the receiver with hundreds of updates per second when the pedal isn't being operated. This problem was approached by sending a MIDI message only when there has been a change in the pedal position, but updating as fast as possible when there is change.

This introduces another little problem. If the ADC output is taken as a raw 7 bits (0-127), noise makes it twitch at fairly high speed when the input is close to a transition point. While this might represent only 1/2 dB of volume change, if it occurs at high speed, it might be perceived as an amplitude modulation. In any case, it would be a waste of resources for the VST host. This problem was solved by using the 10-bit accuracy of the ADC. In each sample of pedal position, thirty-two 10-bit samples are collected and summed in a 16-bit register pair, so that the high byte of the pair will end up with an averaged 7-bit result. The entire 16-bit result is compared to the previous 16-bit value, and no update is done if the difference between the two is less than 30, which represents only a fraction of an LSB of the 7 bit result. If the change is large enough, the 7-bit value is compared to the last 7-bit value, and only if it is different is a new value stored for the next comparison, and put out to MIDI. This means that there is a slight hysteresis, but it is smaller than the LSB of the value used for volume control. Thus, all 127 values can be reached, yet there is no twitching of the output.

The digitized value is transmitted by a software serial transmitter. Although the ATtiny24 has a "universal serial interface", it sends the MSB first, the opposite of MIDI, so it was easier to make a software loop. The task and the code are fairly simple, so no interrupts and not much code were required. The schematics and the code may be seen using the links to the right.

The circuit of the controller is quite simple (see at right). The microcontroller and the 4 MHz crystal can be purchased from an electronic supplier like Digi-key or Mouser. The actual programming of the chip can be done with hardware available from Atmel, or with a general purpose chip programmer like the GQ programmer available from MCU Mall Electronics, available for about $70, or by many other means that can be found with a web search.

The programming is done by moving the hex file (available at right) onto the microcontroller with the programmer. If code changes are needed, the assembler file (text file at right) can be reassembled in AVR Studio 4 or 5, available free from Atmel, to produce a new hex file. Changes that might be desired are the effective MIDI channel, or even the controller number, if something other than volume needs to be controlled. These changes can also be effected in the software in the computer.

For my particular situation, it was easier to have the microcontroller mounted up in the digital piano cabinet, connected by the original cable of the pedal. The power supply for the controller is drawn from the host computer by a USB cable used only to pick up +5 V. The controller could be located inside the pedal, with a MIDI cable connecting to the computer. The controller requires 5 V at about 5 mA.