当前位置:网站首页>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
}
}
边栏推荐
- Winget: the "Winget" item cannot be recognized as the name of cmdlet, function, script file or runnable program. Win11 Winget cannot be used to solve this problem
- Input a line of characters to count the English letters, spaces, numbers and other characters
- Introduction to HLS content diversion and insert advertising specification
- Send a more awesome website, which can convert curl commands into code in any language
- InfiniBand& RDMA
- IAAs, PAAS, SaaS, baas, FAAS differences
- PHP compressed file
- The robotframework executes JS commands to move the mouse from X to y
- mysql 通过sql 修改多表增加多个字段
- ASP. Net core uses function switches to control Route Access (Continued) yyds dry inventory
猜你喜欢
Jmeter- (IV) regular expression for interface testing
Renren mall locates the file according to the route
电脑手写板怎么才能连接电脑使用
Simulate ATM system (account opening, login, account query, withdrawal, deposit, transfer, password modification, account cancellation)
ASC - DAY2
【hnu暑学期】数据库系统设计 准备阶段
Did you really learn the right game modeling with 3DMAX?
Php7.4 arm environment compilation and installation error invalid 'ASM': invalid operate prefix '%c'
What is a ZFS file system
熊市指南|一些本质的教训与具体的生存法则
随机推荐
leetcode: 49. Grouping of alphabetic words
Q5 s905l firmware version 202109
When we talk about the metauniverse, what are we talking about?
[proteus simulation] Arduino uno pattern water lamp
Jmeter- (III) create user test cases for interface testing
Zhiyun health is about to go public: long-term losses, meinian health Yu Rong has withdrawn, and it is difficult to be optimistic about the future
HNU数据库系统概论 ODBC
Volatile qualifier
Big end and small end
Win11 start menu right click blank? The right button of win11 start menu does not respond. Solution
Understand two major web development patterns
Tcapulusdb Jun · industry news collection (VI)
Processing of limit operator in Presto
Insert picture in markdown
InfiniBand& RDMA
PHP runtime and memory consumption statistics code
北工大毕业时用的一些网址
MySQL modifies multiple tables and adds multiple fields through SQL
Win11录屏数据保存在哪里?Win11录屏数据保存的位置
Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing Bing