Quantcast
Channel: Endless sine generation in C - Stack Overflow
Browsing latest articles
Browse All 13 View Live

Image may be NSFW.
Clik here to view.

Answer by Tim V for Endless sine generation in C

Fascinating thread. Minsky's algorithm mentioned in Walter Mitty's answer reminded me of a method for drawing circles that was published in Electronics & Wireless World and that I kept. (Credit:...

View Article



Answer by Willa for Endless sine generation in C

I'd like to address the embedded programming issues in your code directly - @0___________'s answer is the correct way to do this on a microcontroller and I won't retread the same ground.Variables...

View Article

Answer by Walter Mitty for Endless sine generation in C

There is an alternative approach to calculating a series of values of sine (and cosine) for angles that increase by some very small amount. It essentially devolves down to calculating the X and Y...

View Article

Answer by MSalters for Endless sine generation in C

I'm rather shocked at the existing answers. The first problem you detect is easily solved, and the next problem magically disappears when you solve the first problem.You need a basic understanding of...

View Article

Answer by tshiono for Endless sine generation in C

How about a variant of others' modulo-based concept:int t = 0;int divisor = 1000000;void control_loop() { t += 30 * 280; if (t > divisor) t -= divisor; double sine = sin(2 * M_PI * t /...

View Article


Answer by Robin for Endless sine generation in C

I think it would be possible to use a modulo because sin() is periodic.Then you don’t have to worry about the problems.double time = 0;long unsigned int timesteps = 0;double sine;void controll_loop(){...

View Article

Answer by 0___________ for Endless sine generation in C

How to generate a lovely sine.DAC is 12bits so you have only 4096 levels. It makes no sense to send more than 4096 samples per period. In real life you will need much less samples to generate a good...

View Article

Answer by r3mainer for Endless sine generation in C

If you have a few kilobytes of memory available, you can eliminate this problem completely with a lookup table.With a sampling period of 30 µs, 2500 samples will have a total duration of 75 ms. This is...

View Article


Answer by G. Sliepen for Endless sine generation in C

Use a look-up table. Your comment in the discussion with Eugene Sh.:A small deviation from the sine frequency (like 280.1Hz) would be ok.In that case, with a control interval of 30 µs, if you have a...

View Article


Answer by user3386109 for Endless sine generation in C

The function can be rewritten asdouble n;void control_loop() { n += 1; double sine = sin(2 * M_PI * 280 * 30e-6 * n); ...}That does exactly the same thing as the code in the question, with exactly the...

View Article

Answer by Jonathon S. for Endless sine generation in C

As noted in some of the comments, the time value is continually growing with time. This poses two problems:The sin function likely has to perform a modulus internally to get the internal value into a...

View Article

Answer by Yakov Galka for Endless sine generation in C

Instead of calculating sine as a function of time, maintain a sine/cosine pair and advance it through complex number multiplication. This doesn't require any trigonometric functions or lookup tables;...

View Article

Image may be NSFW.
Clik here to view.

Endless sine generation in C

I am working on a project which incorporates computing a sine wave as input for a control loop.The sine wave has a frequency of 280 Hz, and the control loop runs every 30 µs and everything is written...

View Article

Browsing latest articles
Browse All 13 View Live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>