You are here

Sinewave using PSoC3/5 | Cypress Semiconductor

Sinewave using PSoC3/5

Summary: 4 Replies, Latest post by H L on 14 Dec 2011 01:54 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
abunaik's picture
1 post


I have used the following code to generate a sinewave for freqiency 1 kHz.. But the frequency o/p that I'm getting is 35 Hz. Can anyone suggest me where I'm goin wrong? Also how do I use sine function with GCC compiler. If not supported, what's the other alternative ?

 #include <device.h>
#include <math.h>

#define PI 3.14159265

void main()
   float frequency = 10000.0;
   float sample_per_seconds = 50000.0;
   int var=0;
   int i=0;
   i = 0;
  var = 255*(0.5 *(sin(2*PI*frequency*i/sample_per_seconds))+0.5);


user_78878863's picture
2553 posts

Since you do a lot of calculation inside of your loop, it might be just run much more slowly than you (esp. the sin() call might be slow). Actually, the recommended way is to use a DMA transfer. There used to be a application note about this, but its under review right now. But you can look at this app note: (example #3) and this blog post: to get an idea.

user_66945721's picture
256 posts

One word,WaveDAC8!

Heres more on that: Making Waves with the WaveDAC8 PSoC Creator Component

Its still a concept component,but I've used it and it does the job quite well,not to mention the extreme ease of use.

user_1377889's picture
9300 posts

Yes, as posted before WaveDAC8 is a pretty good module for sine-waves.


I have another subject on your code: You write

if (i==50000) i=0;

Although it is obvois in this short program that this will work error-free I wouls insist in writing


if(i >= 50000) i= 0;


which would work correctly even when i is 50001 whatever the reason for this might be.

Save coding



user_460349's picture
1362 posts

1. Set the Psoc CPU clock to 48mh or as high as your chip can support.

2. remove the delay loop

3. This is the fastest you can do with your program.

4. flaoting point use a lot of instruction, if you are not goint to use wave8 as suggest. Then you should see if you can use a table to generate the output or use approxiamtion formula.

Log in to post new comments.