0 Replies Latest reply on Oct 11, 2020 3:03 PM by NoTa_4591161

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

    NoTa_4591161

      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.

      Last time, I was able to express a 7LED dice with DMA of PSoC6, so I can create it on MTB without a circuit input tool. I hope you can see it as a CE of DMA that kicks from PWM.

         1.png

      2.png3.png

      4.png

             

      The environment used is as follows:

      ModusToolbox 2.2

      CY8CKIT-062-BLE

       

      The DMA trigger inputs PWM overflow. The circuit image is as follows. 

      5.png

      The DMA transfer is the following image.

      6.png

       

      Set this in Device Configurator. The settings for DMA_1 are shown below.

        7.png

      The PWM_1 settings are shown below. The period can be changed with swap.

        8.png

      The clock settings for PWM_1 are as follows.

        9.png

       

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

      10.png 

      The program on CM4 is as follows:

      #include"cy_pdl.h"
      #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)
          {
              CY_ASSERT(0);
          }
       
          __enable_irq();
       
          //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_DMA_Enable(DMA_1_HW);
       
              //Cy_TCPWM_PWM_Init(PWM_2_HW, PWM_2_NUM, &PWM_2_config);
          //Cy_TCPWM_PWM_Enable(PWM_2_HW, PWM_2_NUM);
       
          for (;;)
          {
              if(sw==0){
                  if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==0){
                      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);
                      sw=1;
                  }
              }
              if(sw==1){
                  if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==1){
                      /* 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.

       

      Thanks,

      Kenshow