You are on page 1of 14

Design of Electronic Piano System on

FPGA and Keyboard Sensor


Yue Liu
Department of Automation,
Ocean University of China
Qingdao City, China, 266100
E-mail: lyraw@foxmail.com

Abstract: This paper describes how to generate electronic tone using FPGA.
There are three steps to achieve our goal: generating fundamental and
harmonic sinusoidal waves, adjusting proportion of each harmonic wave
and making summation, adding envelope to summation of waves. We also
design a keyboard sensor to measure the key pressure and control the
volume. The design shows high speed and easy programmability of FPGA.

Key Words: Electronic tone, FPGA, SOPC, Keyboard Sensor

1. Introduction

Sound produced by electronic piano can simulate sound of traditional piano


because the musical scales generated by electronic circuit are similar to the
musical scales of traditional piano, which are mostly generated by
mechanical impact.

Before we design a system to generate electronic sound on FPGA, we have


to understand some common knowledge of musical scales. A Piano usually
has five or six groups, each group has 12 keys. Pressing different 12 keys
will produce notes in different periodic frequencies, often written as
C~C#~D~D#~E~F~F#~G~G#~A~A#~B. Frequencies can be heard by
human beings are generally among 20Hz to 20,000Hz. The note A has
frequency 440Hz and it is called international standard note, which is often
used in instruments adjustment and calibration.

A Musical scale of electronic piano is a periodic wave. According to Fourier


Transform, this periodic wave is superposition of fundamental wave and
different harmonics. The fundamental frequency decides which musical
scale it sounds like (i.e. Do, Re, Mi, Fa, So, La, Si, in 7-note scale). The
proportion of harmonic decides the timbre of a musical scale, which can
distinguish different types of musical scales even they have same
fundamental frequency (i.e. both piano and clarinet can produce the note A
in 440Hz, the two A still sound different because they have different
proportion of harmonics). Harmonic in music area is also called overtone.

Figure 1. Traditional Piano with six groups of notes

In order to generate a musical scale on FPGA, first, we have to produce a


sinusoidal wave as fundamental wave. Then, fundamental frequency
multiplied by integers can bring out different harmonics. By adjusting
proportion of harmonics, we can finally get a musical scales that sound like
generated from real piano. [1]

In addition to the electronic tone system of generating musical scales on chip,


another achievement is a smart keyboard sensor to measure the force when
pressing keys. Therefore, the volume of musical scales varies according to
different key pressure. [2]

2.1 Producing a sinusoidal wave on FPGA.


The design will be implemented on Altera Development and Education
Board II (DE-2). The FPGA on DE-2 is Cyclone II EP2C35 with 35000 LEs.
We use Quartus II software to design the electronic tone system.

The DE-2 provides a system clock with 50MHz. First, the system clock
should be subdivided into a slower frequency. Then the slower frequency is
used to drive an address generator to produce 7-digital-bit address signal.
Finally, the address signal will be connected into a RAM which has a
discrete sinusoidal wave table. The RAM should be initialized by a Memory
Initialization File (MIF). The depth of the discrete sinusoidal wave is
7-digital-bit, correspondingly same with that of address signal, which means
the sinusoidal wave has 128 discrete points at time-axis. The width of the
discrete sinusoidal wave is 8-digital-bit, indicating the amplitude of the wave.
[3]

address RAM
system
f clk [6:0] depth*width: D/A
clk Frequency Address Amplitude
128*256 Converte
Divider Generator [7:0]
Sine Wave r
Table

Figure2. Using Frequency Divider, Address Generator, and RAM to


produce a sinusoidal wave

V ( wt ) Ak sin( kwt k )

The frequency of sinusoidal wave kw is determined by coefficient DivFactor


of Frequency Divider and AddrLength of Address Generator.

2 Fsys Fsys
kw 2f 2 2 (Fsys=50MHz)
T AddrLength DivFactor 128 DivFactor

The phase of sinusoidal wave k is determined by initial value of Address


Generator AddrInit. However, the phase has no effect on form of sinusoidal
wave. This parameter is just employed to show programmability the system.

AddrInit
k 2
AddrLength

The RAM is a memory initialized with discrete sinusoidal wave. It is driven


by Address Generator and it will produce the sinusoidal wave in different
frequencies according to the growth speed of address generator.

RAM Sine Wave Table


0 1 2 3 4 ... ... ... 128
128 256 128 0 128
y

addr

Figure 3. Sine Wave Table in RAM


RAM Depth RAM Width
0x00 0x7f
0x01 0x82 Amplitude
0x02 0x90
Frequency Address
Divider Generator 0x03 0xa0
t

t is time-axis, it can also be


explained as address-axis.
0xff 0x70

Figure 4. Relationship between Address Generator and Depth and Width


of RAM

2.2 Superposition of sinusoidal waves to produce periodical wave

We can produce sinusoidal waves in any frequencies on FPGA by method in


2.1. However, to obtain the periodical wave of a certain musical instrument
scale, we have to make the superposition of fundamental wave and its
harmonics. The frequency of fundamental wave kw determines the
frequency of periodical wave while the proportion of harmonics K ji
determines the timbre distinguishing which instrument the musical scales
sound like. In this way, not only can the musical scales of piano be generated
on FPGA. It is possible to produce sound of any instruments if their
harmonic proportion is known.

Generally, harmonics become too weak to be heard after 10 times of


fundamental frequency. We have 16 harmonics in our system to guarantee
the accuracy of superposition.

n
V j
'

i m
K ji Sin( w jit ji )
Amplitude

On the time basis, make summation of fundamental wave and harmonic waves
Amplitude 1

Amplitude 2

Amplitude n

Make superposition at
each time points
Vo

n
Vo Vi
i 1

Figure5. Superposition of sinusoidal waves

2.3 Envelope
Vj` means the Superposition of sinusoidal waves, but there is a final step
before the electronic sound could simulate the sound of real piano. When
users keep pressing the key of instrument like piano, the sound will become
weaken and finally disappear. However, as for violin or some other
orchestras, when users vibrate the strings of violin, the sound will continue.
So we need envelop to describe this feature among different instruments. [4]
n
V j K b (t ) V
i m
iom Sin( w ji t ji )
Figure6. Kb(t) is the envelope function. It is 10-digital-bit signal.

3. Developing of Electronic Tone System on chip using Quartus


II and Nios II software

We will realize our system according to the design in part 2 on FPGA.


address
[6:0] V_data
RAM
[7:0]
system clk f clk depth*width:
Frequency Address
128*8
Divider Generator Sine Wave
Table
A_data
[7:0]
Voltage_data
Envelope [15:0]

address
[6:0] V_data
RAM Voltage_data
[7:0]
system clk f clk depth*width: [15:0]
Frequency Address D/A
Divider Generator
128*8 Converter
Sine Wave
Table A_data
[7:0]

Envelope

address
[6:0] V_data
RAM [7:0] Voltage_data
system clk f clk depth*width: [15:0]
Frequency Address
128*8
Divider Generator Sine Wave A_data
Table [7:0]

Envelope

Figure7. Overview of the whole design in part 2


Figure8. Top Layer in Quartus II software

Figure9. Frequency divider and Address Generator of fundamental wave


and 16 harmonics

Figure10. Superposition of sinusoidal waves and the superposition


multiplied by function of envelope Kb(t)
Figure11. The whole system is controllable over Nios CPU. Parameters,
such as Frequency DivFactors, envelope functions are all programmable,
and they can be modified by PC through UART.

Figure12. Wm8731 is controlled by IIC Bus

Finally, we use the audio chip Wm8731, which is provided on DE-2 board,
to make the electronic tone can be heard through headphones or speaker. The
audio chip Wm8731 is programmable through IIC Bus. It has a High
definition D/A converter inside and supports 32-bit digital audio signal. So
that the high quality of electronic piano can be guaranteed.
To change parameters of Wm8731, we write a VHDL interface to connect
Avalon Bus of Nios CPU and IIC Bus. Therefore, the data can be written
into Nios CPU from PC through UART and then transferred to the Wm8731
through IIC Bus. [5]

Figure13.This is the international standard electronic note A with


frequency 440Hz produced on FPGA. The oscilloscope measures the
waveform from Wm8731.

Figure14. Electronic tone measured by Adobe AUDITION software.


Figure15. This is the spectrum analysis of the electronic tone provided by
Adobe AUDITION software. We can see proportion of different
harmonics.

4. Keyboard Sensor

The keyboard sensor is designed to measure the force of pressing keys. Each
key sensor is mainly based on a capacitance oscillator. When we press a key,
the area of plate is changed. Therefore the value of capacitance changes and
period of oscillator varies as well. We use the counters, which are designed
onto FPGA, to measure the oscillation period. The numbers attained from
the counter is a real-time signal and indicates the key pressure. After linear
transformation, we can get parameter K L (t ) to change the loudness of
electronic musical scale according to the volume when pressing keys.
n
V j K L (t ) K b (t ) ViomSin( w ji t ji )
i m
(Multiplying 10-digital-bit parameter key pressure K L (t ) to the former
n
equation in part 2 V j K b (t ) V
i m
iom Sin( w ji t ji ) )

C A
kd The value of capacitance will change if the area varies.[6]

T C A The period of oscillator finally changes as user presses the key

Figure16.This is the circuit of oscillator using capacitance. LM393 is used


as the Operational Amplifier.

Figure17. Design of PCB( Printed Circuit Board) of the keyboard sensor.


We have our names on the top right corner of the PCB.
capacitance
s

capacitances flexible plastic material Value of capacitances change


to reset keys as pressuring keys

before pressing the key, after pressing the key, the frequency of
the frequency of oscillator is 43Khz oscillator is 33Khz,become longer
Figure18.Connecting the keyboard sensor to DE-2

The counter starts as the key is pressed

Signal from the oscillator

The counter stops as the key reaches bottom

5. Summary

Our system produces electronic tone on FPGA mainly by superposition of


sinusoidal waves. Nios CPU is used to control the system parameters. The
accuracy and length of parameters make sure that the electronic tone
produced by our system is high qualified. Moreover, the design is based on
FPGA and tech of SOPC, so it can be developed easily in the future updating
or even perform like other instruments besides piano. The keyboard sensor is
designed to measure key pressure.
References:
[1] Rui Yang and Yue Liu, Summary of Electronic Piano System Design,
Project Presentation, 2009

[2] Qiwu Liu and Qiwen Liu, Maintain of electronic piano, Beijing
Publishing House of Electronics Industry, 1991.1 ISBN: 7505312103

[3] Wei Jin, Shiqing Qi and Jianguo Wang, Modern detection technology,
Beijing University of Posts and Telecommunications Press, 2007.6 ISBN:
7563511180

[4] Dan Lin, Arbitrary Waveform Generator Based on SOPC, College of


Electronic Science and Technology, Shenzhen University, 2007.5

[5] Song Pan and Jiye Huang, Electronic Design Automation Technique,
Science Press, 2009.1 ISBN: 9787111275817

[6] Chengying Hua and Shibai Tong, Analog Electronics (forth edition),
Higher Education Press 2006.1 ISBN: 704018922

You might also like