Transcript
Demo Player Notes - Page 1 The complete circuit for a 4 channel electronic key board is contained in the document named "electronic_keyboard_circuit". You will recognize that the left hand side of this circuit is exactly what you designed in the last lab, except that this circuit is a four channel design instead of the two channel circuit you dealt with in the last lab; otherwise it is identical to the design of your last lab. As you already know the left hand side of the circuit uses a PS2 keyboard to play the electronic key board. We will call this mode the "play mode". The module PS2_KEYBOARD_4ch (blue module on the top left hand side) sends the appropriate key-codes of the keys being pressed on the Keyboard to the synthesizers in the channels of the left hand side of the circuit. The right hand side, which is the subject of this lab, does not use a keyboard, instead it uses a mif file (one per channel) that contains data about which keys are being pressed and the duration of time these keys are being pressed, depending on the music to be auto-played. In other words the mif file carries "recorded" music in the form of keys being pressed (keycodes) and the duration of time each key is being pressed. We will call this mode "autoplay mode". There is a separate mif file for each channel. Note that since an actual keyboard is not used in autoplay mode there is no restriction on how many keys can be pressed simultaneously since key press data is contained in mif files and is therefore not restricted by the hardware of a keyboard. Therefore four channel (or six channel) music can easily be auto-played without any problem. Also we are not restricted to the limited range of octaves we can play on a keyboard. An examination of the keycode map mif files provided to you (that you used in the last lab) will show that it contains an extended octave range. The job of the autoplay circuit, which is the topic of this lab, is to decipher the data stored in the mif files (one mif file per channel) and send the appropriate key-codes being used by the music to the channels on the left hand side. In other words the autoplay circuit replaces and plays the role of the PS2_KEYBOARD_4ch module for the left hand circuit. As far as the left hand circuit is concerned it does not care or needs to know whether key-code data is originating from an actual hardware keyboard or from the autoplay circuit reading the keypress music data from mif files. SW[17] controls (See [C]) whether key-code data originating from the hardware keyboard is being sent to the left hand circuit or the key code data from the mif files of the autoplay circuit is reaching the synthesizers on the left hand side.
Demo_Player_Notes Page 1
Demo Player Notes - Page 2 Your job in this lab is to start from where you left off your last lab and add a two channel autoplay circuit to it exactly as shown in the document named "electronic_keyboard_circuit". We will call the circuit in this document the EK-circuit (Electronic Keyboard Circuit). The rest of this document explains the various parts of the autoplay circuit. Note that important parts of the EK-circuit have been marked by bold letters in red squares; in this document these locations are referred to by using the letters and enclosing them in squarer brackets, i.e., the location marked by the letter "A" will be denoted as [A].
Location [A]
Note that in this lab you are required to build a two channel electronic keyboard and not a four channel circuit. Mistake in provided schematic: Quartus does not automatically connect pins to all lines with the same name. To fix the mistake, connect draw bus coming out of the SW[17..0] pin. Now name the bus SW[17..0]. Any line with name SW[#] will now be connected to the new bus and the pins to the switches.
Input pin bus is connected to switches. Location [B] The most common mistake in this lab is connecting the wrong lines to the multiplexer input ports. In this example GND is connected to data1x[7..0]. BE CAREFUL THE PORTS ON YOUR LPM_MUX'S MAY BE IN A DIFFERENT ORDER.
SW[1], SW[2], SW[3], SW[4] turn channels 1, 2, 3, 4 on or off. You may use your own switches for your circuit.
Demo_Player_Notes Page 2
Demo Player Notes - Page 3 Location [C]
SW[17] switches between play and autoplay mode. You may use your own switch for your circuit.
Location [D]
From 50 MHz clock
demoClock is the clock for the autoplay circuit. demoClock frequency = (clock frequency) / (constant stored in the lpm_constant) = 50 MHz/320000 In the autoplay mode when we say that a key is pressed N times, it means that that particular key is being pressed for a time duration of N*(demoClokc Period). The autoplayClock code will be provided to you as a VHDL file. Use that file to generate the symbol file for autoplayClock.
Demo_Player_Notes Page 3
Demo Player Notes - Page 4 Location [E]
This ROM contains the data from the mif file that contains the music data to be autoplayed. Each channel contains its own mif file. Note that the address of the ROM is 2^(6) = 64 bits wide. Therefore the mif file contains 64 rows of data ( 0 to 63). In the mif file each row contains 20 bits wide (5 HEX characters) music data. This music data (per row) not only encodes which key is to be pressed but also the duration of time that key needs to remain pressed. This information is encoded as follows (per row) in HEX notation (5 hex digits, ABCDE):
ABCDE key press duration
key-code
Here are the first 5 rows of data in the mif file provided to you for channel 1. Note that this row contains music data 0304c hex. This means that key with key-code 4c hex should be pressed for a duration of 30 hex. WIDTH=20; DEPTH= 64; ADDRESS_RADIX=DEC; DATA_RADIX=HEX; CONTENT BEGIN 0 : 10f0; 1 : 10f0; 2 : 10f0; 3 : 4052; 4 : 304c; 5 : 104b;
Demo_Player_Notes Page 4
Demo Player Notes - Page 5 Location [E] … continued ...
ABCDE
ABC (key press duration)
DE (key-code)
This part of the circuit extracts the key press duration data and key-code data from each row of the mif File. Now imagine that as the autorun clock ticks an imaginary cursor moves from row to row of this ROM in the following way: Assume that at any time the cursor has moved to a particular row of the ROM, also assume that the corresponding data of that row that appears at the output of the ROM is ABCDE (hex), i.e., key code DE (hex) and key press duration ABC (hex). As the autorun clock ticks we want the key-code to remain equal to DE for ABC (key press duration) number of clock ticks (since key with code DE should remain pressed for key press duration ABC amount of time). Thus we want the cursor to remain fixed at that line for ABC number of ticks, after this duration we want the cursor to move to the next row and remain fixed there for another key press duration number of ticks appropriate for that row. We want to move the cursor in this way for all the rows of the ROM (0 to 63) and when we reach the last row we want to repeat this all over again so that the music stored in the ROM can play continuously.
Demo_Player_Notes Page 5
Demo Player Notes - Page 6
Location [E] … continued …
For the mif files use demo_ch1.mif for channel 1 and demo_ch2.mif for channel 2.
Demo_Player_Notes Page 6
Demo Player Notes - Page 6
Location [E] … continued ... The movement of the imaginary cursor is controlled by this alt_accumulator (a Megafunction).
The accumulator increments the data stored in it by one every time it receives a 1 at data[0] at the rising edge of the clock. Its data remains unchanged when a 0 is received at data[0] at the rising edge of the clock. The accumulator starts from 0 (when aclr is set to 1) and counts to a maximum of 63, after that it resets to 0 and starts accumulating all over again. Note that the output of the accumulator is connected to the address bus of the ROM therefore the output of the accumulator is the imaginary cursor that moves from row to row of the ROM. Thus we need a pulse of 1 to appear at data[0] whenever we want to move the cursor to the next row. Recall that we want to move the cursor only after a number of key press duration cycles of the autorun clock have expired, therefore this pulse should arrive at data[0] after a key press duration number of ticks. This pulse is produced by the circuit in location [F].
Demo_Player_Notes Page 7
Demo Player Notes - Page 8 Location [F]
Line 1
ABC (key press duration) ABC ABCDE The lpm_counter in conjunction with lpm_compare produces the required pulse. At each tick of the clock it counts upwards by one. The comparator (lpm_compare) compares the two values dataa and datab at its input and puts a 1 on Line 1 (at the next rising edge of the clock) if the two values are equal otherwise it puts a 0 on Line 1. Thus Line 1 receives a pulse of duration one clock cycle whenever dataa and datab become equal. The counter sets itself to zero when it receives a 1 at sclr which is connected to Line 1. Thus whenever a pulse is produced on Line 1 the counter sets itself to zero and starts counting from zero again. Note that dataa is connected to the output of the counter and datab is connected to ABC (key press duration) belonging to the ROM's row at which the imaginary cursor is currently positioned. Thus at the clock tick when the counter reaches the value of ABC the two inputs of the comparator become equal and a pulse is placed on Line 1, at the same time the counter rests to zero. During the clock cycles when the counter is not equal to ABC a zero remains on Line 1. Recall that the imaginary cursor moves to the next row of the ROM whenever it receives a pulse , otherwise it remains put at the row. Thus we see that that a pulse is produced whenever ABC number of clock cycles have expired. Another look at the timing of the pulse shows that the pulse should be emitted a cycle after the counter reaches a value equal to ABC. Therefore we need to delay the pulse by one clock cycle before it reaches the accumulator. Location [F] contains the circuitry that performs this delay.
Demo_Player_Notes Page 8
Demo Player Notes - Page 9 Location [G]
One clock cycle wide pulse
Line 1
One clock cycle delay
Line 2 One clock cycle delayed pulse Six clock cycle pulse This location performs two actions. First, it delays the one clock cycle pulse on Line 1 by one clock cycle. Second, it uses the one cycle pulse on Line 1 to produces a pulse which is 6 clock cycles wide. The reason why we need a 6 cycle wide pulse is that when the cursor moves from one row of the ROM to another there is a sudden change of tone as one goes from one key code to another, which produces an unpleasant transition. To make the transition more pleasant we will introduce silence (key code F0 hex) for six clock cycles as the cursor moves from one row to another. To implement this silence we will need a six cycle pulse. These functions are accomplished by using a 5 bit wide shift register and a six input OR gate. As the pulse arrives on Line 1 at shiftin it serially moves through the five FlipFlops of the shift register with each tick of the clock. The 1 of the pulse jumps from FlipFlop to FlipFlop inside the register at each tick of the clock, therefore it remains inside the register for five ticks of the clock. The states of the FlipFlops insided the register are accessed in parallel via q1[4..0]. We connect Line 1, q1[0], q1[1], q1[2], q1[3] and q1[4] to a 6 input or gate. As the pulse is produced on Line 1, the line gets a value of 1. With the next clock cycle this value of 1 moves to q1[0]. At the next rising edge of the clock this 1 hops to q1[1]. Since an OR gate outputs a 1 as long as at least one of its inputs are high, it is easy to see that the output of the OR gate produces a six clock cycle wide pulse. It should also be apparent that there is a once clock cycle delay between Line 1 and q1[0], therefore Line 2 gets a one cycle wide pulse that is delayed by one clock cycle compared with the pulse on Line 1.
Demo_Player_Notes Page 9
Demo Player Notes - Page 10 Location [H]
Line 2 Six clock cycle pulse Make sure ck[7..0] is connected to data0x[7..0]
Line 3 During the time Line 2 is equal to 1 (i.e. throughout the duration of the six clock cycle pulse) the mul tiplexer puts key code F0 hex (240 decimal) on Line 3. During the time Line 2 is equal to 0 (i.e. absence of the six clock cycle pulse), Line 3 acquires the key code from the ROM. The mux's in the provided schematic may have the inputs listed in opposite order. Take care that you connect the appropriate line to data0x[] and data1x[] or your synthesizer will NOT work! Example: If ck[7..0] is connected to data1x[7..0] in the above schematic, the demo will chirp in the short transition between notes instead of playing music. Similarly Line 3 must be connected to data1x[7..0] in the schematic below.
Location [I]
Line 3
Finally the key codes from the ROM arrive at the multiplexer on the left hand side. If the electronic keyboard is set to autoplay mode then these keycode are directed to the synthesizers to play the appropriate music.
Demo_Player_Notes Page 10