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 ?
#define PI 3.14159265
float frequency = 10000.0;
float sample_per_seconds = 50000.0;
i = 0;
var = 255*(0.5 *(sin(2*PI*frequency*i/sample_per_seconds))+0.5);
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: http://www.cypress.com/?rID=37793 (example #3) and this blog post: http://www.cypress.com/?rID=39390 to get an idea.
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.
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.
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.