- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
}
Solved! Go to Solution.
- Labels:
-
PSoC 6 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This was exactly the issue, unsure how I ended up placing "ms_timer_CNT_NUM" there, but you saved me nonetheless! Thanks!