G14 A03 Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EE 690 - LAB REPORT 3

Group : 14
NAME : HARSHIT TAK AND MIRIYALA PRANAY KAMAL
ROLL NO. : EE23MT007 AND 200030033
FACULTY ; Dr. ABHIJIT KSHIRSAGAR

Systick Timer to generate a waveform with f = 1KHz and Duty


cycle = 20%

What is SysTick?
Cortex-M4 includes an integrated system timer, SysTick, which provides a simple, 24-bit
clear-on-write, decrementing, wrap-on-zero counter with a flexible control mechanism which can
be configured using three registers, which are:

SysTick Control and Status (STCTRL):


A control and status counter to configure its clock, enable the counter, enable the SysTick
interrupt, and determine counter status.

SysTick Reload Value (STRELOAD):


The reload value for the counter, used to provide the counter's wrap value.

SysTick Current Value (STCURRENT):


The current value of the counter.

Code :
#include <stdint.h>
#include <stdbool.h>
#include "tm4c123gh6pm.h"
#include <time.h>

/* SysTick memory-mapped registers */

#define STCTRL *((volatile long *) 0xE000E010) // control and status


#define STRELOAD *((volatile long *) 0xE000E014) // reload value
#define STCURRENT *((volatile long *) 0xE000E018) // current value
#define COUNT_FLAG (1 << 16) // bit 16 of CSR automatically set to 1
// when timer expires
#define ENABLE (1 << 0) // bit 0 of CSR to enable the timer
#define CLKINT (1 << 2) // bit 2 of CSR to specify CPU clock

#define CLOCK_MHZ 16

void Delay(int ms)


{
STCURRENT = 0;
STRELOAD = ms; // reload value for 'ms' milliseconds
STCTRL |= (CLKINT | ENABLE); // set internal clock, enable the timer

//STCTRL = 1;

while ((STCTRL & COUNT_FLAG) == 0) // wait until flag is set


{
; // do nothing
}
STCTRL = 0; // stop the timer

return;
}

int main(void)
{
SYSCTL_RCGC2_R |= 0x00000020;; /* enable clock to GPIOF */
GPIO_PORTF_LOCK_R = 0x4C4F434B; /* unlock commit register */
GPIO_PORTF_CR_R = 0x01; /* make PORTF0 configurable */
GPIO_PORTF_DIR_R = 0xFF; /* set PORTF3+PORTF2+PORTF1 pin as output
(LED) pin */
/* and PORTF4 and PORTF0 as input, SW1 is on PORTF4
and SW2 is PORTF0*/
GPIO_PORTF_DEN_R = 0xFF; /* set PORTF pins 4-3-2-1 as digital pins */
GPIO_PORTF_PUR_R = 0x00; /* enable pull up for pin 4 and 0 */

while(1)
{
GPIO_PORTF_DATA_R = 0xFF;
Delay(3200);
GPIO_PORTF_DATA_R = 0x00;
Delay(12800);

}
}
CALCULATION:
System Clock Frequency (f) = 16 MHz
Time period = 1/f = 62.5 ns

Count value for ON for 20% duty cycle = desired period / time period
= 200 μs /62.5 ns
= 3200
Count value for OFF = desired period / time period
= 800 μs / 62.5 ns
= 12800
Total time period = 200 μs + 800 μs = 1ms

System Clock Frequency (f) = 16 MHz


Time period = 1/f = 62.5 ns

Count value for ON for 50% duty cycle = desired period / time period
= 500 μ/62.5n
= 8000 ms
Count value for OFF = desired period / time period
= 500 μ / 62.5n
= 8000 ms
Total time period = 500 μs + 500 μs = 1ms

Observations and Outputs


In the above experiment we used a Systick timer which is an inbuilt peripheral in the board to
generate precise delay instead of using for loops like in LAB 2.

Benefits of Systick over For Loops:


1. Precise Timing: The Systick timer provides accurate delays without the overhead of
busy-wait loops, making it ideal for time-sensitive applications.
2. Non-blocking Operation: While waiting for the timer to expire, the CPU is free to
perform other tasks, enhancing overall system efficiency.
3. Reduced Power Consumption: The CPU can enter low-power states while waiting for
the Systick timer, conserving energy.
The output waveforms are plotted:

Fig 1 :1 KHZ 20% duty cycle waveform

Fig 2 : 1 KHZ 50% duty cycle waveform

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy