AnsweredAssumed Answered

Pin interrupt run abnormally

Question asked by jeffcharles on Dec 8, 2017
Latest reply on Dec 11, 2017 by lama

Hi,

 

I use PS0 and PS1 to get the direction and counts about two pulses whose timing diagram is shown in attachment. Enable the PS0 and PS1 pin interrupt. The polarity of the active edge is like that: PS0 select rising edge, PS1 select falling edge. When a valid edge on an input is detected, read the port data about the other. My code is like that:

 

 

 

void port_init(void)
{
    DDRS = 0x0;                     /* PS[3:0] are configured as input */
    PPSS = 0x1;                     /* Rising edge: PS0    Falling edge: PS1 */
    PIFS = 0x3;                       /* Clear PS0, PS1(KWU) flag  */
    PIES = 0x3;                       /* Enable PS0, PS1 interrupt(KWU) */
}

 

 

 

void knob_detect(void)
{
    if (PIFS_PIFS0 == 1 && PIFS_PIFS1 == 0)
    {
        if (PTS_PTS1 == 1)                              /* Rotate the volume knob up in the first case */
        {
            MSG_1.Byte0_0.Bits.VolAdj ++;      /* ① */
        }
        else                                                      /* Rotate the volume knob down in the first case */
        {
            MSG_1.Byte0_0.Bits.VolAdj --;        /* ② */
        }
    }
    if (PIFS_PIFS0 == 0 && PIFS_PIFS1 == 1)
    {
        if (PTS_PTS0 == 1)                             /* Rotate the volume knob up in the second case */
        {
            MSG_1.Byte0_0.Bits.VolAdj ++;      /* ③ */
        }
        else                                                     /* Rotate the volume knob down in the second case */
        {
            MSG_1.Byte0_0.Bits.VolAdj --;      /* ④ */
        }
    }
}

 

 

 

void interrupt VectorNumber_Vports key_wakeup_ISR(void)
{
    knob_detect();
}

 

 

 

/*==============================================================*/

 

The debug result is: the software only enter the code ④, can't enter the code ①, ②, ③.

 

Then I try to change the polarity of the active edge, the code updated is like that:

 

 

 

void port_init(void)
{
    DDRS = 0x0;                     /* PS[3:0] are configured as input */
    PPSS = 0x2;                     /* Falling edge: PS0    Rising edge: PS1 */
    PIFS = 0x3;                       /* Clear PS0, PS1(KWU) flag  */
    PIES = 0x3;                       /* Enable PS0, PS1 interrupt(KWU) */
}

 

 

 

void knob_detect(void)
{
    if (PIFS_PIFS0 == 1 && PIFS_PIFS1 == 0)
    {
        if (PTS_PTS1 == 0)                              /* Rotate the volume knob up in the first case */
        {
            MSG_1.Byte0_0.Bits.VolAdj ++;      /* ① */
        }
        else                                                      /* Rotate the volume knob down in the first case */
        {
            MSG_1.Byte0_0.Bits.VolAdj --;        /* ② */
        }
    }
    if (PIFS_PIFS0 == 0 && PIFS_PIFS1 == 1)
    {
        if (PTS_PTS0 == 0)                             /* Rotate the volume knob up in the second case */
        {
            MSG_1.Byte0_0.Bits.VolAdj ++;      /* ③ */
        }
        else                                                     /* Rotate the volume knob down in the second case */
        {
            MSG_1.Byte0_0.Bits.VolAdj --;      /* ④ */
        }
    }
}

 

 

 

void interrupt VectorNumber_Vports key_wakeup_ISR(void)
{
    knob_detect();
}

 

 

 

/*==============================================================*/

 

The debug result is: the software can enter code ①, ②, ③, ④.

 

 

 

It seems that the polarity of PS0 can't select rising edge, is it correct about my guess?

 

Please help me, thanks!

Attachments

Outcomes