3 Replies Latest reply on Nov 26, 2018 2:57 PM by marcogiorio

    Newbie..problem with UDB counter.

    marcogiorio

      Hi, I'm trying to learn how to use a counter, I would like to fire an interrupt (set on and then off a RGB LED) after pushing for three times an external switch.

      I can't understand what's wrong. Sometimes the interrupt fires after three times,sometimes after twice or one time I push the switch. I think that should be some problems with the parameters I set on the counter.

      Please help me.

       

       

      This is the code:

       

      #include "project.h"

       

      CY_ISR(ISR_COUNTER_HANDLER){

      LED_BLU_Write(1);

      LED_RED_Write(1);

      CyDelay(500);

      LED_BLU_Write(!LED_BLU_Read());

      LED_RED_Write(!LED_RED_Read());

      Counter_ReadStatusRegister();

      }

       

      int main(void){

      CyGlobalIntEnable;

      Counter_Start();

      ISR_COUNTER_StartEx(ISR_COUNTER_HANDLER);

         

      for(;;)

          {     }

      }