Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® Software > Sinewave using PSoC3/5

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Sinewave using PSoC3/5
Moderator:
JFMD

Post Reply
Follow this topic



Sinewave using PSoC3/5

abunaik posted on 13 Dec 2011 3:03 AM PST

1 Forum Post

Hello,

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;
 
   VDAC8_1_Start();   
    
   for(;;)
   {
     if(i==50000)
   i = 0;
 
  var = 255*(0.5 *(sin(2*PI*frequency*i/sample_per_seconds))+0.5);
        i++;
  
  VDAC8_1_SetValue(var);
  CyDelayUs(20);
   }
}
 

 




Re: Sinewave using PSoC3/5

hli posted on 13 Dec 2011 06:50 AM PST
Top Contributor
675 Forum 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: http://www.cypress.com/?rID=37793 (example #3) and this blog post: http://www.cypress.com/?rID=39390 to get an idea.



Re: Sinewave using PSoC3/5

kmmankad posted on 13 Dec 2011 07:32 AM PST
Top Contributor
268 Forum 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.



Re: Sinewave using PSoC3/5

Bob Marlowe posted on 13 Dec 2011 10:27 AM PST
Top Contributor
1768 Forum 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

Bob

 



Re: Sinewave using PSoC3/5

H L posted on 14 Dec 2011 11:54 PM PST
Top Contributor
679 Forum 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.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20