PWM to change LED brightness - A simple program for beginners using Modus Toolbox2.1 with PSoC6(M4)

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

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

Hi all,

I am making some programs for beginners using Modus ToolBox 2.1. When migrating the development environment from PSoc Creator to Modus, I had a hard time creating a simple program. Especially, there are few simple samples using the Device Configuration tool.

Here, a simple program for the M4 core of PSoC 6 using the Device Configuration tool of Modus Toolbox2.1 is introduced here.

The environment is as follows.

ModusToolbox2.1

CY8CKIT-062-BLE

This time, we will use PWM to change the LED brightness.

Select the CY8CKIT-062-BLE kit from the New Application tool in the Quick Panel and use it based on what was created in the empty PSoC 6 app.

About the pin setting, start the Device Configuration tool from the Quick Panel in the IDE of Modus Toolbox2.1, and set it according to the following procedure.

1.png

Select the “Pin” tab.

Check P0[3], name it "LED" and select "Drive Mode" as "Strong Drive, Input buffer off".

The peripherals that can be connected to P0[3] is displayed in the pull-down menu in Digital Output in Parameters on the right. Select "TCPWM[0] 32bit Counter 1 pwm_n" from the pull-down menu.

2.png

3.png

Go to “Peripheral” tab and set TCPWM (Timer Counter PWM) as PWM.

Check TCPWM [0] 32bit Counter 1 selected as Digital output of Pin0 [3]. Then, a selection window will appear. Select "PWM-1.0". Enter Name as "PWM".

On the right side of the Peripheral tab, there is a place to set the PWM parameters. Set the comparison Compare that determines the period and the pulse width.

 Period:1000

 Compare:100

Select the input clock source from the pull-down menu.

 Clock Signal:16bit Divider 0 clk

make sure that what is set as Pin output is selected as PWM output.

 PWM_n:P0[3]

4.png

Go to the Peripheral-Clocks tab.

Check "16bit Divider 0" specified in PWM.

The division is 8.

Divider: 8

Since the clock source is 100MHz, 12.5MHz divided by 8 is output.

Make sure that "TCPWM [0] 32bit Counter (PWM)" is selected as the Peripheral connection destination.

5.png

The program is as follows.

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_PWM_Init(PWM_HW, PWM_NUM, &PWM_config);

    Cy_TCPWM_PWM_Enable(PWM_HW, PWM_NUM);

    __enable_irq();

    Cy_TCPWM_TriggerStart(PWM_HW, PWM_MASK);

    for (;;)

    {

    }

}

It's very easy. First, why don't you get used to Modus toolbox from this program?

Thanks,

Kenshow

0 Likes
2 Replies
Takashi_M
Moderator
Moderator
Moderator
1000 replies posted 500 solutions authored 750 replies posted

Dear Kenshow-san,

Thank you very much for your sharing this CE.

Best regards.

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

Hi,

I changed the order in which API functions are called and updated the program.

Thanks,

Kenshow

18-June-2020

0 Likes