STM32F4 Timer External Clock TI2 Both Edges Demo
#define CLK_FREQ ( 10000 )
#define CORE_FREQ ( 168000000 ) static void TIM_GPIO_Config( void )
{
GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIOA clock
__HAL_RCC_GPIOA_CLK_ENABLE( ); // Configure PA8 pin as CLK output -- to CK Input
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = GPIO_PIN_8;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Alternate = GPIO_AF1_TIM1; HAL_GPIO_Init( GPIOA, &GPIO_InitStructure ); // Enable GPIOC clock
__HAL_RCC_GPIOC_CLK_ENABLE( ); // Configure PC7 pin as CK input -- from CLK Output
// Can not uses GPIO_MODE_INPUT : AF = 0
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; // AF = 3
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = GPIO_PIN_7;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Alternate = GPIO_AF3_TIM8;
HAL_GPIO_Init( GPIOC, &GPIO_InitStructure ); // Configure PC6 pin as CK output -- to Oscilloscope Display
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = GPIO_PIN_6;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Alternate = GPIO_AF3_TIM8;
HAL_GPIO_Init( GPIOC, &GPIO_InitStructure );
} TIM_HandleTypeDef TimHandle;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_SlaveConfigTypeDef sSlaveConfig; TIM_OC_InitTypeDef sConfig; static void Error_Handler( void )
{
while ( )
{
}
} void TIM_CLK_Output( void )
{
__HAL_RCC_TIM1_CLK_ENABLE( )
; TimHandle.Instance = TIM1; TimHandle.Init.Period = ;
TimHandle.Init.Prescaler = CORE_FREQ / CLK_FREQ - ;
TimHandle.Init.ClockDivision = ;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if ( HAL_TIM_PWM_Init( &TimHandle ) != HAL_OK )
Error_Handler( ); sConfig.OCMode = TIM_OCMODE_PWM1;
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
sConfig.Pulse = ;
if ( HAL_TIM_PWM_ConfigChannel( &TimHandle, &sConfig, TIM_CHANNEL_1 ) != HAL_OK )
Error_Handler( ); if ( HAL_TIM_PWM_Start( &TimHandle, TIM_CHANNEL_1 ) != HAL_OK )
Error_Handler( );
} void TIM_CK_Input( void )
{
__HAL_RCC_TIM8_CLK_ENABLE( ); TimHandle.Instance = TIM8; TIM_IC_InitTypeDef IC_InitTypeDef;
IC_InitTypeDef.ICFilter = ;
IC_InitTypeDef.ICPolarity = TIM_ICPOLARITY_BOTHEDGE;
IC_InitTypeDef.ICPrescaler = TIM_ICPSC_DIV1;
IC_InitTypeDef.ICSelection = TIM_ICSELECTION_DIRECTTI; // TIM8_CH2 : PC7
HAL_TIM_IC_ConfigChannel( &TimHandle, &IC_InitTypeDef, TIM_CHANNEL_2 ); TIM_ClockConfigTypeDef ClockConfig;
ClockConfig.ClockFilter = ;
ClockConfig.ClockPolarity = TIM_CLOCKPOLARITY_BOTHEDGE;
ClockConfig.ClockPrescaler = TIM_CLOCKPRESCALER_DIV1;
ClockConfig.ClockSource = TIM_CLOCKSOURCE_TI2; // TIM8_CH2 : PC7
HAL_TIM_ConfigClockSource( &TimHandle, &ClockConfig ); TimHandle.Init.Period = ;
TimHandle.Init.Prescaler = ;
TimHandle.Init.ClockDivision = ;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if ( HAL_TIM_Base_Init( &TimHandle ) != HAL_OK )
Error_Handler( ); if ( HAL_TIM_Base_Start( &TimHandle ) != HAL_OK )
Error_Handler( );
} void TIM_CK_Output( void )
{
TimHandle.Instance = TIM8; sConfig.OCMode = TIM_OCMODE_PWM1;
sConfig.OCPolarity = TIM_OCPOLARITY_LOW; // Inverted CK_Input
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
sConfig.Pulse = ;
if ( HAL_TIM_PWM_ConfigChannel( &TimHandle, &sConfig, TIM_CHANNEL_1 ) != HAL_OK )
Error_Handler( ); if ( HAL_TIM_PWM_Start( &TimHandle, TIM_CHANNEL_1 ) != HAL_OK )
Error_Handler( );
} void Timer_Demo( void )
{
TIM_GPIO_Config( );
TIM_CLK_Output( ); // To CK_Input 5 KHz
TIM_CK_Input( ); // From CLK_Output 5 KHz
TIM_CK_Output( ); // PWM Output 5 KHz -- Inverted CL_Output with Delay while ( )
{
}
}
STM32F4 Timer External Clock TI2 Both Edges Demo的更多相关文章
- STM32 Timer Clock sources -- External Clock Both Edge
Timers get their clock source from External pins or Internal timer sources. External External = pins ...
- STM32F4 Timer simplified block diagram
Timers TIM1 and TIM8 use 16-bit counters and are the most complex timers of all timers included in t ...
- STM32F4 Timer Internal Trigger Connection
The Timers can be cascaded to make more complex timing relationships, or longer periods. Internally ...
- (STM32F4) Timer 基本操作
Timer (計時器) 就是慢慢數時間,在timer內部有一個計數器. 而計數器會數到Register的value當數值數到設定值Timer就會發起IRQ 而程式就會轉跳到中斷向量裡頭去執行想要做的事 ...
- (STM32F4) Timer Compare mode 操作
Timer 比較模式(compare) 具體會用在哪種狀況目前還沒有這種經驗,但Compare有配置功能pin想必有應用會用到這個模式 從Function Block來看比較模式比基本Timer多了比 ...
- Software UART, Timer, PWM, External Interrupt
How can you add extra hardware UARTs to a 32bit TMS470 ARM7-based microcontroller at zero cost? Solu ...
- STM32 System and Timer Clock Configurations
STM32 System and Timer Clock Configurations I've started writing some software to drive a series of ...
- Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock
Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock This is about timer in D2k An externa ...
- (STM32F4) Real-time Clock
老實說Real-time Clok這項功能,我也只有在PC和手機上有見過,其他的應用產品上我也很少見到. 言歸正傳在STM32F4 RTC這項功能在IC內部就有內建,在早期的8051是如果要做RCT是 ...
随机推荐
- Linux学习7-文件操作
标准I/O库(stdio)及其头文件stdio.h 为底层I/O系统调用提供了一个通用的接口. 在标准I/O库中,与底层文件描述符对应的是流(stream),它被实现为指向结构FILE的指针. 在启动 ...
- 第10月第21天 手势识别 开屏广告 Xcode快捷键
1.手势识别 http://yulingtianxia.com/blog/2016/12/29/Multimedia-Edit-Module-Architecture-Design/ 2.开屏广告 h ...
- Zookeeper笔记之基于zk的分布式配置中心
一.场景 & 需求 集群上有很多个节点运行同一个任务,这个任务会有一些可能经常改变的配置参数,要求是当配置参数改变之后能够很快地同步到每个节点上,如果将这些配置参数放在本地文件中则每次都要修改 ...
- mybatis输入输出映射——(五)
0.#{}与${}区别 #{}实现的是向prepareStatement中的预处理语句中设置参数值,sql语句中#{}表示一个占位符即?. <!-- 根据id查询用户信息 --> < ...
- how-to-pass-a-class-variable-to-a-decorator-inside-class-definition
https://stackoverflow.com/questions/17522706/how-to-pass-a-class-variable-to-a-decorator-inside-clas ...
- C++ 螺旋矩阵算法
清理磁盘空间的时候翻出了多年前写过的螺旋矩阵,代码效率和水平较低,纪念一下,保存到博客园! // ConsoleApplication3.cpp : 定义控制台应用程序的入口点. // #includ ...
- redis,nodejs,php,pub/sub 实战: 微信语音识别
2015年5月22日 20:20:20 星期五 效果: 这边对微信说话, 浏览器端及时显示语音识别的文字 注意: 在连接socket.io时, 按下浏览器f12, 如果一直有请求不断的刷, 说明so ...
- Android WebView 详解
相关API 相关类介绍 WebResourceRequest 添加于API21,封装了一个Web资源的请求信息,包含:请求地址,请求方法,请求头,是否主框架,是否用户点击,是否重定向 WebResou ...
- ajax最基础入门
1.介绍 AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重 ...
- Linux学习笔记:sed删除、插入数据
一.sed删除文件第一行 sed -i '1d' file.txt -- 删除第一行 sed -i 'nd' file.txt -- 删除第n行 sed -i '$d' file.txt -- 删除最 ...