1 Reply Latest reply on Mar 18, 2020 5:36 AM by MoTa_728816

    First PWM CC interrupt is delayed

    D.Sd_3235936

      The first CC interrupt either lags or happens before time. I always get a value PWM_ReadCounter of below 50. (as described in the picture below)

      The issue is only happening on the first activation of PWM and PWM_Isr, following boot.

      Next activations looks to work fine.

       

      Code:

      StartEx(isr_name) on startup.

      Then I activate PWM, WriteCounter(1),  PWM_ISr

       

       

        • 1. Re: First PWM CC interrupt is delayed
          MoTa_728816

          Hi,

           

          I tried with CY8CKIT-043 with the following test project,

          but I could not reproduce the problem.

           

          Could you test your board with this project?

           

          schematic

          001-schematic.JPG

          PWM config

           

          pins

          003-Pins.JPG

          main.c

          =================

          #include "project.h"

          #include "stdio.h"

           

          #define STR_LEN 64

          char str[STR_LEN+1] ;

          void print(char *str)

          {

              UART_UartPutString(str) ;

          }

           

          void cls(void)

          {

              print("\033c") ; /* reset */

              CyDelay(20) ;

              print("\033[2J") ; /* clear screen */

              CyDelay(20) ;

          }

           

          void splash(void)

          {

          //    cls() ;

              print("PSoC 4 PWM Interrupt Test") ;

              snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

              print(str) ;

          }

           

          #define NUM_COUNT 10

          volatile uint16_t count_buf[NUM_COUNT] ;

          volatile int16_t count_index = 0 ;

          volatile int     count_flag = 0 ;

           

          CY_ISR(isr_name)

          {

              PWM_BUZZ_ClearInterrupt(PWM_BUZZ_INTR_MASK_CC_MATCH) ;

              count_buf[count_index++] = PWM_BUZZ_ReadCounter() ;

              if (count_index >= NUM_COUNT) {

                  count_flag = 1 ;

                  isr_1_Disable() ;

              }

          }

           

          void init_hardware(void)

          {

              CyGlobalIntEnable; /* Enable global interrupts. */

              UART_Start() ;

              splash() ;

           

              isr_1_StartEx(isr_name) ;

              PWM_BUZZ_WriteCounter(1) ;

              PWM_BUZZ_Start() ;

          }

           

          int main(void)

          {

              int i ; 

           

              init_hardware() ;

           

              for(;;)

              {

                  if (count_flag) {

                      for(i = 0 ; i < NUM_COUNT ; i++ ) {

                          snprintf(str, STR_LEN, "%hu ", count_buf[i]) ;

                          print(str) ;

                      }

                      print("\n\r") ;

                      count_flag = 0 ;

                  }

              }

          }

          /* [] END OF FILE */

          =================

           

          Tera Term log

          I pushed "reset" many times.

          It seems that always the odd ones are bigger than 50 and even ones are less then 50.

          000-TeraTerm-log.JPG

          moto