PSoC 63: Timer / Counter (TCPWM_Counter_PDL) period maximum?

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

cross mob
CaKu_4284131
Level 5
Level 5
50 replies posted 25 replies posted 10 likes received

I'm trying to set the period of the Timer/Counter. Supposedly it has: Range: 0-65535 (for 16 bit resolution) or 0–4294967295 (for 32 bit resolution). But it objects to 4294967295 for 32 bit resolution:

pastedImage_1.png

It will, however, accept half that:

pastedImage_2.png

Am I doing something wrong?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried it with CY8CKIT-062-BLE,

When I set the period to 0x7FFFFFFF it accepted the value,

but when MSB is set, 0x80000000 was rejected.

001-0x7FFFFFF_OK.JPG

002-0x80000000_NG.JPG

So I assumed that this is a GUI bug (or limitation?)

and I tried to set the value from the firmware.

Following is the result Tera Term (serial term) log.

So, it seems that period of 0xFFFFFFFF is taking about 2x time of the period of 0x7FFFFFFF,

which means from the firmware the value 0xFFFFFFFF is valid.

Note: This takes time, I'm glad that you were not asking about 64bit 😉

003-TeraTerm-log.JPG

schematic

004-schematic.JPG

pins

005-pins.JPG

main.c

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

#include "project.h"

#include "stdio.h"

#define SYSTICK_MAX_CNT_BITS 16u

#define SYSTICK_MAX_CNT (1<<SYSTICK_MAX_CNT_BITS)-1

#define LED_ON 0x00

#define LED_OFF 0x01

volatile uint32_t tick_count = 0 ;

volatile int tc_flag = 0 ;

int period_flag = 0 ;

uint32_t period[] = {

    0x7FFFFFFF,

    0xFFFFFFFF

} ;

#define STR_LEN 128

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

void cls(void)

{

    print("\x1b[2J\x1b[;H") ;

}

void splash(char *prog_name)

{

    cls() ;

    if (prog_name && *prog_name) {

        print(prog_name) ;

    }

    print(" (") ;

    print(__DATE__) ;

    print(" ") ;

    print(__TIME__) ;

    print(")\n") ;

}

void timer_isr(void)

{

    uint32_t intSource = Cy_TCPWM_GetInterruptStatus(Timer_HW, Timer_TCPWM__CNT_IDX);

    /* Clear interrupt */

    Cy_TCPWM_ClearInterrupt(Timer_HW, Timer_TCPWM__CNT_IDX, CY_TCPWM_INT_ON_CC_OR_TC);

  

    if(intSource == CY_TCPWM_INT_ON_TC) {

        tc_flag = 1 ;

    }

}

void tick_isr(void)

{

   uint32_t intSource = Cy_TCPWM_GetInterruptStatus(Timer_sec_HW, Timer_sec_TCPWM__CNT_IDX);  

  

    /* Clear interrupt */

    Cy_TCPWM_ClearInterrupt(Timer_sec_HW, Timer_sec_TCPWM__CNT_IDX, CY_TCPWM_INT_ON_CC_OR_TC);

  

    if(intSource == CY_TCPWM_INT_ON_TC) {

        tick_count++ ;

        if (tick_count & 0x01) {

            Cy_GPIO_Write(LED_PORT, LED_NUM, LED_OFF) ;

        } else {

            Cy_GPIO_Write(LED_PORT, LED_NUM, LED_ON) ;

        }

    }

}

void set_timer_period(uint32_t period)

{

    snprintf(str, STR_LEN, "Timer Period: 0x%08X\n\r", period) ;

    print(str) ;

    Timer_Disable() ;

    Timer_SetPeriod(period) ;

    Timer_SetCounter(0) ;

    Timer_Enable() ;

    Timer_TriggerStart() ;

}

void init_hardware(void)

{

    __enable_irq(); /* Enable global interrupts. */  

  

    UART_Start() ;

    splash("PSoC 63 Timer Test") ;

  

    /* Initialize with config set in component and enable the Counter */

    Cy_TCPWM_Counter_Init(Timer_HW, Timer_CNT_NUM, &Timer_config);

    Cy_TCPWM_Counter_Enable(Timer_HW, Timer_CNT_NUM);

  

    /* Hookup and enable interrupt */

    Cy_SysInt_Init(&SysInt_1_cfg, timer_isr);

    NVIC_ClearPendingIRQ(SysInt_1_cfg.intrSrc);

    NVIC_EnableIRQ((IRQn_Type)SysInt_1_cfg.intrSrc);  

  

    /* Start the Counter */

    Cy_TCPWM_TriggerStart(Timer_HW, Timer_CNT_MASK);  

  

    /* Initialize with config set in component and enable the Counter */

    Cy_TCPWM_Counter_Init(Timer_sec_HW, Timer_sec_CNT_NUM, &Timer_sec_config);

    Cy_TCPWM_Counter_Enable(Timer_sec_HW, Timer_sec_CNT_NUM);

  

    /* Hookup and enable interrupt */

    Cy_SysInt_Init(&SysInt_2_cfg, tick_isr);

    NVIC_ClearPendingIRQ(SysInt_2_cfg.intrSrc);

    NVIC_EnableIRQ((IRQn_Type)SysInt_2_cfg.intrSrc);  

  

    /* Start the Counter */

    Cy_TCPWM_TriggerStart(Timer_HW, Timer_CNT_MASK); 

    /* Start the Counter */

    Cy_TCPWM_TriggerStart(Timer_sec_HW, Timer_sec_CNT_MASK);

    set_timer_period(period[period_flag++]) ;

}

int main(void)

{

    init_hardware() ;

  

    for(;;)

    {

        if (tc_flag) {

            snprintf(str, STR_LEN, "Tick: %u\n\r", tick_count) ;

            tick_count = 0 ;

            tc_flag = 0 ;

            print(str) ;

            set_timer_period(period[period_flag++]) ;

            Timer_sec_TriggerReload() ;

            Timer_sec_TriggerStart() ;

            if (period_flag > 1) {

                period_flag = 0 ;

            }

        }

    }

}

/* [] END OF FILE */

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

moto

View solution in original post

0 Likes
4 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried it with CY8CKIT-062-BLE,

When I set the period to 0x7FFFFFFF it accepted the value,

but when MSB is set, 0x80000000 was rejected.

001-0x7FFFFFF_OK.JPG

002-0x80000000_NG.JPG

So I assumed that this is a GUI bug (or limitation?)

and I tried to set the value from the firmware.

Following is the result Tera Term (serial term) log.

So, it seems that period of 0xFFFFFFFF is taking about 2x time of the period of 0x7FFFFFFF,

which means from the firmware the value 0xFFFFFFFF is valid.

Note: This takes time, I'm glad that you were not asking about 64bit 😉

003-TeraTerm-log.JPG

schematic

004-schematic.JPG

pins

005-pins.JPG

main.c

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

#include "project.h"

#include "stdio.h"

#define SYSTICK_MAX_CNT_BITS 16u

#define SYSTICK_MAX_CNT (1<<SYSTICK_MAX_CNT_BITS)-1

#define LED_ON 0x00

#define LED_OFF 0x01

volatile uint32_t tick_count = 0 ;

volatile int tc_flag = 0 ;

int period_flag = 0 ;

uint32_t period[] = {

    0x7FFFFFFF,

    0xFFFFFFFF

} ;

#define STR_LEN 128

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

void cls(void)

{

    print("\x1b[2J\x1b[;H") ;

}

void splash(char *prog_name)

{

    cls() ;

    if (prog_name && *prog_name) {

        print(prog_name) ;

    }

    print(" (") ;

    print(__DATE__) ;

    print(" ") ;

    print(__TIME__) ;

    print(")\n") ;

}

void timer_isr(void)

{

    uint32_t intSource = Cy_TCPWM_GetInterruptStatus(Timer_HW, Timer_TCPWM__CNT_IDX);

    /* Clear interrupt */

    Cy_TCPWM_ClearInterrupt(Timer_HW, Timer_TCPWM__CNT_IDX, CY_TCPWM_INT_ON_CC_OR_TC);

  

    if(intSource == CY_TCPWM_INT_ON_TC) {

        tc_flag = 1 ;

    }

}

void tick_isr(void)

{

   uint32_t intSource = Cy_TCPWM_GetInterruptStatus(Timer_sec_HW, Timer_sec_TCPWM__CNT_IDX);  

  

    /* Clear interrupt */

    Cy_TCPWM_ClearInterrupt(Timer_sec_HW, Timer_sec_TCPWM__CNT_IDX, CY_TCPWM_INT_ON_CC_OR_TC);

  

    if(intSource == CY_TCPWM_INT_ON_TC) {

        tick_count++ ;

        if (tick_count & 0x01) {

            Cy_GPIO_Write(LED_PORT, LED_NUM, LED_OFF) ;

        } else {

            Cy_GPIO_Write(LED_PORT, LED_NUM, LED_ON) ;

        }

    }

}

void set_timer_period(uint32_t period)

{

    snprintf(str, STR_LEN, "Timer Period: 0x%08X\n\r", period) ;

    print(str) ;

    Timer_Disable() ;

    Timer_SetPeriod(period) ;

    Timer_SetCounter(0) ;

    Timer_Enable() ;

    Timer_TriggerStart() ;

}

void init_hardware(void)

{

    __enable_irq(); /* Enable global interrupts. */  

  

    UART_Start() ;

    splash("PSoC 63 Timer Test") ;

  

    /* Initialize with config set in component and enable the Counter */

    Cy_TCPWM_Counter_Init(Timer_HW, Timer_CNT_NUM, &Timer_config);

    Cy_TCPWM_Counter_Enable(Timer_HW, Timer_CNT_NUM);

  

    /* Hookup and enable interrupt */

    Cy_SysInt_Init(&SysInt_1_cfg, timer_isr);

    NVIC_ClearPendingIRQ(SysInt_1_cfg.intrSrc);

    NVIC_EnableIRQ((IRQn_Type)SysInt_1_cfg.intrSrc);  

  

    /* Start the Counter */

    Cy_TCPWM_TriggerStart(Timer_HW, Timer_CNT_MASK);  

  

    /* Initialize with config set in component and enable the Counter */

    Cy_TCPWM_Counter_Init(Timer_sec_HW, Timer_sec_CNT_NUM, &Timer_sec_config);

    Cy_TCPWM_Counter_Enable(Timer_sec_HW, Timer_sec_CNT_NUM);

  

    /* Hookup and enable interrupt */

    Cy_SysInt_Init(&SysInt_2_cfg, tick_isr);

    NVIC_ClearPendingIRQ(SysInt_2_cfg.intrSrc);

    NVIC_EnableIRQ((IRQn_Type)SysInt_2_cfg.intrSrc);  

  

    /* Start the Counter */

    Cy_TCPWM_TriggerStart(Timer_HW, Timer_CNT_MASK); 

    /* Start the Counter */

    Cy_TCPWM_TriggerStart(Timer_sec_HW, Timer_sec_CNT_MASK);

    set_timer_period(period[period_flag++]) ;

}

int main(void)

{

    init_hardware() ;

  

    for(;;)

    {

        if (tc_flag) {

            snprintf(str, STR_LEN, "Tick: %u\n\r", tick_count) ;

            tick_count = 0 ;

            tc_flag = 0 ;

            print(str) ;

            set_timer_period(period[period_flag++]) ;

            Timer_sec_TriggerReload() ;

            Timer_sec_TriggerStart() ;

            if (period_flag > 1) {

                period_flag = 0 ;

            }

        }

    }

}

/* [] END OF FILE */

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

moto

0 Likes

Thanks Motoo-san. It does appear to be a bug in PSoC Creator  4.3 (4.3.0.1445). It's good to know that I can work around it with Cy_TCPWM_Counter_SetPeriod, and that's what I'll do.

         -Carl

Follow-up: for users of FreeRTOS, an easy way to enable FreeRTOS Run Time Stats is to plunk one of these in TopDesign:

pastedImage_2.png

and then edit FreeRTOSConfig.h:

/* Run time and task stats gathering related definitions. */

#define configGENERATE_RUN_TIME_STATS          1

#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() {Counter_1_SetPeriod(0xFFFFFFFF); Counter_1_Start();}

#define portGET_RUN_TIME_COUNTER_VALUE() Counter_1_GetCounter()

#define configUSE_TRACE_FACILITY                1

#define configUSE_STATS_FORMATTING_FUNCTIONS    1

Hello,

Thank you very much MoTa_728816​ and CaKu_4284131​ for pointing out the bug in PSoC Creator 4.3. We will raise an internal ticket for our team,  to review the issue and fix the bug as soon as possible.

Best Regards,

Aashita