#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. <dl>

    定义列表 自定义列表不仅仅是一列项目,而是项目及其注释的组合. 自定义列表以 <dl> 标签开始.每个自定义列表项以 <dt> 开始.每个自定义列表项的定义以 <dd&g ...

  2. 云计算--hdfs dfs 命令

    在hadoop安装目录下:/hadoop2/hadoop-2.7.3 1.创建目录 bin/hdfs dfs -mkdir /user bin/hdfs dfs -mkdir /user/<us ...

  3. Update Bits

    Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits be ...

  4. 编程入门python之定义函数【转】

    编程入门python之定义函数 零基础学编程by学哥 2017-02-06 10:51 今天讲python函数. 输入参数求三角形或圆形或长方形的面积 先输入1个参数:形状类型 1=三角形 2=圆形 ...

  5. [cookie篇]cookie-parser之parser.js

    cookie-parser的作用,官方的说法是:Parse Cookie header and populate req.cookies with an object keyed by the coo ...

  6. Spring bean 配置

    1.传统的创建对象的方式:JedisMall tardition=new JedisMall(); 这样是在程序运行时创建,表示当前模块已经不知不觉和new出的对象耦合了,而我们通常都是更高层次的抽象 ...

  7. Extjs Window用法详解 2 打印具体应用

    Extjs 中的按钮元素 { xtype: 'buttongroup', title: '打印', items: [ me.tsbDel = Ext.create('Ext.button.Button ...

  8. POJ 1948 Triangular Pastures

    题意: 把很多单独的线段重新组合成一个三角形,使得三角形面积最大(所有的线段都必须用上). 思路: 三角形的任意一条边的边长不能超过周长的一半,只需要用dp枚举两条边j,k,剩下的一条边长为tot  ...

  9. 移动端经常出现的兼容问题,谈谈移动端应用或者wap站的一些优化技巧和心得

    移动端经常出现的兼容问题,谈谈移动端应用或者wap站的一些优化技巧和心得 1.        安卓浏览器看背景图片,有些设备会模糊. 因为手机分辨率太小,如果按照分辨率来显示网页,字会非常小,安卓手机 ...

  10. HTML布局思路

    1.DIV+CSS布局 (1)按照由上到下,由里到外的方式 (2)样式由CSS去改变 代码: <style type="text/css"> * { margin:0p ...