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

STM8S/A

STM8S_StdPeriph_Examples/TIM2/TIM2_OC_ActiveMode/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM2_OC_ActiveMode\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 TIM2 OC ActiveMode 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 TIM2_OC_ActiveMode
00033   * @{
00034   */
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private define ------------------------------------------------------------*/
00038 #define CCR1_Val  ((uint16_t)976)
00039 #define CCR2_Val  ((uint16_t)488)
00040 #define CCR3_Val  ((uint16_t)244)
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 /* Private function prototypes -----------------------------------------------*/
00044 static void GPIO_Config(void);
00045 static void TIM2_Config(void);
00046 /* Private functions ---------------------------------------------------------*/
00047 /* Public functions ----------------------------------------------------------*/
00048 
00049 /**
00050   * @brief  Main program.
00051   * @param  None
00052   * @retval None
00053   */
00054 void main(void)
00055 {
00056   /* GPIO configuration -----------------------------------------*/
00057   GPIO_Config();  
00058 
00059   /* TIM2 configuration -----------------------------------------*/
00060   TIM2_Config();  
00061   
00062 
00063   while (1)
00064   {} 
00065 }
00066 
00067 /**
00068   * @brief  Configure PG6 to allow delay of TIM2 channels computation
00069   * @param  None
00070   * @retval None
00071   */
00072 static void GPIO_Config(void)
00073 {
00074   /* Set PG.6 pin */
00075   GPIO_Init(GPIOG, GPIO_PIN_6, GPIO_MODE_OUT_PP_LOW_FAST);
00076   GPIO_WriteHigh(GPIOG, GPIO_PIN_6);
00077 }
00078 
00079 /**
00080   * @brief  Configure TIM2 peripheral to generate 3 different signals with 3
00081   *         different delays
00082   * @param  None
00083   * @retval None
00084   */
00085 static void TIM2_Config(void)
00086 {
00087   /* Time base configuration */      
00088   TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 65535);
00089 
00090   /* Prescaler configuration */
00091   TIM2_PrescalerConfig(TIM2_PRESCALER_2048, TIM2_PSCRELOADMODE_IMMEDIATE);
00092 
00093   /* Output Compare Active Mode configuration: Channel1 */
00094   /*
00095     TIM2_OCMode = TIM2_OCMODE_ACTIVE
00096     TIM2_OutputState = TIM2_OUTPUTSTATE_ENABLE
00097     TIM2_Pulse = CCR1_Val
00098     TIM2_OCPolarity = TIM2_OCPOLARITY_HIGH
00099   */
00100   TIM2_OC1Init(TIM2_OCMODE_ACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH);
00101   
00102   TIM2_OC1PreloadConfig(DISABLE);
00103 
00104   /* Output Compare Active Mode configuration: Channel2 */
00105   
00106   /*TIM2_Pulse = CCR2_Val  */
00107   
00108   TIM2_OC2Init(TIM2_OCMODE_ACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH); 
00109   TIM2_OC2PreloadConfig(DISABLE);
00110 
00111   /* Output Compare Active Mode configuration: Channel3 */
00112   /*
00113   TIM2_Pulse = CCR3_Val
00114   */
00115   TIM2_OC3Init(TIM2_OCMODE_ACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH);
00116   TIM2_OC3PreloadConfig(DISABLE);
00117   TIM2_ARRPreloadConfig(ENABLE);
00118   
00119   /* TIM2 enable counter */
00120   TIM2_Cmd(ENABLE);
00121 }
00122 
00123 #ifdef USE_FULL_ASSERT
00124 
00125 /**
00126   * @brief  Reports the name of the source file and the source line number
00127   *   where the assert_param error has occurred.
00128   * @param file: pointer to the source file name
00129   * @param line: assert_param error line source number
00130   * @retval None
00131   */
00132 void assert_failed(uint8_t* file, uint32_t line)
00133 { 
00134   /* User can add his own implementation to report the file name and line number,
00135      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00136 
00137   /* Infinite loop */
00138   while (1)
00139   {
00140   }
00141 }
00142 #endif
00143 
00144 /**
00145   * @}
00146   */
00147 
00148 
00149 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

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