Psoc 5lp Square wave generation varying duty

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

cross mob
Andrew7
Level 3
Level 3
25 sign-ins 10 questions asked 10 replies posted

Create a Square Wave (0 – 5 V) where frequency lies in the range of 150 Hz to 15 kHz with
varying duty (1 % resolution).  (USE PWM BLOCK)

0 Likes
1 Solution

Hi @Andrew7 ,

If you want to vary the frequency then it can be altered from firmware.

At first, take a clock and configure source to IMO (3 MHz) and a PWM with period value as 1 to vary the frequency. (Kindly refer the attachments given below)

Rakesh_Patrudu_0-1662004546077.pngRakesh_Patrudu_1-1662004555530.png

For varying frequency from 150 Hz to 15 KHz.

  • While configuring the clock, if divider is 10000 so you will get 150 Hz:

             Input clock/divider = 3 x 106 / 10000 = 300 Hz

             Now the period of PWM is 1 so, 300/2 = 150 Hz

  • Similarly, if divider is 100 then you will get 15 KHz:

             Input clock/divider = 3 x 106 / 100 = 30000

             Now the period of PWM is 1 so, 30000/2 = 15000 Hz = 15KHz

Now you got the divider values, so you need to vary divider from 10000 to 100 to vary frequency from 150 Hz to 15 KHz. (Take a loop and use Clock_SetDividerValue() API in firmware to assign the divider). As per your functionality adjust both clock divider and period of a PWM.

Best Regards,

Rakesh

View solution in original post

0 Likes
6 Replies
Rakesh_Patrudu
Moderator
Moderator
Moderator
25 solutions authored 5 likes given 50 replies posted

Hi @Andrew7 ,

If you want to create a square wave between 150 Hz and 15 kHz, kindly Change the input clock's frequency and alter the period value to generate a square wave in the desired frequency range. Can you please be more specific about the frequency, whether it should be dynamic or static within the range, and the duty cycle you want to vary.

Best Regards,
Rakesh

0 Likes
Andrew7
Level 3
Level 3
25 sign-ins 10 questions asked 10 replies posted

Frequency should be variable 

0 Likes

Hi @Andrew7 ,

If you want to vary the frequency then it can be altered from firmware.

At first, take a clock and configure source to IMO (3 MHz) and a PWM with period value as 1 to vary the frequency. (Kindly refer the attachments given below)

Rakesh_Patrudu_0-1662004546077.pngRakesh_Patrudu_1-1662004555530.png

For varying frequency from 150 Hz to 15 KHz.

  • While configuring the clock, if divider is 10000 so you will get 150 Hz:

             Input clock/divider = 3 x 106 / 10000 = 300 Hz

             Now the period of PWM is 1 so, 300/2 = 150 Hz

  • Similarly, if divider is 100 then you will get 15 KHz:

             Input clock/divider = 3 x 106 / 100 = 30000

             Now the period of PWM is 1 so, 30000/2 = 15000 Hz = 15KHz

Now you got the divider values, so you need to vary divider from 10000 to 100 to vary frequency from 150 Hz to 15 KHz. (Take a loop and use Clock_SetDividerValue() API in firmware to assign the divider). As per your functionality adjust both clock divider and period of a PWM.

Best Regards,

Rakesh

0 Likes
shuvra1
Level 5
Level 5
100 sign-ins 10 likes given 100 replies posted

Can It be used as Square wave Voltammatry??? Let me know.

0 Likes
shuvra1
Level 5
Level 5
100 sign-ins 10 likes given 100 replies posted

Can It be used as Square wave Voltammatry??? Let me know.

0 Likes

shuvra1,

It is my understanding that voltammetry requires varying voltage levels.  The PWM output directly only supplies 0V (Vss) and VDDIO (usually 5V).

Len
"Engineering is an Art. The Art of Compromise."
0 Likes