Recommended Posts

Hi everybody!

I'm going through the wonderful Hamstrer book with the help of my Papilio Pro I'm having trouble with the Chapter 16 tutorial about the Delta-Sigma DAC, in creating the required sine wave samples to place in the COE file of the FPGA ROM.

The suggested formula is "f(n) = int((sine(n*PI()/1024)+1)*100)+128" that, as the texts says, "will give you values between 28 and 228 that you can use".

How could I generate such values ?

Any help is really appreciated.

Thanks a lot !

Share on other sites

Hello, I haven’t tried it myself but maybe you could use excel or mathcad or maybe even wolframalpha.

Sent from my iPhone using Tapatalk

Share on other sites

I've tried with Excel, but I cannot obtain values between 28 and 228.

I've simply applied the formula to values from 0 to 1024, what am I doing wrong?

Thanks again.

Share on other sites

That's a math question rather than an FPGA question.

I know that I've found read-made sine tables out there before, if math is not your thing you can probably find one already made. Another option is to just make something up using ballpark values, you don't even have to make it a sine wave, you can use the DAC to generate any arbitrary waveform you want.

Share on other sites

Thanks !

You're right, it's a math question and not a proper FPGA problem.

I'm now using this formula:

127*SIN(n*2*pi/256) + 128

Almost surely I'm wrong, but I have the sentation the formula in Hamster book cannot give the expected 28 to 228 values.

Thanks again.

Share on other sites

Quote

The suggested formula is "f(n) = int((sine(n*PI()/1024)+1)*100)+128" that, as the texts says, "will give you values between 28 and 228 that you can use".

Ok let's look at the formula. I have not actually read that part in the manual.

For the sine argument it splits the full 2*PI range into 2048 entries - so if "n" on that argument ranges from 0 to 2047, it will yield a sinewave across the full 2*PI (360 degrees). It would probably made more sense to write it as "sine( (n/2048) * (2*PI) ). Assuming you indeed want the 360 degree waveform,
The waveform amplitude is given by the "100" value - since the output from sine() will be between -1 and +1, the output range [ of (sine(n*PI()/1024)+1)*100) ] will be from -100 to +100.
Since you need to bias the output for 1/2 VCC (it's an 8-bit output, no negative values, hence ranges from 0 to 255, "zero" is depicted by 128) you add the 128 bias. That will make the output range from 128-100=28 to 128+100=228.
You can change the amplitude at will between 0 and 127.

Exactly how to create the COE file... long time I used such tools.

Alvie

Share on other sites
perl -e 'use Math::Trig qw/pi/; foreach my \$n(0..2047) { print int(128+100*sin(\$n*2*pi/2048)), "\n"; }'

You should be able to translate this to other languages as well.

Share on other sites

Hi Alvie !

First of all thank you for you taking the time for such a thorough answer: really appreciated I've used Excel in order to calculate the sine sample values, and your last formula:

int(128+100*sin(\$n*2*pi/2048))

works as expected , giving values between 28 and 228, with 'n' from '0' to '2047'.

The problem in Hamster Book's formula seems to be the '+1' after the sine (sine(n*PI()/1024)+1)*100), that you have ignored in your formula, that makes the multiplier of '100' to be between '0' and '2', instead between '-1' and '1', giving as a result a different range of values.

Now to my Papilio ! Thanks again.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account