当前位置:网站首页>STM32F103RCT6
STM32F103RCT6
2022-06-25 21:58:00 【Dear_ Atri】
In the configuration structure TIM_OCInitTypeDef when , The elements are as follows :
- (1) TIM_OCMode: Compare output mode selection , There are eight in all , The common one is PWM1/PWM2. It sets CCMRx register OCxM[2:0] The value of a .
- (2) TIM_OutputState: Compare output enable , Determine the final output comparison signal OCx Whether to output through external pins . It sets TIMx_CCER register CCxE/CCxNE The value of a .
- (3) TIM_OutputNState: Compare complementary output enable , decision OCx The complementary signals OCxN Whether to output through external pins . It sets CCER register CCxNE The value of a .
- (4) TIM_Pulse: Compare the output pulse width , Actually set the comparison register CCR Value , Determine the pulse width . The settable range is 0 to 65535.
- (5) TIM_OCPolarity: Compare the output polarity , Optional OCx For high level active or low level active . It determines the effective level of the timer channel . It sets CCER The register of CCxP The value of a .
- (6) TIM_OCNPolarity: Compare complementary output polarity , Optional OCxN For high level active or low level active . It sets TIMx_CCER The register of CCxNP The value of a .
- (7) TIM_OCIdleState: Channel output level setting in idle state , Optional output 1 Or output 0, That is, in the idle state (BDTR_MOE Position as 0) when , After the dead time, the timer channel outputs high level or low level . It sets CR2 The register of OISx The value of a .
- (8) TIM_OCNIdleState: Complementary channel output level setting in idle state , Optional output 1 Or output 0, That is, in the idle state (BDTR_MOE Position as 0) when , After the dead time, the timer complementary channel outputs high level or low level flat , The set value must be the same as TIM_OCIdleState contrary . It's set to be CR2 The register of OISxN The value of a .
Initialize structure TIM_TimeBaseInitTypeDef and TIM_OCInitTypeDef after , You can set the duty cycle to PWM Output .
void TIM3_PWM_Init(u32 ARR , u32 PSC)
{
// This part needs to be modified manually IO Port setup
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); //TIM3 Clock enable
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // Can make PORTA The clock
GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_TIM3); //GPIOA6 Reuse as timer 3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //GPIOFA
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Reuse function
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // Speed 100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // Push pull multiplex output
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Pull up
GPIO_Init(GPIOA,&GPIO_InitStructure); // initialization PA6
TIM_TimeBaseStructure.TIM_Prescaler=PSC; // Timer frequency division
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; // Upcount mode
TIM_TimeBaseStructure.TIM_Period=ARR; // Automatic reload load value
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);// Initialize the timer 3
// initialization TIM14 Channel1 PWM Pattern
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; // Select timer mode :TIM Pulse width modulation mode 2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; // Compare output enable
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; // Output polarity :TIM The output is less polar
TIM_OC1Init(TIM3, &TIM_OCInitStructure); // according to T The specified parameter initializes the peripheral TIM1 4OC1
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); // Can make TIM3 stay CCR1 Pre loaded registers on
TIM_ARRPreloadConfig(TIM3,ENABLE);//ARPE Can make
TIM_Cmd(TIM3, ENABLE); // Can make TIM3
} int main(void)
{
u16 ledpwmval=0;
u8 flag=1;
delay_init(168); // Initialization delay function
LED_GPIO_Config(); // initialization LED
TIM3_PWM_Init(100-1,84-1); // Initialize the timer
while(1)
{
delay_ms(10);
if(flag)ledpwmval++;
else ledpwmval--;
if(ledpwmval==0)flag=1;
if(ledpwmval==40)flag=0;
TIM_SetCompare1(TIM3,ledpwmval); // Modify the comparison value , Change the duty cycle
}
}边栏推荐
- What is the difficulty of the form tool that costs billions of dollars? Exclusive interview with si no
- What if win11 cannot delete the folder? Win11 cannot delete folder
- 什么是代码基线?
- ITU AI and multimedia Seminar: exploring new areas and cross SDO synergy
- js 限制鼠标移动范围
- Jmeter- (III) create user test cases for interface testing
- leetcode: 49. 字母异位词分组
- 数学分析_笔记_第4章:连续函数类和其他函数类
- ECU test modify test case
- About the version mismatch of unity resource package after importing the project
猜你喜欢

Introduction to HNU database system ODBC

js禁用浏览器 pdf 打印、下载功能(pdf.js 禁用打印下载、功能)

Presto中Limit算子的处理过程

How to write an infinite loop

Jmeter- (I) installation of interface test

SSH modifies grub in heiqunhui ds918+ system 7.0.1 cfg

Tcapulusdb Jun · industry news collection (VI)

用idea建立第一個網站

How to use Matplotlib library to realize enlarged display of graphic local data

Understand two major web development patterns
随机推荐
Volatile qualifier
Tcapulusdb Jun · industry news collection (VI)
Php7.4 arm environment compilation and installation error invalid 'ASM': invalid operate prefix '%c'
The latest (2022-2-16) vulnerability of WordPress plug-in bee collection (XSS, WordPress user name exposure, arbitrary article publishing) is repeated
Legal mix of settlements (utf8mb4_0900_ai_ci, implicit) and (utf8mb4_general_ci, implicit) error resolution
Pytest assert encapsulation
Summary of digital image processing knowledge points
了解有哪几个C标准&了解C编译管道
If switch branch structure
[proteus simulation] Arduino uno+ key controls 2-bit digital tube countdown
Support JPEG format in GD Library in php7.4
Win11无法删除文件夹怎么办?Win11无法删除文件夹的解决方法
HNU计网实验:实验五 网络层与链路层协议分析(PacketTracer)
“No bean named ‘UserController‘ available“
About the version mismatch of unity resource package after importing the project
How does idea package its own projects into jar packages
SwiftUI 4 新功能 之 网格视图Gridview组件 (教程含源码)
Using recursive method to find the value of 1~n
XMIND to excel test case
Will neuvector be the next popular cloud native security artifact?