PWM Buzzer with PSoC6(M4) for Modus Toolbox2.1

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

cross mob
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi all,

Previously, I introduced the device that generates sound using the piezoelectric buzzer with Creator. This time, I introduce an example of realizing this with Modus Toolbox 2.1.

1.jpg

                   

The environment used is as follows:

Modus Toolbox2.1

CY8CKIT-062-BLE

The buzzer sounds if you simply set PWM to the audible range and output it, but I added an additional timer to express it so that it would be beep sound like pi, pi, pi...

In the Creator version, I expressed using PWM, but in Modus, the input signal from another PWM cannot be used for the PWM input. Also, since the circuit image is not represented in the tool in Modus, I will try to explain it as much as possible here.

1.5.png

Timer_1 creates a sound output period (5Hz), and PWM_2 creates a sound frequency of 2KHz. The start and kill/stop inputs of PWM_2 are used to control whether or not the sound is output. The circuit is follows.

2.png

 

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.

I will explain how to create a project. For Modus projects, click New Application from the Modus Quick panel, select "PSoC 6 BSPs>CY8CKIT-062-BLE", and click the Next button.

3.png

 

Then select “Empty PSoC6 App”, click the Create button, Close to create a new empty project on the Modus IDE.

4.png

    

After creating an empty project, click “Device Configuration” from the Quick panel to configure your component. And, open “Peripheral Clocks” tab and set the clock that is the clock input for PWM and Timer. Check "16 bit Divider1" and set "Divider" to 100 and output to 1MHz. The source for this Clock is CLK_PERI, which supplies 100MHz by default.

5.png


Go to "Peripherals" tab to configure the components to use.

The output pin Buzzer will use P12[0], but the only 16bit PWM that can be used at that time is TCPWM[1] 16-bit Counter 4pwm. Therefore, name TCPWM[1] 16-bit Counter 4 as "PWM_2", select PWM-1.0, and set it to output PWM with Period=499 (frequency 2KHz) and Compare=25 (duty 50%).  Select Clock Source = “16bit Divider 1 clk” as the clock source for PWM_2. Input Start and Kill (Stop) to control PWM. Modus cannot use the output from another PWM as input, but you can specify the output of the Timer. Here, I decided to use the timer output of the adjacent TCPWM[1] 16-bit Counter 5.  As the PWM input, select Start Input = "TCPWM[1] 16-bit Counter 5 overflow" and Kill Signal =" TCPWM[1] 16-bit Counter 5 compare". Kill Mode is "Stop on Kill". The settings of TCPWM[1] 16-bit Counter 4 are shown below.

6.png

The Timer uses "TCPWM[1] 16-bit Counter 5 ". Enter the name as "Timer_1" and select "Timer-counter". For the Clock Signal, select "16 bit Divider 1 clk" which is also used for PWM_1. For Clock Prescaler, select "Divide by 64", and set Period = "3124 "(frequency 5Hz) and Compare = "1500"(time when sound is emitted). As outputs, we have confirmed that Overflow and Compare are given to the input of PWM_1. The settings are as follows.

7.png


Pin settings open "Pins" tab. Pin "Buzzer" selected Drive Mode = "Strong Drive, Input Buffer off" as P12[0]. Select the PWM output "TCPWM[1] 16-bit Counter 4 pwm (PWM_2)" as Digital Output. The settings are as follows.

8.png

The program just starts setting up the PWM and Timer as shown below.

#include "cy_pdl.h"

#include "cyhal.h"

#include "cybsp.h"

int main(void)

{

    cy_rslt_t result;

    /* Initialize the device and board peripherals */

    result = cybsp_init() ;

    if (result != CY_RSLT_SUCCESS)

    {

        CY_ASSERT(0);

    }

    Cy_TCPWM_Counter_Init(Timer_1_HW, Timer_1_NUM, &Timer_1_config);

    Cy_TCPWM_PWM_Init(PWM_2_HW, PWM_2_NUM, &PWM_2_config);

    Cy_TCPWM_Counter_Enable(Timer_1_HW, Timer_1_NUM);

    Cy_TCPWM_PWM_Enable(PWM_2_HW, PWM_2_NUM);

    __enable_irq();

    Cy_TCPWM_TriggerStart(Timer_1_HW, Timer_1_MASK);

    Cy_TCPWM_TriggerStart(PWM_2_HW, PWM_2_MASK);

    for (;;)

    {

    }

}

This time, the point that Modus is inferior to Creator has appeared remarkably. If you are a Creator user or have done the previous Creator examples before, you may spend a hard time with Modus. The disadvantages of Modus will be largely eliminated if component settings can be expressed by a circuit like Creator instead of using the "Device Configuration" tool and an API that matches the component can be generated.

We are looking forward to an update to Modus Toolbox that addresses these issues.

Thanks,

Kenshow

5 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Thank you for sharing this project.

ModusToolBox has HAL layer implemented for PSoC 6, which allows setting the parameters in code, thereby eliminating the requirement of changing configuration in design.modus, as well as easing the process of porting to different kits. Please do try the HAL features of PSoC 6.

Thank you for your interest in Cypress products.


Best regards,
Hari

0 Likes
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi Hari,

The advantage of the Device Configuration tool is that we can use the GUI and can set it intuitively. Certainly it would be better to use HAL if we consider portability to other devices.

I have a question about using HAL.

In the device configuration tool, the signal of the component that can be input by PWM was limited. When using HAL, can I use the output of another PWM as input?

For example, in the case of this CE, can the output of the PWM be used as the input of another PWM instead of the Timer?

Thanks,

Kenshow

0 Likes
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello Kenshow-san,

It is not possible to assign the output of one block as the input of another using HAL. HAL only allows setting basic device configurations.

Best regards,
Hari

Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi Hari-san,

I just wanted to make a code example using Device Configuration Tool of Modus Toolbox because there are many HAL examples.

I'll try to make a program with HAL if I have an opportunity.

Thanks for your reply and advice.

Best Regards,

Kenshow

0 Likes
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi Hari-san,

I looked into the path to use PWM output instead of timer in HAL.

Unfortunately, I found there isn't path from PWM output to PWM input. There are underflow/overflow/comare_match of PWM only, not any other output of PWM. The device configuration tool faithfully reproduces the route.

If we can use UDB like Creator's circuit design, it will fill this gap.

Best Regards,

Kenshow