Last active
February 15, 2024 11:36
-
-
Save ctring/7f12d812fb594eecc493 to your computer and use it in GitHub Desktop.
Convert from SysCtlDelay in TivaWare library to milliseconds and microseconds delay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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)); | |
} | |
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
It was 7 years ago so I'm not exactly sure where I got that number. A Google search for
SysCtlDelay
yields this document (which looks very familiar to me so highly likely I got the number from it). On page 77, it says: