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

STM8S/A

STM8S_StdPeriph_Examples/TIM1/TIM1_7PWM_Output/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file TIM1_7PWM_Output\main.c
00004   * @brief This file contains the main function for TIM1 7 PWM Output example.
00005   * @author  MCD Application Team
00006   * @version  V2.2.0
00007   * @date     30-September-2014
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_7PWM_Output
00033   * @{
00034   */
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 
00038 /* Private define ------------------------------------------------------------*/
00039 #define CCR1_Val  ((uint16_t)2047)
00040 #define CCR2_Val  ((uint16_t)1535)
00041 #define CCR3_Val  ((uint16_t)1023)
00042 #define CCR4_Val  ((uint16_t)511)
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 7 PWM signals with 4 different duty cycles
00066   * @param  None
00067   * @retval None
00068   */
00069 static void TIM1_Config(void)
00070 {
00071 
00072    TIM1_DeInit();
00073 
00074   /* Time Base configuration */
00075   /*
00076   TIM1_Period = 4095
00077   TIM1_Prescaler = 0
00078   TIM1_CounterMode = TIM1_COUNTERMODE_UP
00079   TIM1_RepetitionCounter = 0
00080   */
00081 
00082   TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0);
00083 
00084   /* Channel 1, 2,3 and 4 Configuration in PWM mode */
00085   
00086   /*
00087   TIM1_OCMode = TIM1_OCMODE_PWM2
00088   TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
00089   TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
00090   TIM1_Pulse = CCR1_Val
00091   TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
00092   TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
00093   TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
00094   TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
00095   
00096   */
00097   TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
00098                CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, 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, CCR2_Val,
00103                TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, 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_HIGH, TIM1_OCIDLESTATE_SET,
00109                TIM1_OCNIDLESTATE_RESET);
00110 
00111   /*TIM1_Pulse = CCR4_Val*/
00112   TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, CCR4_Val, TIM1_OCPOLARITY_LOW,
00113                TIM1_OCIDLESTATE_SET);
00114 
00115   /* TIM1 counter enable */
00116   TIM1_Cmd(ENABLE);
00117 
00118   /* TIM1 Main Output Enable */
00119   TIM1_CtrlPWMOutputs(ENABLE);
00120 }
00121 
00122 #ifdef USE_FULL_ASSERT
00123 
00124 /**
00125   * @brief  Reports the name of the source file and the source line number
00126   *   where the assert_param error has occurred.
00127   * @param file: pointer to the source file name
00128   * @param line: assert_param error line source number
00129   * @retval None
00130   */
00131 void assert_failed(uint8_t* file, uint32_t line)
00132 { 
00133   /* User can add his own implementation to report the file name and line number,
00134      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00135 
00136   /* Infinite loop */
00137   while (1)
00138   {
00139   }
00140 }
00141 #endif
00142 
00143 /**
00144   * @}
00145   */
00146 
00147 
00148 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

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