2024-09-22 19:49:27 +05:30
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2024-09-22 19:50:13 +05:30
|
|
|
#include "tm4c123gh6pm.h"
|
|
|
|
// Global Variables
|
|
|
|
volatile int duty = 50; // Initial duty cycle
|
|
|
|
volatile bool buttonPressed = false; // Track button state
|
|
|
|
volatile uint32_t pressDuration = 0; // Track how long the button is pressed
|
|
|
|
const long int PWM_PERIOD = 1000000; // Period for 100kHz in microseconds (10ms)
|
2024-09-22 19:50:42 +05:30
|
|
|
#define STCTRL *((volatile uint32_t *) 0xE000E010) // Control and status
|
|
|
|
#define STRELOAD *((volatile uint32_t *) 0xE000E014) // Reload value
|
|
|
|
#define STCURRENT *((volatile uint32_t *) 0xE000E018) // Current value
|
|
|
|
|
|
|
|
#define COUNT_FLAG (1 << 16) // Bit 16 of CSR automatically set to 1
|
|
|
|
#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_HZ 16000000 // Clock frequency of EK-TM4C123GXL
|
|
|
|
#define INTEN (1 << 1) // Bit 1 of CSR to enable interrupt
|
|
|
|
#define SYSTICK_RELOAD_VALUE(us) ((CLOCK_HZ / 1000000) * (us) - 1) // SysTick reload value in microseconds based on clock frequency
|
|
|
|
|
2024-09-22 19:51:55 +05:30
|
|
|
void GPIO_PORT_F_init(void) {
|
|
|
|
SYSCTL_RCGC2_R |= 0x00000020; // Enable clock to GPIOF
|
|
|
|
GPIO_PORTF_LOCK_R = 0x4C4F434B; // Unlock commit register
|
|
|
|
GPIO_PORTF_CR_R = 0x1F; // Make PORTF0 configurable
|
|
|
|
GPIO_PORTF_DEN_R = 0x1F; // Set PORTF digital enable
|
|
|
|
GPIO_PORTF_DIR_R = 0x0E; // Set PF0, PF4 as input and PF1, PF2, PF3 as output
|
|
|
|
GPIO_PORTF_PUR_R = 0x11; // PORTF PF0 and PF4 is pulled up
|
|
|
|
|
|
|
|
NVIC_EN0_R |= 1 << 30; // Enable interrupt for PORTF
|
|
|
|
GPIO_PORTF_IS_R = 0x00; // Make it edge-sensitive
|
|
|
|
GPIO_PORTF_IBE_R = 0x00; // Trigger on one edge
|
|
|
|
GPIO_PORTF_IEV_R = 0x00; // Falling edge event
|
|
|
|
GPIO_PORTF_IM_R |= 0x11; // Unmask interrupts for PF0 and PF4
|
|
|
|
}
|
2024-09-22 19:53:15 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
}
|