/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v30x_tim.c
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : This file provides all the TIM firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "ch32v30x_tim.h"
#include "ch32v30x_rcc.h"
/* TIM registers bit mask */
#define SMCFGR_ETR_Mask ((uint16_t)0x00FF)
#define CHCTLR_Offset ((uint16_t)0x0018)
#define CCER_CCE_Set ((uint16_t)0x0001)
#define CCER_CCNE_Set ((uint16_t)0x0004)
static void TI1_Config(TIM_TypeDef *TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
uint16_t TIM_ICFilter);
static void TI2_Config(TIM_TypeDef *TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
uint16_t TIM_ICFilter);
static void TI3_Config(TIM_TypeDef *TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
uint16_t TIM_ICFilter);
static void TI4_Config(TIM_TypeDef *TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
uint16_t TIM_ICFilter);
/*********************************************************************
* @fn TIM_DeInit
*
* @brief Deinitializes the TIMx peripheral registers to their default
* reset values.
*
* @param TIMx - where x can be 1 to 4 to select the TIM peripheral.
*
* @return none
*/
void TIM_DeInit(TIM_TypeDef *TIMx)
{
if(TIMx == TIM1)
{
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, DISABLE);
}
else if(TIMx == TIM8)
{
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, DISABLE);
}
else if(TIMx == TIM9)
{
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, DISABLE);
}
else if(TIMx == TIM10)
{
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, DISABLE);
}
else if(TIMx == TIM2)
{
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
}
else if(TIMx == TIM3)
{
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE);
}
else if(TIMx == TIM4)
{
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, DISABLE);
}
else if(TIMx == TIM5)
{
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, DISABLE);
}
else if(TIMx == TIM6)
{
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, DISABLE);
}
else if(TIMx == TIM7)
{
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, DISABLE);
}
}
/*********************************************************************
* @fn TIM_TimeBaseInit
*
* @brief Initializes the TIMx Time Base Unit peripheral according to
* the specified parameters in the TIM_TimeBaseInitStruct.
*
* @param TIMx - where x can be 1 to 4 to select the TIM peripheral.
* TIM_TimeBaseInitStruct - pointer to a TIM_TimeBaseInitTypeDef
* structure.
*
* @return none
*/
void TIM_TimeBaseInit(TIM_TypeDef *TIMx, TIM_TimeBaseInitTypeDef *TIM_TimeBaseInitStruct)
{
uint16_t tmpcr1 = 0;
tmpcr1 = TIMx->CTLR1;
if((TIMx == TIM1) || (TIMx == TIM2) || (TIMx == TIM3) || (TIMx == TIM4) ||
(TIMx == TIM5) || (TIMx == TIM8) || (TIMx == TIM9) || (TIMx == TIM10))
{
tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_DIR | TIM_CMS)));
tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_CounterMode;
}
if((TIMx != TIM6) && (TIMx != TIM7))
{
tmpcr1 &= (uint16_t)(~((uint16_t)TIM_CTLR1_CKD));
tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision;
}
TIMx->CTLR1 = tmpcr1;
TIMx->ATRLR = TIM_TimeBaseInitStruct->TIM_Period;
TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;
if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM9) || (TIMx == TIM10))
{
TIMx->RPTCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter;
}
TIMx->SWEVGR = TIM_PSCReloadMode_Immediate;
}
/*********************************************************************
* @fn TIM_OC1Init
*
* @brief Initializes the TIMx Channel1 according to the specified
* parameters in the TIM_OCInitStruct.
*
* @param TIMx - where x can be 1 to 4 to select the TIM peripheral.
* TIM_OCInitStruct - pointer to a TIM_OCInitTypeDef structure.
*
* @return none
*/
void TIM_OC1Init(TIM_TypeDef *TIMx, TIM_OCInitTypeDef *TIM_OCInitStruct)
{
uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
TIMx->CCER &= (uint16_t)(~(uint16_t)TIM_CC1E);
tmpccer = TIMx->CCER;
tmpcr2 = TIMx->CTLR2;
tmpccmrx = TIMx->CHCTLR1;
tmpccmrx &= (uint16_t)(~((uint16_t)TIM_OC1M));
tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CC1S));
tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
tmpccer &= (uint16_t)(~((uint16_t)TIM_CC1P));
tmpccer |= TIM_OCInitStruct->TIM_OCPolarity;
tmpccer |= TIM_OCInitStruct->TIM_OutputState;
if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM9) || (TIMx == TIM10))
{
tmpccer &= (uint16_t)(~((uint16_t)TIM_CC1NP));
tmpccer |= TIM_OCInitStruct->TIM_OCNPolarity;
tmpccer &= (uint16_t)(~((uint16_t)TIM_CC1NE));
tmpccer |= TIM_OCInitStruct->TIM_OutputNState;
tmpcr2 &= (uint16_t)(~((uint16_t)TIM_OIS1));
tmpcr2 &= (uint16_t)(~((uint16_t)TIM_OIS1N));
tmpcr2 |= TIM_OCInitStruct->TIM_OCIdleState;
tmpcr2 |= TIM_OCInitStruct->TIM_OCNIdleState;
}
TIMx->CTLR2 = tmpcr2;
TIMx->CHCTLR1 = tmpccmrx;
TIMx->CH1CVR = TIM_OCInitStruct->TIM_Pulse;
TIMx->CCER = tmpccer;
}
/*********************************************************************
* @fn TIM_OC2Init
*
* @brief Initializes the TIMx Channel2 according to the specified
* parameters in the TIM_OCInitStruct.
*
* @param TIMx - where x can be 1 to 4 to select the TIM peripheral.
* TIM_OCInitStruct - pointer to a TIM_OCInitTypeDef structure.
*
* @return none
*/
void TIM_OC2Init(TIM_TypeDef *TIMx, TIM_OCInitTypeDef *TIM_OCInitStruct)
{
uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CC2E));
tmpccer = TIMx->CCER;
tmpcr2 = TIMx->CTLR2;
tmpccmrx = TIMx->CHCTLR1;
tmpccmrx &= (uint16_t)(~((uint16_t)TIM_OC2M));
tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CC2S));
tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8);
tmpccer &= (uint16_t)(~((uint16_t)TIM_CC2P));
tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 4);
tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 4);
if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM9) || (TIMx == TIM10))
{
tmpccer &= (uint16_t)(~((uint16_t)TIM_CC2NP));
tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 4);
tmpccer &= (uint16_t)(~((uint16_t)TIM_CC2NE));
tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 4);
tmpcr2 &=
没有合适的资源?快使用搜索试试~ 我知道了~
沁恒CH32V30X学习笔记11-使用外部时钟模式2采集脉冲计数
共102个文件
h:43个
c:42个
prefs:3个
0 下载量 119 浏览量
2024-02-19
22:34:03
上传
评论
收藏 387KB ZIP 举报
温馨提示
沁恒CH32V30X学习笔记11-使用外部时钟模式2采集脉冲计数
资源推荐
资源详情
资源评论
收起资源包目录
沁恒CH32V30X学习笔记11-使用外部时钟模式2采集脉冲计数 (102个子文件)
ch32v30x_tim.c 81KB
ch32v30x_eth.c 80KB
ch32v30x_rcc.c 44KB
ch32v30x_adc.c 38KB
ch32v30x_can.c 36KB
ch32v30x_gpio.c 31KB
ch32v30x_i2c.c 31KB
ch32v30x_dma.c 31KB
system_ch32v30x.c 29KB
ch32v30x_usart.c 28KB
ch32v30x_flash.c 27KB
ch32v30x_sdio.c 22KB
ch32v30x_spi.c 21KB
ch32v30x_fsmc.c 19KB
ch32v30x_dac.c 10KB
core_riscv.c 10KB
ch32v30x_pwr.c 9KB
ch32v30x_rtc.c 8KB
ch32v30x_bkp.c 6KB
multi_button.c 5KB
bsp_usart_it.c 5KB
debug.c 5KB
ch32v30x_exti.c 5KB
bsp_usart_idle_dma.c 5KB
ch32v30x_misc.c 5KB
bsp_time_base.c 4KB
ch32v30x_wwdg.c 4KB
ch32v30x_rng.c 4KB
ch32v30x_iwdg.c 4KB
ch32v30x_dbgmcu.c 4KB
ch32v30x_dvp.c 3KB
bsp_exit.c 3KB
bsp_gpio.c 3KB
ch32v30x_crc.c 3KB
bsp_tim_etrclock_etrpin.c 3KB
ch32v30x_opa.c 3KB
bsp_time_pwm.c 3KB
bsp_tim_etrclock_ch1ch2.c 2KB
key_input.c 2KB
main.c 1KB
ch32v30x_it.c 1KB
bsp_systick.c 1KB
.cproject 25KB
CH32V303RCT6.elf 224KB
ch32v30x.h 369KB
ch32v30x_eth.h 97KB
ch32v30x_tim.h 28KB
ch32v30x_i2c.h 21KB
ch32v30x_rcc.h 20KB
ch32v30x_can.h 20KB
core_riscv.h 17KB
ch32v30x_fsmc.h 16KB
ch32v30x_dma.h 15KB
ch32v30x_sdio.h 13KB
ch32v30x_adc.h 13KB
ch32v30x_gpio.h 11KB
ch32v30x_spi.h 10KB
ch32v30x_usart.h 10KB
ch32v30x_dac.h 8KB
ch32v30x_flash.h 8KB
ch32v30x_bkp.h 4KB
ch32v30x_exti.h 4KB
ch32v30x_pwr.h 2KB
ch32v30x_dbgmcu.h 2KB
ch32v30x_rtc.h 2KB
ch32v30x_opa.h 2KB
ch32v30x_iwdg.h 2KB
bsp_usart_it.h 2KB
ch32v30x_rng.h 2KB
ch32v30x_misc.h 2KB
ch32v30x_dvp.h 1KB
multi_button.h 1KB
ch32v30x_wwdg.h 1KB
ch32v30x_conf.h 1KB
debug.h 1KB
ch32v30x_crc.h 1KB
system_ch32v30x.h 1KB
bsp_time_base.h 844B
bsp_systick.h 841B
ch32v30x_it.h 757B
bsp_usart_idle_dma.h 660B
bsp_gpio.h 576B
bsp_tim_etrclock_etrpin.h 507B
bsp_tim_etrclock_ch1ch2.h 496B
bsp_exit.h 464B
bsp_time_pwm.h 400B
key_input.h 246B
CH32V303RCT6.hex 35KB
CH32V303RCT6.launch 6KB
Link.ld 4KB
CH32V303RCT6.lst 237KB
makefile 2KB
CH32V303RCT6.map 211KB
org.eclipse.cdt.core.prefs 14KB
org.eclipse.cdt.codan.core.prefs 13KB
org.eclipse.cdt.ui.prefs 122B
.project 1KB
startup_ch32v30x_D8C.S 16KB
startup_ch32v30x_D8.S 14KB
.template 708B
共 102 条
- 1
- 2
资源评论
Car12
- 粉丝: 2480
- 资源: 73
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功