您的位置 首页 5G

STM32 TIM重映射

复用功能没有重映射部分重映射完全重映射TIM3_CH1PA6PB4PC6CH2PA7PB5PC7CH3PB0PB0PC8CH4PB1PB1PC91234567891011121314151617181

复用功用 没有重映射 部分重映射 彻底重映射
TIM3_CH1 PA6 PB4 PC6
CH2 PA7 PB5 PC7
CH3 PB0 PB0 PC8
CH4 PB1 PB1 PC9
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**重映射 tim3 使得PC7 PC8输出Pwm波
******************************************************************************
* @file Project/Template/main.c
* @author MCD Application Team
* @version V3.0.0
* @date 04/06/2009
* @brief Main program body
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
*

COPYRIGHT 2009 STMicroelectronics

*/
/* Includes ——————————————————————*/
#include “stm32f10x.h”
#include “stm32f10x_tim.h”
#include “misc.h”
voidGPIO_AFIODeInit(void);//这个函数不能落下,不然不能成功
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;//装备PWM需求运用的结构体声名
TIM_OCInitTypeDef TIM_OCInitStructure;
u16 CCR3_Val =250;
u16 CCR4_Val =250;
voidGPIO_Config(void);
voidTimer_Config(void);
/**
* @brief Delay program.
* @param None
* @retval : None
*/
voidDelay (u32 nCount)
{
for(; nCount != 0; nCount–);
}
/**
* @brief Main program.
* @param None
* @retval : None
*/
intmain(void)
{
/* Setup STM32 system (clock, PLL and Flash configuration) */
SystemInit();
GPIO_Config();
Timer_Config();
/* Infinite loop */
while(1) {
}
}
/**
* @brief GPIO_Config program.
* @param None
* @retval : None
*/
voidGPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
GPIO_AFIODeInit();//刚开始没有这个句子,所以一向没有重映射成功
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3 , ENABLE);//这个便是重映射功用函数
/*GPIOA Configuration: TIM3 channel 3 and 4 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//这儿也要留意
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);//这四句是为了校验终究PB0,PB1是否还有PWM输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
voidTimer_Config(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = 999;//鄙人一个更新事情装入活动的主动重装载寄存器周期的值
TIM_TimeBaseStructure.TIM_Prescaler = 0;// 设置了用来作为 TIMx 时钟频率除数的预分频值
TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel3 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;//TIM_OCMode
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR3_Val;//设置了待装入捕获比较寄存器的值
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;//TIM_OCPolarity :TIM 输出比较极性高
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);//使能或许失能 TIM3 在 CCR3 上的预装载寄存器
/* PWM1 Mode configuration: Channel4 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR4_Val;
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);//敞开时钟,别落下
}
/**
* @brief EXTI_Config Program.
* @param None
* @retval : None
*/
/**
* @brief Configures the nested vectored interrupt controller.
* @param None
* @retval : None
*/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
voidassert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(“Wrong parameters value: file %s on line %d\r\n”, file, line) */
/* Infinite loop */
while(1)
{
}
}
#endif
/**
* @}
*/
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/5g/276289.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部