Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > 0-50kHz variable square wave in 1Hz step

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



0-50kHz variable square wave in 1Hz step
Moderator:
ANCY

Post Reply
Follow this topic



0-50kHz variable square wave in 1Hz step

Danielek posted on 22 Feb 2011 11:02 AM PST
Member
3 Forum Posts

Hello,

I try to built a square wave generator in PSoC5( range ca.0-50kHz in 1Hz step). With PWM it works fine, but the steps are not linear. Please, can someone of you sent me an example.
I hope, somebody can help me
Thanks a lot !!!!!
Daniel



Re: 0-50kHz variable square wave in 1Hz step

posted on 22 Feb 2011 05:39 PM PST
Top Contributor
99 Forum Posts

Are you trying to change the PWM parameters via APIs at run-time?

 

-Bobby



Re: 0-50kHz variable square wave in 1Hz step

Gautam Das posted on 23 Feb 2011 05:43 AM PST
Cypress Employee
742 Forum Posts

Hi Danielek,

This can be implemented using a 16bit PWM component.

I'll upload a project shortly.

 

Regards,

dasg

 



Re: 0-50kHz variable square wave in 1Hz step

DPG posted on 11 Mar 2011 05:44 AM PST
Member
3 Forum Posts

 I've just done this using a counter (16-bit) producing 200Hz to 900KHz on a 24MHz clock. I know exactly what you mean about the non-linearity (f=1/T)!

The code I wrote for the loading of the conter is:

                                        count=(abs((1/counter)*(scale)));

compare=((count)/2);

Counter_1_WritePeriod(count);

Counter_1_WriteCompare(compare);

 

where "count" (uint16) is  the number to load into the Counter

"counter" (uint16) is the value of your pot or encoder for inputting the frequency

"scale"  is simply the range of frequency required.

I am using this to generate quadrature encoder output frequecy using a flag for direction change (hence the use of "abs" - as I'm generating the +/- elsewhere.

 

Hope it helps!

 

Dan



Re: 0-50kHz variable square wave in 1Hz step

Gautam Das posted on 12 Mar 2011 10:49 AM PST
Cypress Employee
742 Forum Posts

Hi,

 

Generating square wave of increasing frequency from 0Hz to 50KHz in steps of 1Hz might not be possible in a straight forward manner.

For example, increasing the frequency in steps of 1Hz, that is, 0Hz, 1Hz, 2Hz - - -  49,998Hz, 49,999Hz and then 50,000Hz using only a single PWM looks quite tricky.

Can anyone come up with algorithm/ strategy to attain this?

 

Regards,

dasg



Re: 0-50kHz variable square wave in 1Hz step

Danielek posted on 12 Mar 2011 02:28 PM PST
Member
3 Forum Posts

Thanks for the replies.
I have already solved the problem. I used a DDS (AD9833).
AD9833 is very easy to use and works very well with SPIM User Module of PSoC 5.

Thanks

Danielek






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: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20