0-50kHz variable square wave in 1Hz step

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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   
0 Likes
6 Replies
Anonymous
Not applicable

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

   

 

   

-Bobby

0 Likes
Anonymous
Not applicable

Hi Danielek,

   

This can be implemented using a 16bit PWM component.

   

I'll upload a project shortly.

   

 

   

Regards,

   

dasg

0 Likes
dan_DMI
Level 2
Level 2
10 sign-ins 5 replies posted 5 sign-ins

 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

0 Likes
Anonymous
Not applicable

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

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

Hi Danielek,

   

   How to do frequency sweeping on step 1 hz .sweeping from 1mhz on evert step 1 hz using AD9833.i am new to this.please help.

0 Likes