3 Replies Latest reply on Jun 17, 2020 11:04 PM by NoTa_4591161

    Timer to set the lighting time of the LED - A simple program for beginners using Modus Toolbox2.1 with PSoC6(M4)


      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.




      This time, use the Timer interrupt to set the LED lighting time.


      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.



      Select the “Pin” tab.

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


      Move to “peripheral” tab

      Check "TCPWM [1] 16bit Timer Counter 0", select Timer-Counter-1.0, and name it "Timer".

      The parameter settings are as follows.



       Interrupt Source:Overflow & Underflow

       Clock Signal:16bit Divider 0 clk



      Go to the “Peripheral-Clocks” tab.

      Check the 16bit Divider 0 specified in the PWM. Divide by 10,000.

      Divider: 10000


      Since the clock source is 100MHz, 10KHz divided by 10,000 is output.

      Make sure that "TCPWM [1] 16bit Counter (Timer)" is selected as the connection destination of Peripheral.



      The program is as follows.


      #include "cy_pdl.h"
      #include "cyhal.h"
      #include "cybsp.h"
      #define SWITCH_INTR_PRIORITY (3u)
      const cy_stc_sysint_t switch_intr_config = {
          .intrSrc = Timer_IRQ,                           /* Source of interrupt signal */
          .intrPriority = SWITCH_INTR_PRIORITY /* Interrupt priority */
      void Timer_isr(void){
         Cy_GPIO_Inv(LED_PORT, LED_NUM);
         Cy_TCPWM_ClearInterrupt(Timer_HW, Timer_NUM, CY_TCPWM_INT_ON_TC);
      int main(void)
          cy_rslt_t result;
          /* Initialize the device and board peripherals */
          result = cybsp_init() ;
          if (result != CY_RSLT_SUCCESS)
          Cy_TCPWM_Counter_Init(Timer_HW, Timer_NUM, &Timer_config);
          Cy_TCPWM_Counter_Enable(Timer_HW, Timer_NUM);
          Cy_SysInt_Init(&switch_intr_config, Timer_isr);
          Cy_TCPWM_TriggerStart(Timer_HW, Timer_MASK);
          for (;;)


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