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.

  • Resolved

TMS570LS1224: How To Delay The Microcontroller In Some Time?

Part Number: TMS570LS1224

Hi, all. For TMS570LS1224, how could I delay the microcontroller for some micro seconds? Just like "sleep()" in PC's multithread programming?

And by the way, is this microcontroller multithread or single thread?

Thanks for help.

  • Hi Joe,

    To be more helpful on your request for a "delay" feature, I would need more information.

    For sure you can simply create a delay function where the CPU spins in a while loop until a counter passes a threshold. This would cause the CPU to spin on the loop instructions for the number of counts you define creating a general delay. The draw back of this is the delay loop would be subject to interruption if there were interrupts enabled.

    You can also use the RTI in several ways.

    The first option is to program a delay loop as before by use a flag set by the RTI interrupt to break out of/end the loop. This would be more definitive regarding the timing of the loop but would also require disabling of other interrupts to prevent the loop from being interrupted by the subsequent ISR execution.

    The other option is to use the low power modes of the device to implement either sleep or doze modes of operation. This will put the device in a low power mode (low power modes as extreme conditions do not offer much power savings due to current leackage of the silicon technology node). During these low power modes, the device is put into an idle state and most of the clocks are disabled. In your cause you would leave the RTI clock enabled and use an RTI interrupt to wakeup the device and restore normal operation.

    For your question about multithreading, this device is a lockstep CPU device. Effectively, there is one CPU core doing all the work and the second core is operating in lockstep and used a diagnostic to check for faults in the primary CPU. In short, it is still a single core architecture but with high diagnostic capability. There are no ways to perform parallel operation. This, doesn't, in itself limit multi-threading but means you would need to implement an RTOS to manage the threading (in reality it is time slicing). There are several RTOS's that support Hercules including FreeRTOS, SafeRTOS, Micrium, SCIOPTA, etc. A complete list can be seen at this link:

    Thanks and Regards,

    Chuck Davenport

  • In reply to Chuck Davenport:

    Hi, Chuck,

      I mean, for example, if I use GIO protocol, I set a pin to 5V, then, I want to keep 5V for 2 seconds, and then, back to 0V. The problem of writing a loop is that, I cannot have the relatively correct  " 2 seconds ". I do not know the number of iterations could make the CPU to delay for 2 s. In Arduino, I see they have such delay(int timeInterval) function.

      For low power modes, I am not sure, but I think it is too complex. I just want to simply delay the execution of program for a little time.


  • In reply to Joe X20:

    Hi Joe,

    Normally, the delay you are referring to is programmed specific to the microcontroller that you are using. For certain, the RTI can handle this or you can use the NHET or ePWM to do this if the signal is repeated every time period (i.e., a PWM). The other method is to write your own delay function. As you have noted, the Arduino support package comes with this high level function that is doing something under the hood to either use an embedded timer or to simply count execution cycles in a loop like I have suggested. To implement a loop, it is usually recommended to write it in assembler since the CPY cycles for each instruction can be found in the ARM instruction user guides. Each CPU cycle is, of course, 1/HCLK so knowing both the number of cycles to execute each instruction, and the time per cycle, you can determine the total time in a function.

    With that said, the easiest implementation would be to setup the RTI to fire a compare interrupt every mS for example. When the interrupt fires, increment a counter representing the number of mS that have passed. In your main, setup a loop for application execution with if statements or a switch case statement within the loop checking the value of the mS counter. When the counter reaches 2000 mS, toggle the GPIO as required. You can then use this same counter to initiate other tasks on a mS resolution. If 1mS is too short, set the RTI compare to higher value as long as the 32bit counter can handle it given the selected clock source for the RTI.

    Finally, just as a matter of correctness and clarity, the IO on Hercules is 3.3V not 5V so please be certain that your application isn't expecting 5V otherwise a level shifting circuit will be needed.

    Thanks and Regards,

    Chuck Davenport

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.