Thursday, April 29, 2010

Organ FPGA First version (Simulated)


Here it is, the first version of the code. I tried to use a BUFG to buffer the 2mhz clock I'm generating for the clock dividers, but for some reason Xilinix ISim didn't seem to want to simulate it (I was probably doing it wrong.)


`timescale 1ns / 1ps

module clk2freq(
input clk2mhz,
output [4:0] notes
);
parameter ctarget = 239;
reg [10:0] ctr;
reg [4:0] out;
initial ctr = 0;
initial out = 0;
assign notes[4:0] = out[4:0];

always @(posedge clk2mhz) begin
ctr = ctr + 1;
if (ctr == ctarget) begin
ctr = 0;
out = out + 1;
end
end
endmodule


module main_clk_div(
input clk,
output mhz2
);

reg [3:0] div_clk;
initial div_clk = 0;
assign mhz2 = div_clk[2];

always @(posedge clk) begin
div_clk = div_clk + 1;
end
endmodule

module organ(
input clk16,
output [4:0] c_notes,

output [4:0] cs_notes,

output [4:0] d_notes,

output [4:0] ds_notes,

output [4:0] e_notes,

output [4:0] f_notes,

output [4:0] fs_notes,

output [4:0] g_notes,

output [4:0] gs_notes,

output [4:0] a_notes,

output [4:0] as_notes,

output [4:0] b_notes
);


// create a 2mhz clock generator
wire clock2mhz;
main_clk_div main_clock_gen(clk16, clock2mhz);


clk2freq #(239) c_generator (clock2mhz, c_notes);

clk2freq #(253) b_generator (clock2mhz, b_notes);

clk2freq #(268) as_generator (clock2mhz, as_notes);

clk2freq #(284) a_generator (clock2mhz, a_notes);

clk2freq #(301) gs_generator (clock2mhz, gs_notes);

clk2freq #(319) g_generator (clock2mhz, g_notes);

clk2freq #(338) fs_generator (clock2mhz, fs_notes);

clk2freq #(358) f_generator (clock2mhz, f_notes);

clk2freq #(379) e_generator (clock2mhz, e_notes);

clk2freq #(402) ds_generator (clock2mhz, ds_notes);

clk2freq #(426) d_generator (clock2mhz, d_notes);

clk2freq #(451) cs_generator (clock2mhz, cs_notes);


endmodule




What's next? Route all the signals to IO pins and test this sucker.

More FPGA Organs


The Vox Jaguar was a lower model organ that Vox put out. It features a much simpler design, for example, each key only has one switch, instead of each key having multiple switches fed into multiple audio busses like the Continental. It also only has 4 possible harmonics and thats only on certain keys.

From looking at the schematic, it appears the Jaguar only generated 44 tones, which is possible from my FPGA dev board. Also the wiring is a little less complicated, also I have a keyboard removed from a broken synth which I could use for keys.


Excellent.


Also, I could add dividers later on if I wanted to add more keys or harmonics, etc.

Tuesday, April 27, 2010

<3

I have the Crossway ESV Bible "Verse of the Day" android widget for my phone, and today it gave me a nice golden nugget:

He has told you, O man, what is good; and what does the Lord require of you but to do justice, and to love kindness, and to walk humbly with your God
-- Micah 6:8



This really moves me. Sometimes we want to boil everything down to a set of rules; "If I do X, Y will happen. If I do A, God will like that because of B, I shouldn't do C. Do this, Do that."

But this isn't what we read, it tells us, we know what's good, so let's "Do Justice", let's "love kindness" and "walk humbly".

It reminds me of when Paul says:


If I speak in the tongues of men and of angels, but have not love, I am a noisy gong or a clanging cymbal. And if I have prophetic powers, and understand all mysteries and all knowledge, and if I have all faith, so as to remove mountains, but have not love, I am nothing. If I give away all I have, and if I deliver up my body to be burned, but have not love, I gain nothing.
-- 1 Corinthians 13:1-3


God tells us in Micah, that "We know what is good", but as with all things, if we try and do these things without love, it's useless, because this is the central part of our beings: Love.

This goes along with "Walk Humbly", like Paul also says "Knowledge puffs up, but love builds up.". If we know what is good we can sometimes rest of this knowledge alone, "puffing" us up, giving us an inflated sense of things, We can say"Oh I've read the entire Bible 14 times this year, I can recite the Sermon on the Mount from heart...", but without love, all of this knowledge is useless.

We can't really help our fellow brothers (and sisters) without loving them. Without love we can't genuinely care about them enough to help them, why? Because we just do the bare minimum and then move along, and people can tell easily if we are being genuine or doing it 'just because'.


"A new commandment I give to you, that you love one another: just as I have loved you, you also are to love one another. By this all people will know that you are my disciples, if you have love for one another."
-- Jesus (by way of John 13:34-45)



Or in the words of the Great Rufus:


Be Excellent to one another.

FPGA Fun begins.



I have recently dived into the world of FPGA, via the purchase of the Avnet Spartan-3A Evaluation Kit priced a rather marvelous $49.

For those of you who are interested in diving into this as well, I highly recommend that you do not use Avnet's Avprog software to program the device, it is terrible. I've had pretty good success running Xilinx's Webpack ISE dev environment on linux (Ubuntu 9.10) using ASTriAEKiPro to program the SPI flash on the board.

My first project? A while ago I was digging into the schematics of the Vox Continental Organ (think: The Doors / Light my Fire), in an attempt to see how it would be possible to produce something similar using modern components.






thanks to combo organ heaven for the images


In this image you can see the guts of this monster. Above the keys, you can see there are 12 identical boards in a row. These are the tone generators, and their operation is quite simple.







The boards consist of a LC oscillator producing a square wave. For each of the 12 boards this oscillator is generating a square wave for the each musical note (i.e C, C# ... B), which you can see to the left of the board shown here. The repeated sections you see going right are the frequency dividers that take this top frequency and divide the frequency in half to get the same note one octave lower, and then another divider divides that in half, and another divides that, and another.. 6 times. This gives us 6 octaves for each note. Each key on the keyboard has a number of switches which routes one of these signals onto a number of audio busses, the volume of which is controlled by the distinctive organ drawbars.


Later on, transistor organs replaced these components with ICs. There was one IC called a "Top Octave Generator" which, when given a ~2mhz clock generated the top frequencies for the musical notes by dividing this clock by some constants:



Note Constant
C -> 239
B -> 253
A# -> 268
A -> 284
G# -> 301
G -> 319
F# -> 338
F -> 358
E -> 379
D# -> 402
D -> 426
C# -> 451


These where then fed into a clock divider IC to generate the rest of the notes. These clock dividers are simply binary counters.


My initial (non-fpga) design, involved using 12 PIC 12F683 ICs to generate the top musical frequencies. This ICs have a fairly good and stable internal oscillator and the code to divide this by a certain number is fairly trivial. Instead of using the internal timer to do generate this wave, I just used a big block of NOPs that delayed the amount of time needed in between each flip of the square wave, and i generated the right number of NOPs from a script. I then took this musical square wave from the PIC and fed it into a CMOS 4024 7bit counter IC. This gave me pretty usable results.

The only thing left to do was to program 12 PICs with 12 individual timing programs, connect them to 12 4024 counters, and then begin the giant wiring bundle to make it work (each key would need to fire 4 tones, there's 61 keys...)

It was at that point that I stopped working on this project.


However, it suddenly occurs to me that an FPGA could easily perform the function of those 24 chips. I can quite easily divide the 16mhz clock on this fpga board into 2mhz, and I can quite easily divide that into 12 seperate musical square waves, and i can very easily divide those 12 square waves into several octave square waves. The real big issue with this board is the number of user IO pins available, which is about 40+, which is not enough tones. The vox continental had 12 divider cards with 6 octaves each, thats 12 * 6 = 72 individual square waves, and therefore I'd need 72 pins of user IO. I could fix this by having the board only output the 12 top octaves and then use the cmos divider chips again, but that kind of defeats the point, having an fpga generate 12 square waves is pretty much overkill.


However, since this is just a starter project to cut my teeth on fpga, I decide I'm just going to have the fpga output 3 octaves per note, which is 36 tones as a proof of concept. One day, If I decide to build the full on organ and undertake the massive wiring project, I can easily obtain an FPGA that has the right number of IO pins.


After this, I suppose I will have the write the obligatory FPGA pong program.