3 Replies Latest reply on Jul 14, 2020 6:11 PM by NoTa_4591161

    PWM Buzzer with PSoC6(M4)

    NoTa_4591161

      Hi all,

       

      I wanted to make a device that uses a piezoelectric buzzer to generate sound, so I expressed it using PWM.

      1.jpg 

      The environment used is as follows:

      PSoC Creator 4.3

      CY8CKIT-062-BLE

       

      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:

      2.png

      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:

      3.png

      The LED pin is output to check the period. The piezoelectric buzzer is connected to Pin_1 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 uses the clock input of 1KHz of Clock_1 to create the period for buzzer sound. Divide it into 200 counts (Period=199) to obtain 5Hz (200mS). Of the 200 counts, the duty is set to 180:20 (90%) using Compare0. 20 counts is the time when the sound is generated by PWM_2. The settings are as follows. Please change the duty ratio according to your preference.

      4.png

       

      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. The setting of PWM_2 is shown below:

      5.png

       

      In order to control the output of PWM_2, it is possible to provide a Start/Stop (kill) input and use it as an edge trigger, but this time, Kill mode is asynchronous mode and the kill input is set to Level. The settings of Advanced tab are as follows:

      6.png

       

      Pin settings are output only. The LED is set to P1[5] (orange LED) and Pin_1 is set to P12[1]. 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 setting of Pin_1 is shown.

      7.png

      8.jpg

       

      The program in main_cm4.c is simple. Since the PWM is only started, the CPU will be released when the setting is completed. The program looks like this:

       

      #include "project.h"
      int main(void)
      {
          __enable_irq(); /* Enable global interrupts. */
          /* Start the PWM component */
          PWM_2_Start();
          PWM_1_Start();
          for(;;)
          {
              /* Place your application code here. */        
          }
      }
      

       

      Thanks,

      Kenshow