STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/TIM1/TIM1_ComplementarySignals_DeadTime_Break_Lock/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file TIM1_ComplementarySignals_DeadTime_Break_Lock\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 Complementary Signals & 00008 * DeadTime & Break & Lock. 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 TIM1_ComplementarySignals_DeadTime_Break_Lock 00034 * @{ 00035 */ 00036 00037 /* Private typedef -----------------------------------------------------------*/ 00038 00039 /* Private define ------------------------------------------------------------*/ 00040 #define CCR1_Val ((uint16_t)32767) 00041 #define CCR2_Val ((uint16_t)16383) 00042 #define CCR3_Val ((uint16_t)8191) 00043 /* Private macro -------------------------------------------------------------*/ 00044 /* Private variables ---------------------------------------------------------*/ 00045 /* Private function prototypes -----------------------------------------------*/ 00046 static void TIM1_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 /* TIM1 configuration -----------------------------------------*/ 00058 TIM1_Config(); 00059 00060 while (1) 00061 {} 00062 } 00063 00064 /** 00065 * @brief Configure TIM1 to generate 3 complementary signals, to insert a 00066 * defined dead time value, to use the break feature and to lock the 00067 * desired parameters 00068 * @param None 00069 * @retval None 00070 */ 00071 static void TIM1_Config(void) 00072 { 00073 /* TIM1 Peripheral Configuration */ 00074 TIM1_DeInit(); 00075 00076 /* Time Base configuration */ 00077 /* 00078 TIM1_Prescaler = 0 00079 TIM1_CounterMode = TIM1_COUNTERMODE_UP 00080 TIM1_Period = 65535 00081 TIM1_RepetitionCounter = 0 00082 */ 00083 00084 TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 65535,0); 00085 00086 /* Channel 1, 2 and 3 Configuration in PWM mode */ 00087 /* 00088 TIM1_OCMode = TIM1_OCMODE_PWM2 00089 TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE 00090 TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE 00091 TIM1_Pulse = CCR1_Val 00092 TIM1_OCPolarity = TIM1_OCPOLARITY_LOW 00093 TIM1_OCNPolarity = TIM1_OCNPOLARITY_LOW 00094 TIM1_OCIdleState = TIM1_OCIDLESTATE_SET 00095 TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET 00096 */ 00097 TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 00098 CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, 00099 TIM1_OCNIDLESTATE_RESET); 00100 00101 /* TIM1_Pulse = CCR2_Val */ 00102 TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 00103 CCR2_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, 00104 TIM1_OCNIDLESTATE_RESET); 00105 00106 /* TIM1_Pulse = CCR3_Val */ 00107 TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 00108 CCR3_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, 00109 TIM1_OCNIDLESTATE_RESET); 00110 00111 /* Automatic Output enable, Break, dead time and lock configuration */ 00112 /* 00113 TIM1_OSSIState = TIM1_OSSISTATE_ENABLE 00114 TIM1_LockLevel = TIM1_LOCKLEVEL_1 00115 TIM1_DeadTime = 117 00116 TIM1_Break = TIM1_BREAK_ENABLE 00117 TIM1_BreakPolarity = TIM1_BREAKPOLARITY_HIGH 00118 TIM1_AutomaticOutput = TIM1_AUTOMATICOUTPUT_ENABLE 00119 */ 00120 TIM1_BDTRConfig( TIM1_OSSISTATE_ENABLE, TIM1_LOCKLEVEL_1, 117, TIM1_BREAK_ENABLE, 00121 TIM1_BREAKPOLARITY_HIGH, TIM1_AUTOMATICOUTPUT_ENABLE); 00122 00123 /* TIM1 counter enable */ 00124 TIM1_Cmd(ENABLE); 00125 00126 /* Main Output Enable */ 00127 TIM1_CtrlPWMOutputs(ENABLE); 00128 } 00129 00130 #ifdef USE_FULL_ASSERT 00131 00132 /** 00133 * @brief Reports the name of the source file and the source line number 00134 * where the assert_param error has occurred. 00135 * @param file: pointer to the source file name 00136 * @param line: assert_param error line source number 00137 * @retval None 00138 */ 00139 void assert_failed(uint8_t* file, uint32_t line) 00140 { 00141 /* User can add his own implementation to report the file name and line number, 00142 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00143 00144 /* Infinite loop */ 00145 while (1) 00146 { 00147 } 00148 } 00149 #endif 00150 00151 /** 00152 * @} 00153 */ 00154 00155 00156 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/