Get interrupt source from Timer block in PSoC 5

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

cross mob
JoNe_4268451
Level 2
Level 2
First like received First like given

Hi!

I have a project in PSoC4 that uses a timer block to measure the speed motor trough "hall" sensors. It's essencial to determinate the source of interrupt, in case the interrupt is due to "tc" a variable that store the number of periods, is increased. But if the source is because a capture has been done, the code calculates the time between this capture and the last one to determinate how many time the motor takes to turn.

CY_ISR (isr_spd_Handler){

    //Si la interrupción es porque ha llegado al final de la cuenta, y además el motor está en marcha

//if the interrupt source is due to reach the final of the count (one period has been completed by the timer)

//the state_button variable only indicates that the motor is running

//the "first_turn" variable is used to know when the motor starts, to not measure the first capture when the motor has uncertain position

    if ((Speed_Counter_GetInterruptSource() == Speed_Counter_INTR_MASK_TC) && State_Button && !first_turn){

        vueltas_cont++;

        Speed_Counter_ClearInterrupt(Speed_Counter_INTR_MASK_TC);

    }

    //Si es porque ha recibido señal de los sensores hall de una vuelta completa

// If the source is due to a capture activated by the hall sensors

    if (Speed_Counter_GetInterruptSource() == Speed_Counter_INTR_MASK_CC_MATCH){

        if (first_turn){ //Es la primera vez

            first_turn = ~first_turn;

            T0 = Speed_Counter_ReadCapture();

        }else{

            delay = (Speed_Counter_ReadCapture()-T0+vueltas_cont)*T_clock;

            T0 = Speed_Counter_ReadCapture();

            vueltas_cont = 0;

            Vel_real = 1/(delay*60e-6); //Vel obtenida [rpm]

            

        }

        Speed_Counter_ClearInterrupt(Speed_Counter_INTR_MASK_CC_MATCH);

    }

Now, I'm trying to do the same in PSoC 5 LP, but I don't know how to get the source of the capture, "Timer_clock_INTR_MAS_TC and "Timer_block_INTR_MASK_CC_MATH" have disapeared, I have tested to get the interrupt source using the fuction "Timer_ReadStatusRegister();" but I don't know how to split each case.

Thank you,

Jose Antonio.

1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I read Speec_Counter.c to find "Speed_Counter_ReadStatusRegister()"

and it was in line 333 of Speed_Counter.c then to find Speed_Counter_STATUS

I read Speed_Counter.h is was defined line 197.

Then in the line 299 - 301 there were

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

    /* Status Register Bit Masks */

    #define Speed_Counter_STATUS_TC                       ((uint8)((uint8)0x01u << Speed_Counter_STATUS_TC_SHIFT))

    #define Speed_Counter_STATUS_CAPTURE                  ((uint8)((uint8)0x01u << Speed_Counter_STATUS_CAPTURE_SHIFT))

    /* Interrupt Enable Bit-Mask for interrupt on TC */

    #define Speed_Counter_STATUS_TC_INT_MASK              ((uint8)((uint8)0x01u << Speed_Counter_STATUS_TC_INT_MASK_SHIFT))

    /* Interrupt Enable Bit-Mask for interrupt on Capture */

    #define Speed_Counter_STATUS_CAPTURE_INT_MASK         ((uint8)((uint8)0x01u << Speed_Counter_STATUS_CAPTURE_INT_MASK_SHIFT))

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

So I think that we can write something like

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

CY_ISR(timer_isr)

{

    uint8_t status ;

    status = Speed_Counter_ReadStatusRegister() ;

    if ((status & Speed_Counter_STATUS_TC_INT_MASK) != 0) {

    }

    if ((status &  Speed_Counter_STATUS_CAPTURE_INT_MASK) != 0) {

    }

  

}

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

But better than this reading the datasheet of the Timer component,

in the page 25 there is

aaa.JPG

moto

View solution in original post

0 Likes
3 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I read Speec_Counter.c to find "Speed_Counter_ReadStatusRegister()"

and it was in line 333 of Speed_Counter.c then to find Speed_Counter_STATUS

I read Speed_Counter.h is was defined line 197.

Then in the line 299 - 301 there were

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

    /* Status Register Bit Masks */

    #define Speed_Counter_STATUS_TC                       ((uint8)((uint8)0x01u << Speed_Counter_STATUS_TC_SHIFT))

    #define Speed_Counter_STATUS_CAPTURE                  ((uint8)((uint8)0x01u << Speed_Counter_STATUS_CAPTURE_SHIFT))

    /* Interrupt Enable Bit-Mask for interrupt on TC */

    #define Speed_Counter_STATUS_TC_INT_MASK              ((uint8)((uint8)0x01u << Speed_Counter_STATUS_TC_INT_MASK_SHIFT))

    /* Interrupt Enable Bit-Mask for interrupt on Capture */

    #define Speed_Counter_STATUS_CAPTURE_INT_MASK         ((uint8)((uint8)0x01u << Speed_Counter_STATUS_CAPTURE_INT_MASK_SHIFT))

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

So I think that we can write something like

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

CY_ISR(timer_isr)

{

    uint8_t status ;

    status = Speed_Counter_ReadStatusRegister() ;

    if ((status & Speed_Counter_STATUS_TC_INT_MASK) != 0) {

    }

    if ((status &  Speed_Counter_STATUS_CAPTURE_INT_MASK) != 0) {

    }

  

}

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

But better than this reading the datasheet of the Timer component,

in the page 25 there is

aaa.JPG

moto

0 Likes

Hello!

You're right, I tried with "Timer_STATUS_TC" and "Timer_STATUS_CAPTURE" and it works properly, I don't have tested with "Timer_STATUS_TC_INT_MASK" and "Timer_STATUS_CAPTURE_INT_MASK" and I'm not sure enough what the difference would be.

We can also make the logic "AND" with a binary number e.g:  "status_register & 00000001", setting value "HIGH" in right position.

CY_ISR(isr_speed_handler){

    uint8 status_register;

   

    status_register = Timer_speed_ReadStatusRegister(); //Se lee y se limpia la interrupción

   

    /*** INTERRUPCIÓN DEBIDA A TC ***/

     if (status_register & Timer_speed_STATUS_TC){

    }

 

    /*** INTERRUPCIÓN DEBIDA A CAPTURA ***/

    if (status_register & Timer_speed_STATUS_CAPTURE){

    }

}

Thanks a lot!

Jose Antonio

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I think ..._INT_MASK is bit mask to enable/disable that interrupt

and the one without "MASK" is the value returned by the ReadStatusRegister().

So your code is correct and mine was wrong.

(But quite good change, their values same...)

But I'm glad that your code is working properly.

moto