STM32F10x_StdPeriph_Examples/TIM/PWM_Input/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM/PWM_Input/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 /** @addtogroup TIM_PWM_Input
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 /* Private macro -------------------------------------------------------------*/
00035 /* Private variables ---------------------------------------------------------*/
00036 TIM_ICInitTypeDef  TIM_ICInitStructure;
00037 
00038 /* Private function prototypes -----------------------------------------------*/
00039 void RCC_Configuration(void);
00040 void GPIO_Configuration(void);
00041 void NVIC_Configuration(void);
00042 
00043 /* Private functions ---------------------------------------------------------*/
00044 
00045 /**
00046   * @brief   Main program
00047   * @param  None
00048   * @retval None
00049   */
00050 int main(void)
00051 {
00052   /*!< At this stage the microcontroller clock setting is already configured, 
00053        this is done through SystemInit() function which is called from startup
00054        file (startup_stm32f10x_xx.s) before to branch to application main.
00055        To reconfigure the default setting of SystemInit() function, refer to
00056        system_stm32f10x.c file
00057      */     
00058        
00059   /* System Clocks Configuration */
00060   RCC_Configuration();
00061 
00062   /* NVIC configuration */
00063   NVIC_Configuration();
00064 
00065   /* Configure the GPIO ports */
00066   GPIO_Configuration();
00067 
00068   /* TIM3 configuration: PWM Input mode ------------------------
00069      The external signal is connected to TIM3 CH2 pin (PA.01), 
00070      The Rising edge is used as active edge,
00071      The TIM3 CCR2 is used to compute the frequency value 
00072      The TIM3 CCR1 is used to compute the duty cycle value
00073   ------------------------------------------------------------ */
00074 
00075   TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
00076   TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
00077   TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
00078   TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
00079   TIM_ICInitStructure.TIM_ICFilter = 0x0;
00080 
00081   TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);
00082 
00083   /* Select the TIM3 Input Trigger: TI2FP2 */
00084   TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);
00085 
00086   /* Select the slave Mode: Reset Mode */
00087   TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
00088 
00089   /* Enable the Master/Slave Mode */
00090   TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
00091 
00092   /* TIM enable counter */
00093   TIM_Cmd(TIM3, ENABLE);
00094 
00095   /* Enable the CC2 Interrupt Request */
00096   TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
00097 
00098   while (1);
00099 }
00100 
00101 /**
00102   * @brief  Configures the different system clocks.
00103   * @param  None
00104   * @retval None
00105   */
00106 void RCC_Configuration(void)
00107 {
00108   /* TIM3 clock enable */
00109   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
00110 
00111   /* GPIOA clock enable */
00112   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
00113 }
00114 
00115 /**
00116   * @brief  Configure the GPIOD Pins.
00117   * @param  None
00118   * @retval None
00119   */
00120 void GPIO_Configuration(void)
00121 {
00122   GPIO_InitTypeDef GPIO_InitStructure;
00123 
00124   /* TIM3 channel 2 pin (PA.07) configuration */
00125   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
00126   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00127   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00128 
00129   GPIO_Init(GPIOA, &GPIO_InitStructure);
00130 }
00131 
00132 /**
00133   * @brief  Configure the nested vectored interrupt controller.
00134   * @param  None
00135   * @retval None
00136   */
00137 void NVIC_Configuration(void)
00138 {
00139   NVIC_InitTypeDef NVIC_InitStructure;
00140 
00141   /* Enable the TIM3 global Interrupt */
00142   NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
00143   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00144   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
00145   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00146   NVIC_Init(&NVIC_InitStructure);
00147 }
00148 
00149 #ifdef  USE_FULL_ASSERT
00150 
00151 /**
00152   * @brief  Reports the name of the source file and the source line number
00153   *         where the assert_param error has occurred.
00154   * @param  file: pointer to the source file name
00155   * @param  line: assert_param error line source number
00156   * @retval None
00157   */
00158 void assert_failed(uint8_t* file, uint32_t line)
00159 {
00160   /* User can add his own implementation to report the file name and line number,
00161      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00162 
00163   while (1)
00164   {}
00165 }
00166 #endif
00167 
00168 /**
00169   * @}
00170   */ 
00171 
00172 /**
00173   * @}
00174   */ 
00175 
00176 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32