From 5bcde2ebc0015b1ed1a95a8af15dc95c68dc4a16 Mon Sep 17 00:00:00 2001 From: Uttam Ambappa Bhavimani Date: Sun, 22 Sep 2024 19:54:50 +0530 Subject: [PATCH] Update Group21_Lab06_Task2/main.c Define Delay Function --- Group21_Lab06_Task2/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Group21_Lab06_Task2/main.c b/Group21_Lab06_Task2/main.c index 0c6c861..460ef92 100644 --- a/Group21_Lab06_Task2/main.c +++ b/Group21_Lab06_Task2/main.c @@ -36,4 +36,12 @@ void systick_setting(void) { STRELOAD = SYSTICK_RELOAD_VALUE(PWM_PERIOD/100); // Set reload value for 10 µs intervals (100 kHz) STCTRL |= (CLKINT | ENABLE | INTEN); // Set internal clock, enable the timer STCURRENT = 0; // Clear STCURRENT value +} +void delay(int us) // DEFINING DELAY FUNCTION +{ + STRELOAD = SYSTICK_RELOAD_VALUE(us); // RELOAD VALUE FOR REQUIRED DELAY + STCURRENT = 0; // Clear STCURRENT + STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick + while ((STCTRL & (1 << 16)) == 0); // Wait until flag is set + STCTRL &= 0x0; // Stop the timer } \ No newline at end of file