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

STM8S/A

STM8S_StdPeriph_Examples/TIM1/TIM1_6Steps/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM1_6Steps\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 6 Steps 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_6Steps
00033   * @{
00034   */
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private define ------------------------------------------------------------*/
00038 /* Private macro -------------------------------------------------------------*/
00039 /* Private variables ---------------------------------------------------------*/
00040 /* Private function prototypes -----------------------------------------------*/
00041 static void TIM1_Config(void);
00042 static void TIM4_Config(void);
00043 /* Private functions ---------------------------------------------------------*/
00044 /* Public functions ----------------------------------------------------------*/
00045 
00046 /**
00047   * @brief  Main program.
00048   * @param  None
00049   * @retval None
00050   */
00051 void main(void)
00052 {
00053   /* TIM1 configuration -----------------------------------------*/
00054     TIM1_Config();
00055     
00056   /* TIM4 configuration -----------------------------------------*/
00057     TIM4_Config();
00058    
00059   /* Main Output Enable */
00060   TIM1_CtrlPWMOutputs(ENABLE);
00061   
00062   enableInterrupts();
00063   
00064   while (1)
00065   {} 
00066 }
00067 
00068 /**
00069   * @brief  Configure TIM1 to generate 6 Steps PWM signal
00070   * @param  None
00071   * @retval None
00072   */
00073 static void TIM1_Config(void)
00074 {
00075   /* TIM1 Peripheral Configuration */ 
00076   TIM1_DeInit();
00077 
00078   /* Time Base configuration */
00079   TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0);
00080 
00081   /* Channel 1, 2 and 3 Configuration in TIMING mode */  
00082   
00083   /* TIM1_Pulse = 2047 */
00084   TIM1_OC1Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
00085                2047, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
00086                TIM1_OCNIDLESTATE_SET);  
00087 
00088   /* TIM1_Pulse = 1023 */
00089   TIM1_OC2Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 1023,
00090                TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, 
00091                TIM1_OCNIDLESTATE_SET); 
00092 
00093   /* TIM1_Pulse = 511 */
00094   TIM1_OC3Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
00095                511, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
00096                TIM1_OCNIDLESTATE_SET); 
00097 
00098   /* Automatic Output enable, Break, dead time and lock configuration*/
00099   TIM1_BDTRConfig( TIM1_OSSISTATE_ENABLE,  TIM1_LOCKLEVEL_OFF, 1,  TIM1_BREAK_DISABLE,
00100                    TIM1_BREAKPOLARITY_LOW,  TIM1_AUTOMATICOUTPUT_ENABLE);
00101   TIM1_CCPreloadControl(ENABLE);
00102   TIM1_ITConfig(TIM1_IT_COM, ENABLE);
00103 
00104   /* TIM1 counter enable */
00105   TIM1_Cmd(ENABLE);
00106 }
00107 
00108 /**
00109   * @brief  Configure TIM4 to generate a software COM event each 180 ms
00110   * @param  None
00111   * @retval None
00112   */
00113 static void TIM4_Config(void)
00114 {
00115   /* TIM4 Peripheral Configuration */ 
00116   /* Time Base configuration */
00117   TIM4_TimeBaseInit(TIM4_PRESCALER_128, 0xFF);
00118   
00119   /*TIM4 counter enable */
00120   TIM4_Cmd(ENABLE);
00121   
00122   TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
00123 }
00124 
00125 #ifdef USE_FULL_ASSERT
00126 
00127 /**
00128   * @brief  Reports the name of the source file and the source line number
00129   *   where the assert_param error has occurred.
00130   * @param file: pointer to the source file name
00131   * @param line: assert_param error line source number
00132   * @retval None
00133   */
00134 void assert_failed(uint8_t* file, uint32_t line)
00135 { 
00136   /* User can add his own implementation to report the file name and line number,
00137      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00138 
00139   /* Infinite loop */
00140   while (1)
00141   {
00142   }
00143 }
00144 #endif
00145 
00146 /**
00147   * @}
00148   */
00149 
00150 
00151 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

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