Help with Hamster Book tutorial (newbie stupid question inside)


weirdocollector

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 !

 

Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.