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.

Tmdsrm48usb Timer

Other Parts Discussed in Thread: HALCOGEN

Hello

I am new to embedded programming.

I have some confusion regarding timers.

I want to run two separate timers(HET). One should be 1 sec and other one should be 5 sec. Although I can use single timer for both timing but I want to run two separate timers. So my confusion is: 
1) Which interrupt will be invoked if both interrupt comes together ?
2)If I want to interrupt the ISR of other timer, how can I do that ? 

Is there any guide, how can I run 2 timers ? I am following these steps: 
a) toggles the High End Timer (HET) pin 1 based on an RTI timer compare 0 tick of one second, as shown in example_rtiBlinky.c
b)Enable RTI Compare 0 and RTI Compare 1.
c)Configure RTI compare 0 period to 1000 ms and Configure RTI compare 1 period to 5000 ms.

What modifications should I do in the ISR part to differentiate interrupts of two timers ?

  • Hi Ankush,

      Each compare will have its only interrupt flag so in the ISR you will need to distinguish between the different sources. When the compare0 (the 1000ms) interrupt comes in, the compare0 interrupt flag will be set. When the compare1 (the 5000ms) interrupt comes in, the compare1 flag will be set. You will write your handler according depending which flag is set and clear the flag by writing a '1' to it after you finish servicing the interrupt. Please check the RTIINTFLAG register.

  • Hello

    I am referring the example_rtiBlinky.c from Halcogen
    Can you please guide me , where the interrupt flag is cleared in this example code?
  • Hello Ankush,

      If you are using the FreeRTOS then this is all taken care of by the RTOS. You don't need to worry about clearing the RTI flags. You just create a task and let the RTOS schedule this task. If you have two tasks with one LED blinking at 1s and another LED blinking at 5s then the RTOS will schedule these two tasks and service them accordingly.

    I will suggest that you visit   to learn more about how the FreeRTOS works. 

      Below is a simple example that toggles one HET pin at 1s and another HET pin at 4s. 

    /* Include Files */
    
    #include "sys_common.h"
    #include "system.h"
    
    /* USER CODE BEGIN (1) */
    /* Include FreeRTOS scheduler files */
    #include "FreeRTOS.h"
    #include "os_task.h"
    
    /* Include HET header file - types, definitions and function declarations for system driver */
    #include "het.h"
    #include "esm.h"
    
    /* Define Task Handles */
    xTaskHandle xTask1Handle, xTask2Handle;
    
    /* Task1 */
    void vTask1(void *pvParameters)
    {
        for(;;)
        {
            /* Toggle HET[17] with timer tick */
            gioSetBit(hetPORT1, 17, gioGetBit(hetPORT1, 17) ^ 1);
            vTaskDelay(1000);
        }
    }
    void vTask2(void *pvParameters)
    {
        for(;;)
        {
            /* Toggle HET[0] with timer tick */
            gioSetBit(hetPORT1, 0, gioGetBit(hetPORT1, 0) ^ 1);
            vTaskDelay(4000);
        }
    }
    /* USER CODE END */
    
    
    /** @fn void main(void)
    *   @brief Application main function
    *
    */
    
    /* USER CODE BEGIN (2) */
    /* USER CODE END */
    
    
    void main(void)
    {
    /* USER CODE BEGIN (3) */
    
        /* Set high end timer GIO port hetPort pin direction to all output */
        gioSetDirection(hetPORT1, 0x20001);
    
    
        /* Create Task 1 */
        if (xTaskCreate(vTask1, (const signed char *)"Task1", configMINIMAL_STACK_SIZE, NULL, 1, &xTask1Handle) != pdTRUE)
        {
            /* Task could not be created */
            while(1);
        }
    //    vTaskDelay(1000);
        /* Create Task 2 */
         if (xTaskCreate(vTask2, (const signed char *)"Task2", configMINIMAL_STACK_SIZE, NULL, 1, &xTask2Handle) != pdTRUE)
         {
             /* Task could not be created */
             while(1);
         }
    
        /* Start Scheduler */
        vTaskStartScheduler();
    
        /* Run forever */
        while(1);
    /* USER CODE END */
    }

  • Thanks Charles,
    I got the example using FreeRTOS.

    The example is without using RTOS. Can you please help me to explain code without FreeRTOS ? Specially the portion where the Interrupt flag is cleared in example_rtiBlinky.c
  • Hi Ankush,

     The clearing of the flag is done inside the ISR. See below example. Upon the ISR for the rtiCompare0Interrupt() is entered, the first thing it does is rtiREG1->INTFLAG = 1U. This is to clear the flag for the compare0 source. Upon the ISR for the rtiCompare1Interrupt() is entered, the first thing it does is rtiREG1->INTFLAG = 2U. This is to clear the flag for the compare1 source. You can find the ISR in the rti.c

    #pragma CODE_STATE(rtiCompare0Interrupt, 32)
    #pragma INTERRUPT(rtiCompare0Interrupt, IRQ)
    
    /* SourceId : RTI_SourceId_022 */
    /* DesignId : RTI_DesignId_022 */
    /* Requirements : HL_SR95 */
    void rtiCompare0Interrupt(void)
    {
    /* USER CODE BEGIN (74) */
    /* USER CODE END */
    
        rtiREG1->INTFLAG = 1U;
        rtiNotification(rtiNOTIFICATION_COMPARE0);
    
    /* USER CODE BEGIN (75) */
    /* USER CODE END */
    }
    
    /* USER CODE BEGIN (76) */
    /* USER CODE END */
    
    /** @fn void rtiCompare1Interrupt(void)
    *   @brief RTI1 Compare 1 Interrupt Handler
    *
    *   RTI1 Compare 1 interrupt handler 
    *
    */
    #pragma CODE_STATE(rtiCompare1Interrupt, 32)
    #pragma INTERRUPT(rtiCompare1Interrupt, IRQ)
    
    /* SourceId : RTI_SourceId_023 */
    /* DesignId : RTI_DesignId_022 */
    /* Requirements : HL_SR95 */
    void rtiCompare1Interrupt(void)
    {
    /* USER CODE BEGIN (77) */
    /* USER CODE END */
    
        rtiREG1->INTFLAG = 2U;
        rtiNotification(rtiNOTIFICATION_COMPARE1);
    
    /* USER CODE BEGIN (78) */
    /* USER CODE END */
    }

  • Thanks Charles

    I want to ask one more thing. If I am in ISR part of first timer T1 interrupt doing some time consuming function. And if interrupt by other timer T2 occurs, then what the program will do ? It will enter in T2 interrupt ISR part ? How can we make it possible to enter in T2 ISR part if T1 interrupt flag is cleared but ISR function is not finished ?
  • Hi Ankush,
    By default the ARM CPU will disable interrupt by setting the I bit in the CPSR register. Setting the I bit will disable further IRQ interrupt. This is to prevent nested interrupt. But if you want nested interrupt you can clear the I bit after you clear the RTI flag. It may become a bit difficult to manage if you have multiple levels of nesting when many interrupts are coming in.
  • Thanks Chales
    But now I have problem in Halcogen.
    I am not able to Navigate: -> OS -> General to Configure OS timer tick to 1 ms:
    I have updated my Halcogen to 04.05.02 version and I am not having option of OS in tabs. PINMUX RTI GIO. Not able to see OS option at all. What should I do ??
  • Ankush,

      When you create a new project did you pick the one with the the FreeRTOS? If you don't select the one with the FreeRTOS then you will not have not the OS tab.

  • Hello

    I have successfully executed freeRTOS program with two tasks running which blink led.
    But I want to make sequence as follow
    1) Timer 1: 2 sec repeating.
    2)Timer 1 ISR: create semaphore to enable task 1
    3) Timer 2: 3 sec repeating.
    4) Timer 2 ISR: create semaphore to enable task 2

    My motto behind the above logic is, instead of blinking led continuously, the CPU should switch them on/off at specific interval and remaining time it should remain idle.
  • Hi Ankush,
    I will suggest that you go to www.freertos.org for advice on using FreeRTOS.

    I also find the below app note to be helpful in answering your question about using FreeRTOS semaphore.

    www.atmel.com/.../atmel-42382-getting-started-with-freertos-on-atmel-sam-flash-mcus_applicationnote_at04056.pdf
  • Hi Ankush,

    This seems like a good project - especially for someone learning how to use freeRTOS.

    Have you considered writing up your experiences in a Blog? If you make a good writeup - we might wind up getting a TI 'tweet' to point people to your blog or something to that effect. It's really important and valuable to have content geared to beginners and what we do ourselves is focused more at experts... so community content aimed at beginners is much appreciated.
  • Dear Anthony,

    Surely I will write about it.
    But I think it is not new thing.
    But as you have suggest good idea, I would like to ask you about the blog writing websites. Can you please suggest me, which I can post on linkedin which will help me to get job ?
  • Hi Ankush,

    For Hercules MCUs you might want to look at the excellent posts of and .

    I would not worry if a topic is 'not new' if you can explain something well with clear examples that others can follow. There is always demand for good examples and clear instructions even if the concept isn't 'new'.
    Many people will appreciate your fresh perspective as well - sometimes the more you know about something actually the harder it makes it to explain to a non-expert... a fresh perspective can be an asset so don't be discouraged.
  • Okay.
    I will follow these experts. I will try to frame my experience.
    Thanks alot Mr Anthony.
  • Super - and keep us in the loop as you work on your blog - in case we can help.
  • Thanks Charles
    I will go through this pdf and will come back if I face problem.
  • when you have, your blog ready please share the link here, so we can see it!
    Thank you very much for sharing
    Regards
    Martin V.