Jump to content
  • 0

Producing sound using the PmodAMP2 and Vivado


RobinVDS

Question

Hello,

 

I'm making a project using Vivado, a Basys3 Atrix-7 FPGA Board and the PmodAMP2.

The purpose of this project is to make a digital piano, but i can't find the proper code to send a specfic frequency to the Pmod AMP2 using VHDL and Vivado.

Can someone help me out ? I'm pretty new to programming in VHDL.

 

Thanks !

 

Robin

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

@RobinVDS,

I have the PModAMP2!  I love the thing.  It's got some decent audio quality, especially when you play canned waveforms into it.  That means it should be able to sound like a nice digital piano, but ... gosh, there's a lot that goes on between playing a tone into an audio output and a fine-quality piano sound--more than I could ever coach you through.

What I can do, though, is point you at some examples of projects that use the PModAMP2, but I'll warn you: all my examples are in Verilog, not VHDL.

Here's the "core" I put together to control the PModAMP2.  As you are probably familiar, to create the tone in the PModAMP2 you will need to create a PWM waveform.  This is usually done by comparing a counter to a threshold, and producing a one if the counter is less than the threshold and a zero otherwise.  I've taken a twist on this approach and I like to bit-reverse the counter before the comparison.  The result has the same number of "on" vs "off" cycles as it would if it weren't reversed, but it spreads the distortion across higher frequencies which are easier to filter out within hardware.

Here's a design, using the CMod-S6, that uses the PModAMP2.  It plays a recorded sound (a doorbell) when a button is pressed.  It was a fun project to do.

But your request was to output a tone.  Usually, a tone starts with a counter.  You add to the counter a value proportional to the tone frequency.  This is then the phase of your tone, although in some rather strange units.  For example, if your clock rate is 80MHz, and you add a 1 to a 1 bit counter on every clock, you will produce a 40MHz ... waveform.  (I hate to call a square wave a "tone"--this is more of a square wave.)  If you have an 8-bit counter and add 1 to it on every cycle, you will produce a 312.5kHz waveform.  Adding 128 on every cycle will bring you back up to 40MHz and so on and so forth.  The counter will count from 0 to 2^N-1 before quietly rolling over, where N is the number of bits in the counter.  The "phase" such a counter produces can be mapped to 0 to 2pi--but without ever using the PI or the complicated multiplies that go with it.  As some examples ... :

One way to produce a tone from a counter like this would be to just grab the top bit, and send one value if the top bit is a 1, and it's negative if the top bit is a zero.  This is called a square wave.  It's not necessarily that pleasant on the ear, but it gets the job done.

You can do better by grabbing the top two bits and mapping them to 00->1, 01-> 0, 10 -> -1, and 11-> 0.

Another approach to making sound from such a counter is to just use the counter itself as your sampled bits.  This will produce something of a "triangle wave".  I'm told the digital audio guys use these extensively, but to be honest I don't know how.  I'm usually more into the sine wave's myself.

To produce a true sine wave, you'll need to either 1) use a table lookup: take the top W bits of your N bit counter, and use them in a table lookup fashion--a table of 1024 values isn't that hard to do, or 2) Use a CORDIC.  A CORDIC is a fairly simple circuit--it uses only adds and multiplies, subtracts and compares.  You can place your counter into the CORDIC and generate both a sine and a cosine wave with ... well, as much precision as you wish to put into the task and more precision than your PModAMP2 can handle.  The trick is, it takes some work to set up, some coefficients to find, etc.  There are several CORDIC implementations on OpenCores, so you might wish to take a peek and see if one does what you need.

Hope this helps, and I hope you enjoy your PmodAMP2 as much as I have enjoyed mine!

Dan

Link to comment
Share on other sites

@D@n

 

Thank alot for your very explaining comment !

I would just be happy with the digital sound. The problem is that I find alot of examples to use te PModAMP2 using Verilog, I have no knowledge in this program language.

Is there a tool where i can convert Verilog code to VHDL code ?

 

Thanks alot !

 

Robin 

Link to comment
Share on other sites

@RobinVDS,

I don't know of any such tool, but there are many people like you who would like such a tool.

Care to write it for them?  :D

In all seriousness, the languages aren't so different that you can't understand what's going on in Verilog if you understand VHDL well enough.  Well ... you'll at least get a vague idea of what's going on ...

Hope this helps encourages you!

Dan

Link to comment
Share on other sites

Regarding Verilog vs VHDL,

If you ever work on a complex FPGA project you will have to at least be able to read both languages because it's almost a certainty that your source code will include both, and possible more languages. The only way to deal with this is to dive in and learn how to code in both. Fortunately, the portion of either language that is synthesizable is a subset of the entire language. All FPGA vendors will tell you what aspects of both VHDL and Verilog their synthesis tool supports. Anyone developing FPGA code should be familiar with the vendor's HDL guidelines for a specific language. VHDL is a strongly typed language with lineage from Pascal and Ada and requires a lot of typing. Verilog is more similar to C and allows you write some code that's pretty hard to read for non-experts.  Both were developed for simulation and commandeered as a synthesis language, mostly by the FPGA vendors. Having said that I haven't run into many people equally expert in both languages and who also understand the electrical aspects of real world systems using programmable devices. It's a big world out there... get busy and expand your skills.. or get rich and hire minions to do the work for you ( or as more and more companies are doing convince people to do it for free ). But then you really don't have any control over what you want to do.

Just one person's viewpoint.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...