-
Notifications
You must be signed in to change notification settings - Fork 29
/
PWM_config.c
48 lines (40 loc) · 1.87 KB
/
PWM_config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*!
* @author Yash Bansod
* @date 29th September 2017
*
* @brief Source containing function definitions for PWM configuration
* @file PWM_config.c
*/
/* ----------------------- Include Files --------------------- */
#include "PWM_config.h"
/* ----------------------- Function Definition --------------------- */
// Function for Initializing PWM1_0
void PWM1_0_init(void){
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
// Enable the clock for peripherals PortD and PWM1
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
// Configure the PD0 for PWM signal (PWM module 1 generator 0)
ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
ROM_GPIOPinConfigure(GPIO_PD0_M1PWM0);
// Configure the PD1 and PD2 pins as Digital Output Pins
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
// Write the output value to the GPIO PortD to control the PD2 and PD3
ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3, 0x00);
// Calculate the Timer period of the PWM Module.
uint32_t ui32PWMClock = ROM_SysCtlClockGet() >> 6;
ui32Period_PWM1_0 = (ui32PWMClock / PWM_FREQUENCY) - 1;
// Configure thE PWM1 Genrator0 to work in Count Down Mode
ROM_PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
// Load the calculated time period to the Generator0 of the PWM1 Module
ROM_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Period_PWM1_0);
// Set the PWM duty cycle to a specified value
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui16Adjust_PWM1_0 * ui32Period_PWM1_0 / 100);
// Enable the PWM0 pin of the PWM Module 1 as output
ROM_PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
}
// Function for Enabling PWM1_0
void PWM1_0_enable(void){
// Enable the PWM1 Generator0
ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);
}