STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/TIM2/TIM2_PWM_DutyCycleConfiguration/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file TIM2_PWM_DutyCycleConfiguration\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 PWM_DutyCycleConfiguration 00008 * example. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00013 * 00014 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00015 * You may not use this file except in compliance with the License. 00016 * You may obtain a copy of the License at: 00017 * 00018 * http://www.st.com/software_license_agreement_liberty_v2 00019 * 00020 * Unless required by applicable law or agreed to in writing, software 00021 * distributed under the License is distributed on an "AS IS" BASIS, 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00023 * See the License for the specific language governing permissions and 00024 * limitations under the License. 00025 * 00026 ****************************************************************************** 00027 */ 00028 00029 /* Includes ------------------------------------------------------------------*/ 00030 #include "stm8s.h" 00031 00032 /** 00033 * @addtogroup TIM2_PWM_DutyCycleConfiguration 00034 * @{ 00035 */ 00036 00037 /* Private typedef -----------------------------------------------------------*/ 00038 /* Private define ------------------------------------------------------------*/ 00039 /* Private macro -------------------------------------------------------------*/ 00040 /* Private variables ---------------------------------------------------------*/ 00041 uint16_t CCR1_Val = 500; 00042 uint16_t CCR2_Val = 250; 00043 uint16_t CCR3_Val = 125; 00044 00045 /* Private function prototypes -----------------------------------------------*/ 00046 static void TIM2_Config(void); 00047 /* Private functions ---------------------------------------------------------*/ 00048 /* Public functions ----------------------------------------------------------*/ 00049 00050 /** 00051 * @brief Main program. 00052 * @param None 00053 * @retval None 00054 */ 00055 void main(void) 00056 { 00057 /* TIM2 configuration -----------------------------------------*/ 00058 TIM2_Config(); 00059 00060 while (1) 00061 {} 00062 } 00063 00064 /** 00065 * @brief Configure TIM2 peripheral in PWM mode 00066 * @param None 00067 * @retval None 00068 */ 00069 static void TIM2_Config(void) 00070 { 00071 /* Time base configuration */ 00072 TIM2_TimeBaseInit(TIM2_PRESCALER_1, 999); 00073 00074 /* PWM1 Mode configuration: Channel1 */ 00075 TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH); 00076 TIM2_OC1PreloadConfig(ENABLE); 00077 00078 /* PWM1 Mode configuration: Channel2 */ 00079 TIM2_OC2Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH); 00080 TIM2_OC2PreloadConfig(ENABLE); 00081 00082 /* PWM1 Mode configuration: Channel3 */ 00083 TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH); 00084 TIM2_OC3PreloadConfig(ENABLE); 00085 00086 TIM2_ARRPreloadConfig(ENABLE); 00087 00088 /* TIM2 enable counter */ 00089 TIM2_Cmd(ENABLE); 00090 } 00091 00092 #ifdef USE_FULL_ASSERT 00093 00094 /** 00095 * @brief Reports the name of the source file and the source line number 00096 * where the assert_param error has occurred. 00097 * @param file: pointer to the source file name 00098 * @param line: assert_param error line source number 00099 * @retval None 00100 */ 00101 void assert_failed(uint8_t* file, uint32_t line) 00102 { 00103 /* User can add his own implementation to report the file name and line number, 00104 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00105 00106 /* Infinite loop */ 00107 while (1) 00108 { 00109 } 00110 } 00111 #endif 00112 00113 /** 00114 * @} 00115 */ 00116 00117 00118 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/