restart counter

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

cross mob
DaGa_4352226
Level 2
Level 2
10 questions asked 5 replies posted 5 questions asked

Hello Cypress

I am using a Timer Counter with a clock of 1 MHz. My frequency is 20 Hz (50,000 counts). When its unitl a value it trigger an output and after it needs to change the output again. But what it is happening is that is not restarting again and Ive programmed it as continous. My interrupt is trigger just once.

here is my code of initalizing the timer:

Cy_SysInt_Init(&Triger_ISR_cfg,&TimerTreatmentInterruptHandler);

    NVIC_EnableIRQ(Triger_ISR_cfg.intrSrc); /* Enable the core interrupt */

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

   

    /* Start the TCPWM component in timer/counter mode. The return value of the

     * function indicates whether the arguments are valid or not. It is not used

     * here for simplicity.

     */

    (void)Cy_TCPWM_Counter_Init(Counter_1_HW, Counter_1_CNT_NUM, &Counter_1_config);

    Cy_TCPWM_Enable_Multiple(Counter_1_HW, Counter_1_CNT_MASK); /* Enable the counter instance */

   

    /* Set the timer period in milliseconds. To count N cycles, period should be

     * set to N-1.

     */

    Cy_TCPWM_Counter_SetPeriod(Counter_1_HW, Counter_1_CNT_NUM, cycleTime - 1);

    Cy_TCPWM_TriggerStart(Counter_1_HW, Counter_1_CNT_MASK);   

the interrupt function code:

o++;

    DBG_PRINTF("Enter how many time %x\r\n", o);

   

    /* Clear the terminal count interrupt */

    Cy_TCPWM_ClearInterrupt(Counter_1_HW, Counter_1_CNT_NUM, CY_TCPWM_INT_ON_TC);

   

    /* Toggle the LED */ 

    if (triggerValue == TRIGGER_LOW)

    {

        DBG_PRINTF("TriggerValue %x \r\n", triggerValue);

        triggerValue = TRIGGER_HIGH;

        Counter_1_SetCounter(dutyCycleOn);

    }

    else

    {

        DBG_PRINTF("TriggerValue %x \r\n", triggerValue);

        triggerValue = TRIGGER_LOW;

        Counter_1_SetCounter(dutyCycleOff);

    }

    if (treatmentActive == ON)

    {

        Trigger_Write(triggerValue);

        cycleCounter++;

        if (cycleCounter >= 2* onCycles){

            treatmentActive = OFF;

            cycleCounter = 0;

            DBG_PRINTF("Treatment finsih at: ");

            CtsPrintCurrentTime();

            DBG_PRINTF("\r\n");

        }

        else if (cycleCounter == 1)

        {

            blickControl = ON;

        }

       

        if ( blickControl == ON)

        {

            Treatment_On_INV();

            CyDelay(100);

        }

        else

        {

            Treatment_On_Write(LED_OFF);

        }

    }

    else

    {

        Trigger_Write(TRIGGER_LOW);

        Counter_1_SetCounter(0);

        treatmentActive = ON;

        blickControl = OFF;

    }

there is a method to restart the Timer?

0 Likes
1 Reply
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello David,

Can you please try adding NVIC_ClearPending() API in after the Cy_TCPWM_ClearInterrupt() API

in the interrupt function code and before the NVIC_EnableIRQ() in the main. Please let me know if this works.

Also can you please attach your project this will help me narrow down the issue.

Best Regards

Ekta

0 Likes