cancel
Showing results for 
Search instead for 
Did you mean: 

problem with generation of sine wave

j3lda
Associate II
Posted on March 09, 2013 at 14:29

Hello, I am trying to generate sinusoid signal via DAC. I can´t use look up table of sine values, because user will enter amplitude. So values of sine are first computed in program and than stored in buffer:

sine[i] = (sin(2*PI*i/number_of_samples)+1)*((amplitude+1)/2);

But it isn´t generate anything. It is very strange because values are stored correctly. There is some problem with sine function. When I delete sin(), DAC works. Do you know why it doesn´t work with computing sin(x)? Thank you for answeres.
4 REPLIES 4
Posted on March 09, 2013 at 14:59

Ok, so what data is actually generated?

Can you show the complete loop, with variables?

Is it a problem with int vs float/double variables, and conversion/casting?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
M0NKA
Senior
Posted on March 09, 2013 at 16:43

Hi,

I generate sine wave(in the the audio frequency range), using pre-calculated 1024 point

table in flash. To edit the output amplitude i just multiply/devide each sample by a float

value. Although i am using external DAC, i think same technique should work on the

internal one.

Regards, Chris

Andrew Neil
Evangelist
Posted on March 09, 2013 at 23:19

''I can´t use look up table of sine values, because user will enter amplitude''

Of course you can  use a lookup table - it's just a matter of applying the appropriate scale factor to get the requested amplitude!!
dusan2
Associate III
Posted on March 17, 2013 at 14:46

Dear Pavel,

You might find a chapter on DDS (16th from the top) at

http://www.fmf.uni-lj.si/~ponikvar/STM32f407.htm

 useful.

Regards