当前位置:网站首页>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
}
}边栏推荐
- CANoe. Diva operation guide TP layer test
- Measurement fitting based on Halcon learning -- Practice [2]
- Jmeter- (I) installation of interface test
- Modprobe: fatal: module kvmgt not found, kvmgt has no module, kvmgt has no driver, gvt-g precautions, gvt-g precautions for starting win10 in UEFI mode
- Legal mix of settlements (utf8mb4_0900_ai_ci, implicit) and (utf8mb4_general_ci, implicit) error resolution
- Guidelines for implementing dns-sd in an NMOS environment
- HNU network counting experiment: Experiment 5 network layer and link layer protocol analysis (packettracer)
- [proteus simulation] Arduino uno pattern water lamp
- Jmeter- (II) basic interface and common components for interface testing
- 实验三的各种特效案例
猜你喜欢

Free cloud function proxy IP pool just released
What is the difficulty of the form tool that costs billions of dollars? Exclusive interview with si no

Various special effect cases of Experiment 3

idea怎么把自己的项目打包成jar包

org. apache. ibatis. exceptions. PersistenceException:

Bear market guide | some essential lessons and specific survival rules

Jmeter- (II) basic interface and common components for interface testing

Did you really learn the right game modeling with 3DMAX?

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

How to write an infinite loop
随机推荐
Solve the parameter problem that laravels cannot receive wechat callback
Support JPEG format in GD Library in php7.4
Renren mall locates the file according to the route
Jmeter- (II) basic interface and common components for interface testing
Insert picture in markdown
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
Modprobe: fatal: module kvmgt not found, kvmgt has no module, kvmgt has no driver, gvt-g precautions, gvt-g precautions for starting win10 in UEFI mode
什么是代码基线?
Weed FS stress test
Devops之制品库平台nexus实践
What is the difficulty of the form tool that costs billions of dollars? Exclusive interview with si no
Simple record of fire & spell effects
Bat script simple command
Invalid bound statement (not found): com. qf. mapper. PassengerMapper. findByPassengerId
Win11录屏数据保存在哪里?Win11录屏数据保存的位置
Command 'GCC' failed with exit status 1 when PIP install mysqlclient
【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧
Canoe learning notes (4)
Shell syntax
St2110 network connected display for virtualized production