6 Replies Latest reply on Sep 27, 2016 5:40 AM by sulochana.pt.1919646

# 0-50kHz variable square wave in 1Hz step

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
• ###### 1. Re: 0-50kHz variable square wave in 1Hz step

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

-Bobby

• ###### 2. Re: 0-50kHz variable square wave in 1Hz step

Hi Danielek,

This can be implemented using a 16bit PWM component.

Regards,

dasg

• ###### 3. Re: 0-50kHz variable square wave in 1Hz step

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)!

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

• ###### 4. Re: 0-50kHz variable square wave in 1Hz step

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

• ###### 5. Re: 0-50kHz variable square wave in 1Hz step

Thanks for the replies.
AD9833 is very easy to use and works very well with SPIM User Module of PSoC 5.

Thanks

Danielek

• ###### 6. Re: 0-50kHz variable square wave in 1Hz step

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.