1 Reply Latest reply on Jul 20, 2020 11:59 AM by RakshithM_16

    PWM Buzzer with PSoC4


      Hi all,


      I used the piezoelectric buzzer on PSoC 6 before, so I made a similar one on PSoC 4.



      The environment used is as follows:

      PSoC Creator 4.3



      The buzzer sounds if you simply set the PWM to the audible range and output it, but I expressed it using another PWM so that it would be beep sound like pi, pi, pi... The image of the output waveform is as follows:


      PWM_1 creates the period of sound output, and PWM_2 creates the frequency of the sound. The kill input of PWM_2 is used to control whether or not the sound output. The circuit is as follows:


      PSoC 4's TCPWM has a slightly different display of component settings than PSoC 6, but you can do the same thing. The LED pin is output to check the period. The piezoelectric buzzer is connected to Buzzer pin and via 1kΩ to GND. If you want a louder sound, connect it to the output of pwm_n in PWM_2 instead of GND.


      PWM_1 creates period of buzzer with 1MHz of Clock_1 as the clock input. PWM_1 is a PWM (check "PMW" in Configuration" tab in the component), and it is divided into 10Hz (100mS) by Prescale=”x2” and Period=49999 in “PWM” tab. The settings are as follows.




      PWM_2 is where you set the frequency of the sound. The frequency of the sound is decided by inputting the clock of 1MHz and dividing this. This time, 2KHz (Period=499) and 50% duty (Compare0=250). If you want to change the frequency of the sound, change the Period value here. We recommend a duty of 50%. Otherwise, the sound will be a bit dirty.

      In order to control the output of PWM_2, a Start/Stop input is provided, and the edge of the input signal of line coming from PWM_1 is used as a trigger to start and stop with a trigger. The setting of PWM_2 is as follows.




      Pin settings are output only. LED is set to P3[6] (green LED) and Buzzer pin is set to P3[0]. The parameter setting of the pin is the same for both, check the Digital output and HW connection, and set the Drive mode to “Strong Drive”. The settings are shown below.




      The program in main.c is simple. Since the PWM is only started, the CPU will be released when the setting is completed. The program is below.


      #include "project.h"
      int main(void)
          CyGlobalIntEnable; /* Enable global interrupts. */
          /* Place your initialization/startup code here (e.g. MyInst_Start()) */
              /* Place your application code here. */