1 Reply Latest reply on Oct 11, 2020 10:46 PM by TakashiM_61

    Let's make the dice of seven eyes on PSoC 6 with DMA & Beep for ModusToolBox2.2


      Hi all,


      Through this programing of the dice, I was able to learn various PSoC designs. I've considered 7LEDs dice with ModusToolbox, but I gave up because ModusToolbox doesn't have a tool like the circuit input of PSoC Creator. In addition, Creator generats C functions using the created component name, so it was easy to program. Unfortunately, in MTB, it is necessary to make detailed settings with the cy_ function, and there are few CEs that use the function when using Device Configurator, which causes confusion in how to use the cy_ function.

      Add a BEEP sound to the one created in the previous DMA transfer. I also created this in PSoC Creator, but arranged it for Modus Toolbox 2.2. I hope you can see it as one of the CEs that control PWM from PWM.


      The environment used is as follows:

      ModusToolbox 2.2



      See the previous post for LED board circuitry and the concept of DMA.

      Let's make the dice of seven eyes on PSoC 6 with DMA for ModusToolBox2.2

      When using Creator, I designed the beep sound with the following circuit. However, for ModusToolbox, the pwm output in PWM cannot be used for the next PWM control input. Therefore, we have to use Device Configurator. Device Configurator in Modus Toolbox can faithfully reproduce the PSoC 6 MCU Trigger Multiplexer and help you find this route.


      Since the Beep output is decided to Pin10 [0], you can see that the output of TCPWN [0] 32bit counter 6 can be used by setting from pin with Device Configurator. 


      In the case of ModusToolbox, pwm output of the PWM cannot be used for the next PWM control input, so use ovrflw and Compare of PWM_1 to control the Start / Stop of PWM_2. The settings of the Device Configurator of PWM_2 to be added are as follows.


      The clock settings for PWM_2 are as follows.


      The Pin settings are as follows. Drive Mode is set to LEDx and Buzzer pin: "Strong Drive, Input buffer off", SW2: "Resistive Pull-Up, Input Buffer on".


      The program only adds the PWM_2 settings.

      #include "cyhal.h"
      #include "cybsp.h"
      uint32 Buffer[12]={0x37,0x01,0x1D,0x01,0x15,0x01,0x1C,0x00,0x14,0x00,0x08,0x00};
      uint32_t sw=0;  //sw is off (Stop rolling dicce)
      int main(void)
          cy_rslt_t result;
          /* Initialize the device and board peripherals */
          result = cybsp_init() ;
          if (result != CY_RSLT_SUCCESS)
          //DMA_1_Start ((void const *)Buffer, (void const *)0x40320280);
          if (CY_DMA_SUCCESS != Cy_DMA_Descriptor_Init(&DMA_1_Descriptor_0, &DMA_1_Descriptor_0_config))
              while(1); // Handle Error
          if(CY_DMA_SUCCESS != Cy_DMA_Channel_Init(DMA_1_HW, DMA_1_CHANNEL, &DMA_1_channelConfig)){
              while(1); // Handle Error
       Cy_DMA_Descriptor_SetSrcAddress(&DMA_1_Descriptor_0, (void const *)Buffer);
       Cy_DMA_Descriptor_SetDstAddress(&DMA_1_Descriptor_0, (void const *)0x40320280);
       Cy_DMA_Descriptor_SetNextDescriptor(&DMA_1_Descriptor_0, &DMA_1_Descriptor_0);
          Cy_DMA_Channel_Enable(DMA_1_HW, DMA_1_CHANNEL);
      Cy_TCPWM_PWM_Init(PWM_2_HW, PWM_2_NUM, &PWM_2_config);
          Cy_TCPWM_PWM_Enable(PWM_2_HW, PWM_2_NUM);
          for (;;)
                      Cy_TCPWM_PWM_Init(PWM_1_HW, PWM_1_NUM, &PWM_1_config);
                      Cy_TCPWM_PWM_Enable(PWM_1_HW, PWM_1_NUM);
                       Cy_TCPWM_TriggerStart(PWM_1_HW, PWM_1_MASK);
                      /* Roll dice slowly */
       Cy_TCPWM_TriggerCaptureOrSwap(PWM_1_HW, PWM_1_MASK);
                      CyDelay(1500);  // keep rolling slowly for 1.5sec
                      Cy_TCPWM_PWM_Disable (PWM_1_HW, PWM_1_NUM);
                      sw=0;           // sw is off
      /* [] END OF FILE */


      Usage: Press SW2 to rotate the dice and release it to slow down and stop.