This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Halcogen Level-triggered GIO Interrupt

Other Parts Discussed in Thread: HALCOGEN

Hello,

I am a newbie to MCU programming and I just started playing around the TMS570 Hercules Safety MCU DK. I started with toggling a light by responding to GIOA[7] interrupt (using HALCoGen I enabled the interrupt to be falling edge and of high priority). But if I understand correctly what I have searched around, this is a level triggered interrupt. What should I do if I want while holding the button down my LED be on and when I release it, to turn off?


Thank you in advance.

  • Hi Stelios,

    The interrupts are triggered for Rising and Falling edges. You can turn the LED On in the Rising Edge interrupt and turn it Off in the falling edge interrupt. Is this what you mean or am I missing something?

    Thanks and Regards,
    Vineeth
  • Hello Vinneth,

    I am sure that I am the one who is missing something. What I did:

    - In Halcogen, I set this (If I understand correctly I enabled a high priority interrupt in GIO[7]

    I also set VIM channel 9 as follows:

    - In code composer studio

    file notification.c (This is the ISR, right?).

    void gioNotification(uint32_t bit)
    {
    /*  enter user code between the USER CODE BEGIN and USER CODE END. */
    /* USER CODE BEGIN (19) */
        if(gioGetBit(gioPORTA, 7) == 0)
            Task_Number = 1;
        else
            Task_Number = 0;
    /* USER CODE END */
    }

    in sys_main.c

    void main(void)
    {
    /* USER CODE BEGIN (3) */
        gioInit();
        gioSetDirection(hetPORT1, 0xFFFFFFFF);
        _enable_IRQ();
        while(1)
        {
            switch(Task_Number)
            {
            case 0:
                gioSetBit(hetPORT1, 25, 0);
                i = 1000000;
                while(i!=0)
                    i--;
                break;
            case 1:
                gioSetBit(hetPORT1, 25, 1);
                i = 1000000;
                while(i!=0)
                    i--;
                break;
            }
        }

    /* USER CODE END */
    }


    The result is that when I press the button, the LED turns on...But when I release it, it does not go off. Furthermore, I cannot use a level-triggered interrupt? I mean to check when the button is pressed or released.

    Thank you for your reply.

  • Hi Stelios,

    You have to call gioEnableNotification()  [after gioInit()]] to enable interrupts for the pin. But, I don't get how the LED turns On when you press the button. Anyway, just add this call and see what happens.

    Also, I'm just curious as to why you added the delay after gioSetBit() calls. Was this for the button de-bouncing issue?

    Thanks and Regards,

    Vineeth

  • Hello Vineeth,

    I modified my code as you suggested:

    sys_main.c:

    void main(void)
    {
    /* USER CODE BEGIN (3) */
    gioInit();
    gioEnableNotification(7);
    gioSetDirection(hetPORT1, 0xFFFFFFFF);
    _enable_IRQ();
    while(1)
    {
    switch(Task_Number)
    {
    case 0:
    gioSetBit(hetPORT1, 25, 0);
    break;
    case 1:
    gioSetBit(hetPORT1, 25, 1);
    break;
    }
    }

    and notification.c is the same:

    void gioNotification(uint32_t bit)
    {
    /* enter user code between the USER CODE BEGIN and USER CODE END. */
    /* USER CODE BEGIN (19) */
    if(gioGetBit(gioPORTA, 7) == 0)
    Task_Number = 1;
    else
    Task_Number = 0;
    /* USER CODE END */
    }

    I added breakpoints in my two cases in main and I noticed that sometimes the Task_Number becomes 1, but not always. If I understand correctly, when I press the button, the signal is toggling. Right? What would be a solution?
  • You can also generate an interrupt on both a rising edge and a falling edge on the GIOA[7] pin. This is done by setting bit 7 of the GIOINTDET register (address 0xFFF7BC08). Unfortunately, this feature is not supported by HALCoGen and is on the to-do list for a future update.

    This may make your code simpler.

  • As Sunil mentioned, we have configured GIO interrupt only on falling edges. You will have to configure it to trigger on both edges(not supported by HalCoGen).
    The "sometimes" you mentioned could be a result of button switch bouncing, in which case, you can go ahead and add that delay you had introduced(this should reduce it to an extend).
  • Thank you both,

    I did it work, but I would like to use a timer instead of a loop for delay. I am looking for clocks and delays in Cortex-R, but I cannot understand which one I have to use and how to do it. Any tips?

    Thank you in advance,
    Stelios
  • Hi Stelios,

    You can use RTI module as a timer. Example code for RTI should be available in HalCoGen to help you along the way.

    After setting up the RTI, you can call gioDisableNotification() and  rtiStartCounter()  instead of the delay loop. Inside the rtiNotification(), you can call gioEnableNotification(). This way, we will disable the GIO interrupt for the configured amount of time and then re-enable it.

    Thanks and Regards,
    Vineeth

     

    PS:- If your question has been answered by a reply, please select “Verify Answer”.

  • Hello Vineeth,

    I will verify your useful reply. I have one more problem and I do not know if I have to create a new post. I am trying to use printf but it does not work. Actually I realized that my program terminates at the point that I use it. I found out that I have to set the stack and heap size in a large amount (i.e 0x400C) and to check "Enable CIO function use". I did the above...but it does not work. Any suggestions?

    Thank you once more. :)
  • Stellios,

    Here is a thread that talk about printf with a very basic example.

    Please have a look and let me know.

  • Hello Jean-Marc,

    It works like a charm. Thank you for your time. :)

    Stelios