STM8S/A Standard Peripherals Firmware Library: main.c Source File

STM8S/A

STM8S_StdPeriph_Examples/TIM1/TIM1_Input_Capture/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file     TIM1_Input_Capture\main.c
00004   * @author   MCD Application Team
00005   * @version  V2.2.0
00006   * @date     30-September-2014
00007   * @brief    This file contains the main function for TIM1 Input Capture example.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */ 
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm8s.h"
00030 
00031 /**
00032   * @addtogroup TIM1_Input_Capture
00033   * @{
00034   */
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private define ------------------------------------------------------------*/
00038 /* Private macro -------------------------------------------------------------*/
00039 /* Private variables ---------------------------------------------------------*/
00040 uint32_t TIM1ClockFreq = 2000000;
00041 __IO uint32_t LSIClockFreq = 0;
00042 uint16_t ICValue1 =0, ICValue2 =0;
00043 /* Private function prototypes -----------------------------------------------*/
00044 static void TIM1_Config(void);
00045 /* Private functions ---------------------------------------------------------*/
00046 /* Public functions ----------------------------------------------------------*/
00047 
00048 /**
00049   * @brief  Main program.
00050   * @param  None
00051   * @retval None
00052   */
00053 void main(void)
00054 {
00055 
00056   /* Connect LSI to COO pin*/
00057   GPIO_Init(GPIOE, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
00058   CLK_CCOConfig(CLK_OUTPUT_LSI);
00059   CLK_CCOCmd(ENABLE);
00060 
00061   /* TIM1 configuration -----------------------------------------*/
00062   TIM1_Config();
00063     
00064   /* Compute LSI clock frequency */
00065   LSIClockFreq = (8 * TIM1ClockFreq) / (ICValue2 - ICValue1);
00066   
00067   /* Insert a break point here */
00068   while (1)
00069   {}
00070 }
00071 
00072 /**
00073   * @brief  Configure TIM1 to to capture the internal clock source (LSI)
00074   * @param  None
00075   * @retval None
00076   */
00077 static void TIM1_Config(void)
00078 {
00079   TIM1_ICInit( TIM1_CHANNEL_1, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI,
00080                TIM1_ICPSC_DIV8, 0x0);
00081   
00082   /* Enable TIM1 */
00083   TIM1_Cmd(ENABLE);
00084 
00085   /* Clear CC1 Flag*/
00086   TIM1_ClearFlag(TIM1_FLAG_CC1);
00087   
00088   /* wait a capture on CC1 */
00089   while((TIM1->SR1 & TIM1_FLAG_CC1) != TIM1_FLAG_CC1);
00090   /* Get CCR1 value*/
00091   ICValue1 = TIM1_GetCapture1();
00092   TIM1_ClearFlag(TIM1_FLAG_CC1);
00093   
00094   /* wait a capture on cc1 */
00095   while((TIM1->SR1 & TIM1_FLAG_CC1) != TIM1_FLAG_CC1);
00096   /* Get CCR1 value*/
00097   ICValue2 = TIM1_GetCapture1();
00098   TIM1_ClearFlag(TIM1_FLAG_CC1);
00099 }
00100 
00101 #ifdef USE_FULL_ASSERT
00102 
00103 /**
00104   * @brief  Reports the name of the source file and the source line number
00105   *   where the assert_param error has occurred.
00106   * @param file: pointer to the source file name
00107   * @param line: assert_param error line source number
00108   * @retval None
00109   */
00110 void assert_failed(uint8_t* file, uint32_t line)
00111 { 
00112   /* User can add his own implementation to report the file name and line number,
00113      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00114 
00115   /* Infinite loop */
00116   while (1)
00117   {
00118   }
00119 }
00120 #endif
00121 
00122 /**
00123   * @}
00124   */
00125 
00126 
00127 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com