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

PSoC™ 6 Forum Discussions

NoahP
Level 2
10 sign-ins 5 replies posted 5 questions asked
Level 2

GPIO LED on my PCB works well and I can toggle them on/off normally.

I am trying to add a timer that will help me to toggle them when I want without the use of delays.

I am using a CYBLE-416045-02 and a MiniProg4 for programming. Code is written in PSOC Creator 4.4.

The project compiles and programs fine, but LEDs only toggle when interrupts are disabled (ie. When I comment out __enable_irq();).

Please help, thank you.

 

 

uint16 uiBlinkTimer = BLINKTIME;
bool pinReadValue;
    
int main(void) {
    
    __enable_irq(); /* Enable global interrupts. */
    
    // Start Timer and interrupt
    ms_timer_Start();
    Cy_SysInt_Init(&timer_isr_cfg, &timer_isr_handler); // bind interrupt to handler
    NVIC_EnableIRQ(timer_isr_cfg.intrSrc); // enable timer interrupt
    
    
    Cy_GPIO_Write(RedLED_0_PORT, RedLED_0_NUM, LEDON);
    Cy_GPIO_Write(GreenLED_0_PORT, GreenLED_0_NUM, LEDON);
    CyDelay(500);
    Cy_GPIO_Write(RedLED_0_PORT, RedLED_0_NUM, LEDOFF);
    Cy_GPIO_Write(GreenLED_0_PORT, GreenLED_0_NUM, LEDOFF);
    CyDelay(500);
    
    pinReadValue = LEDOFF;
    
    for(;;) 
    {
        
        Cy_GPIO_Write(RedLED_0_PORT, RedLED_0_NUM, LEDON);
        Cy_GPIO_Write(GreenLED_0_PORT, GreenLED_0_NUM, LEDON);
        CyDelay(250);
        Cy_GPIO_Write(RedLED_0_PORT, RedLED_0_NUM, LEDOFF);
        Cy_GPIO_Write(GreenLED_0_PORT, GreenLED_0_NUM, LEDOFF);
        CyDelay(250);

        if(!uiBlinkTimer) 
        {
            if(pinReadValue == LEDOFF) 
            {
                Cy_GPIO_Write(RedLED_0_PORT, RedLED_0_NUM, LEDON);
                Cy_GPIO_Write(GreenLED_0_PORT, GreenLED_0_NUM, LEDON);
                pinReadValue = LEDON;
            } 
            else 
            {
                Cy_GPIO_Write(RedLED_0_PORT, RedLED_0_NUM, LEDOFF);
                Cy_GPIO_Write(GreenLED_0_PORT, GreenLED_0_NUM, LEDOFF);  
                pinReadValue = LEDOFF;              
            }
            uiBlinkTimer = BLINKTIME;
        }
        /* Place your application code here. */
    }
}

// Timer used is ms_timer
// 1 interrupt / ms
void timer_isr_handler() {
    
    if(uiBlinkTimer)
        uiBlinkTimer--;
    
    NVIC_ClearPendingIRQ(timer_isr_cfg.intrSrc);
    ms_timer_ClearInterrupt(ms_timer_CNT_NUM);
}
0 Likes
1 Solution
RodolfoGL
Employee
250 sign-ins 5 comments on KBA First comment on KBA
Employee

The problem is related to the way you are clearing the interrupt. ClearInterrupt() function requires a mask for the interrupt source, not the CNT number.  The source is probably (1u) or CY_TCPWM_INT_ON_TC.

So what's going on is that the CPU is constantly executing your timer ISR, since it is never properly cleared.

View solution in original post

2 Replies
RodolfoGL
Employee
250 sign-ins 5 comments on KBA First comment on KBA
Employee

The problem is related to the way you are clearing the interrupt. ClearInterrupt() function requires a mask for the interrupt source, not the CNT number.  The source is probably (1u) or CY_TCPWM_INT_ON_TC.

So what's going on is that the CPU is constantly executing your timer ISR, since it is never properly cleared.

NoahP
Level 2
10 sign-ins 5 replies posted 5 questions asked
Level 2

This was exactly the issue, unsure how I ended up placing "ms_timer_CNT_NUM" there, but you saved me nonetheless! Thanks!

0 Likes