140 likes | 369 Views
Pulse Width Modulator (PWM). PWMConfigure.c Establish PWMConfigure.c files, and join it into the project. PWMConfigure.c file is responsible for the initialization of PWM.It enables the PWM generator and output pins, and set the PWM output cycle and duty cycle.
E N D
PWMConfigure.c • Establish PWMConfigure.c files, and join it into the project. • PWMConfigure.c file is responsible for the initialization of PWM.It enables the PWM generator and output pins, and set the PWM output cycle and duty cycle. • First of all, we add the following references in PWMConfigure.c file: • #include "HardwareLibrary.h" • #include "LuminaryDriverLibrary.h" • #include "SysCtlConfigure.h" • #include "PWMConfigure.h" • These reference file let us call the chip to enable and set functions. The PWMConfigure.h set up this section in the experiment using the cycle of PWM output. • We define t PWM initialization function PWMInitial(). • voidPWMInitial(void) • { • } • Then in PWMInital(), we call the function SysCtlPeripheralEnable (), SysCtlPWMClockSet (), PWMGenConfigure (), PWMGenPeriodSet (), PWMPulseWidthSet (), PWMOutputState (), PWMGenEnable () to initialize the PWM modulein turn. • Function SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM) can enable the PWM module,SysCtlPWMClockSet (SYSCTL_PWMDIV_1) set the clock frequency to be 1. The function PWMGenConfigure () initializes the PWM signal generator.Because we export pin 5 of PWM module to LED0, we choose corresponding PWM_GEN_2 signal generator andenable the output pin 5.We use PWMGenConfigure (PWM_BASE PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC) to initialize PWM_GEN_2. Function PWMGenPeriodSet() andPWMPulseWidthSet() set the PWM output cycle and duty cycle. Then we use the function PWMOutputState () toenable the output of the PWM module pin 5, PWMOutputState (PWM_BASE PWM_OUT_5_BIT, true). At this point, initialization of PWM module is complete, then we can enable the PWM signal generator, lighting LED0. • Specific function parameter can be set by reference in front of the library functionswhich are introduced.