Skip to main content
j3lda
Associate II
March 9, 2013
Question

problem with generation of sine wave

  • March 9, 2013
  • 4 replies
  • 792 views
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.
    This topic has been closed for replies.

    4 replies

    Tesla DeLorean
    Guru
    March 9, 2013
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    M0NKA
    Associate III
    March 9, 2013
    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
    Super User
    March 9, 2013
    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!!
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    dusan2
    Associate II
    March 17, 2013
    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