Skip to content

Instantly share code, notes, and snippets.

@ctring
Last active February 15, 2024 11:36
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctring/7f12d812fb594eecc493 to your computer and use it in GitHub Desktop.
Save ctring/7f12d812fb594eecc493 to your computer and use it in GitHub Desktop.
Convert from SysCtlDelay in TivaWare library to milliseconds and microseconds delay.
/*
* delay.c - Delay in millisecond and microsecond functions
*
* Created on: Jul 7, 2014
* Author: Cuong T. Nguyen
*/
#include <stdint.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
void delayMs(uint32_t ui32Ms) {
// 1 clock cycle = 1 / SysCtlClockGet() second
// 1 SysCtlDelay = 3 clock cycle = 3 / SysCtlClockGet() second
// 1 second = SysCtlClockGet() / 3
// 0.001 second = 1 ms = SysCtlClockGet() / 3 / 1000
SysCtlDelay(ui32Ms * (SysCtlClockGet() / 3 / 1000));
}
void delayUs(uint32_t ui32Us) {
SysCtlDelay(ui32Us * (SysCtlClockGet() / 3 / 1000000));
}
@OmarRamadan1
Copy link

Hi, bro. How do you know 1 SysCtlDelay = 3 clock cycle? It is not mentioned in reference manual.

It is actually mentioned in the SysCtlDelay description in the api manual as the following "This function provides a means of generating a delay by executing a simple 3 instruction cycle
loop a given number of times. It is written in assembly to keep the loop instruction count
consistent across tool chains."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment