#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的更多相关文章

  1. STM32 Timer Clock sources -- External Clock Both Edge

    Timers get their clock source from External pins or Internal timer sources. External External = pins ...

  2. 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 ...

  3. STM32F4 Timer Internal Trigger Connection

    The Timers can be cascaded to make more complex timing relationships, or longer periods. Internally ...

  4. (STM32F4) Timer 基本操作

    Timer (計時器) 就是慢慢數時間,在timer內部有一個計數器. 而計數器會數到Register的value當數值數到設定值Timer就會發起IRQ 而程式就會轉跳到中斷向量裡頭去執行想要做的事 ...

  5. (STM32F4) Timer Compare mode 操作

    Timer 比較模式(compare) 具體會用在哪種狀況目前還沒有這種經驗,但Compare有配置功能pin想必有應用會用到這個模式 從Function Block來看比較模式比基本Timer多了比 ...

  6. Software UART, Timer, PWM, External Interrupt

    How can you add extra hardware UARTs to a 32bit TMS470 ARM7-based microcontroller at zero cost? Solu ...

  7. STM32 System and Timer Clock Configurations

    STM32 System and Timer Clock Configurations I've started writing some software to drive a series of  ...

  8. 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 ...

  9. (STM32F4) Real-time Clock

    老實說Real-time Clok這項功能,我也只有在PC和手機上有見過,其他的應用產品上我也很少見到. 言歸正傳在STM32F4 RTC這項功能在IC內部就有內建,在早期的8051是如果要做RCT是 ...

随机推荐

  1. 【三分钟视频教程】iOS开发中 Xcode 报 apple-o linker 错误的#解决方案#

      [三分钟视频教程]iOS开发中 Xcode 报 apple-o linker 错误的#解决方案#   同样的道理,指向同一库文件的代码语句如果重复书写,即使重复书写所在的文件名字不同,同样会造成这 ...

  2. 【黑客免杀攻防】读书笔记10 - switch-case分支

    0x1 switch-case分支 switch-case其实就是if-else语句的另一种体现形式.但大于3之后的switchc-case.编译器会对代码进行优化. 1.1 简单switch-cas ...

  3. OpenWRT开发之——对C++的支持(解决库依赖问题)【转】

    转自:https://my.oschina.net/hevakelcj/blog/411944 摘要: 本文尝试用C++来开发一个cpp-demo包 遇到打包库依赖的问题,分析打包过程并解决了这个问题 ...

  4. 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 ...

  5. MongoDB 3.x 安装及权限验证

    1.首先在网上下载MongoDB的安装包,我这边使用的是3.2版本: 2.安装MongoDB安装程序,安装完成后设置环境变量,我这边的安装路径是:“C:\Program Files\MongoDB\S ...

  6. eclipse导入导出工作空间配置

    首先,导出T1中的配置:打开T1,选择fileExport 在弹出框中选择General 下的preferencenext在export preferences 页面选择export all, 点Br ...

  7. Project Euler Problem2

    Even Fibonacci numbers Problem 2 Each new term in the Fibonacci sequence is generated by adding the ...

  8. poj 2524 求连通分量(并查集模板题)

    求连通分量 Sample Input 10 91 21 31 41 51 61 71 81 91 1010 42 34 54 85 80 0Sample Output Case 1: 1Case 2: ...

  9. TypeScript的HTML5游戏

    wildfirecode 自动化的基于TypeScript的HTML5游戏开发 自动化的开发流程 在HTML5游戏开发或者说在Web客户端开发中,对项目代码进行修改之后,一般来说,需要手动刷新浏览器来 ...

  10. vue-element-table-js去重合并单元格解析【实战需求】

    有数据如下: { '2019-01-23': [ { 'channel': 'zp', 'listScanListNum': 24, 'listParseOkNum': 0, 'listPersonM ...