GPIO_PWM

smallcracker 2021-01-29 00:00:00
Categories: Tags:

GPIOPinTypePWM

一、概述

感谢这位老哥

Configures pin(s) for use by the PWM peripheral.

配置引脚以用作PWM外设

Prototype:
void
GPIOPinTypePWM(uint32_t ui32Port,
uint8_t ui8Pins)

Parameters:
ui32Port is the base address of the GPIO port.
ui8Pins is the bit-packed representation of the pin(s).
Description:
The PWM pins must be properly configured for the PWM peripheral to function correctly. This function provides a typical configuration for those pin(s); other configurations may work as well depending upon the board setup (for example, using the on-chip pull-ups).

为了使PWM外设正常工作,一定要正确配置PWM引脚,这个函数为这些引脚提供了典型的配置,其他的配置也可能正确配置。

The pin(s) are specified using a bit-packed byte, where each bit that is set identifies the pin to be accessed, and where bit 0 of the byte represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.

Note:
This function cannot be used to turn any pin into a PWM pin; it only configures a PWM pin
for proper operation. Note that a GPIOPinConfigure() function call is also required to properly
configure a pin for the PWM function.

要配置一个引脚发挥PWM功能,还需调用GPIOPinConfigure()函数

A subset of GPIO pins on Tiva devices, notably those used by the JTAG/SWD interface and
any pin capable of acting as an NMI input, are locked against inadvertent reconfiguration.
These pins must be unlocked using direct register writes to the relevant GPIO_O_LOCK and
GPIO_O_CR registers before this function can be called. Please see the “gpio_jtag” example
application for the mechanism required and consult your part datasheet for information on
affected pins.

Returns:
None.

二、例程

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
//配置PWM预分频,这里不分频
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

//使能两个模块的时钟
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

//复用引脚
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);

//配置信号分配
GPIOPinConfigure(GPIO_PF2_M1PWM6);
GPIOPinConfigure(GPIO_PF3_M1PWM7);

//配置PWM发生器
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

//配置周期 表示100hz
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, 50000);

//配置占空比
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, 0);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, 0);

//使能PWM模块1输出
PWMOutputState(PWM1_BASE, (PWM_OUT_6_BIT | PWM_OUT_7_BIT), true);

//使能PWM发生器
PWMGenEnable(PWM1_BASE, PWM_GEN_3);