STM32F10x_StdPeriph_Examples/TIM/TIM15_ComplementarySignals/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM/TIM15_ComplementarySignals/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 /** @addtogroup TIM15_ComplementarySignals
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 /* Private macro -------------------------------------------------------------*/
00035 /* Private variables ---------------------------------------------------------*/
00036 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
00037 TIM_OCInitTypeDef  TIM_OCInitStructure;
00038 TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
00039 uint16_t CCR1_Val = 32767;
00040 
00041 /* Private function prototypes -----------------------------------------------*/
00042 void RCC_Configuration(void);
00043 void GPIO_Configuration(void);
00044 
00045 /* Private functions ---------------------------------------------------------*/
00046 
00047 /**
00048   * @brief   Main program
00049   * @param  None
00050   * @retval None
00051   */
00052 int main(void)
00053 {
00054   /*!< At this stage the microcontroller clock setting is already configured, 
00055        this is done through SystemInit() function which is called from startup
00056        file (startup_stm32f10x_xx.s) before to branch to application main.
00057        To reconfigure the default setting of SystemInit() function, refer to
00058        system_stm32f10x.c file
00059      */     
00060        
00061   /* System Clocks Configuration */
00062   RCC_Configuration();
00063 
00064   /* GPIO Configuration */
00065   GPIO_Configuration();
00066 
00067   /* -----------------------------------------------------------------------
00068   TIM15 Configuration to:
00069 
00070   1/ Generate a complementary PWM signals with 50% duty cycles:
00071   TIM15CLK = 24 MHz, Prescaler = 0, TIM15 counter clock = 24 MHz
00072   TIM15 frequency = TIM15CLK/(TIM15_Period + 1) = 366 Hz
00073 
00074   TIM15 Channel1 duty cycle = TIM15->CCR1 / TIM15_Period = 50% 
00075   TIM15 Channel1N duty cycle = (TIM15_Period - TIM15_CCR1) / (TIM15_Period + 1) = 50%
00076 
00077   2/ Insert a dead time equal to 1.62 us
00078   3/ Configure the break feature, active at High level, and using the automatic 
00079      output enable feature
00080   4/ Use the Locking parametres level1. 
00081   ----------------------------------------------------------------------- */
00082 
00083   /* Time Base configuration */
00084   TIM_TimeBaseStructure.TIM_Prescaler = 0;
00085   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
00086   TIM_TimeBaseStructure.TIM_Period = 65535;
00087   TIM_TimeBaseStructure.TIM_ClockDivision = 0;
00088   TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
00089 
00090   TIM_TimeBaseInit(TIM15, &TIM_TimeBaseStructure);
00091 
00092   /* Channel 1 Configuration in PWM mode */
00093   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
00094   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
00095   TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
00096   TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
00097   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
00098   TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
00099   TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
00100   TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
00101 
00102   TIM_OC1Init(TIM15, &TIM_OCInitStructure);
00103 
00104   /* Automatic Output enable, Break, dead time and lock configuration*/
00105   TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
00106   TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
00107   TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
00108   TIM_BDTRInitStructure.TIM_DeadTime = 39;
00109   TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
00110   TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
00111   TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
00112 
00113   TIM_BDTRConfig(TIM15, &TIM_BDTRInitStructure);
00114 
00115   /* TIM15 counter enable */
00116   TIM_Cmd(TIM15, ENABLE);
00117 
00118   /* Main Output Enable */
00119   TIM_CtrlPWMOutputs(TIM15, ENABLE);
00120 
00121   while (1)
00122   {
00123   }
00124 }
00125 
00126 /**
00127   * @brief  Configures the different system clocks.
00128   * @param  None
00129   * @retval None
00130   */
00131 void RCC_Configuration(void)
00132 {
00133   /* TIM15, GPIOA, GPIOB and AFIO clocks enable */
00134   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB 
00135                          | RCC_APB2Periph_AFIO, ENABLE);
00136 }
00137 
00138 /**
00139   * @brief  Configure the TIM1 Pins.
00140   * @param  None
00141   * @retval None
00142   */
00143 void GPIO_Configuration(void)
00144 {
00145   GPIO_InitTypeDef GPIO_InitStructure;
00146 
00147   /* GPIOA Configuration: Channel 1 as alternate function push-pull */
00148   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
00149   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00150   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00151   GPIO_Init(GPIOA, &GPIO_InitStructure);
00152 
00153   /* GPIOB Configuration: Channel 1N as alternate function push-pull */
00154   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
00155   GPIO_Init(GPIOB, &GPIO_InitStructure);
00156 
00157   /* GPIOA Configuration: BKIN pin */
00158   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
00159   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00160   GPIO_Init(GPIOB, &GPIO_InitStructure);  
00161 }
00162 
00163 #ifdef  USE_FULL_ASSERT
00164 
00165 /**
00166   * @brief  Reports the name of the source file and the source line number
00167   *         where the assert_param error has occurred.
00168   * @param  file: pointer to the source file name
00169   * @param  line: assert_param error line source number
00170   * @retval None
00171   */
00172 void assert_failed(uint8_t* file, uint32_t line)
00173 {
00174   /* User can add his own implementation to report the file name and line number,
00175      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00176 
00177   while (1)
00178   {}
00179 }
00180 #endif
00181 
00182 /**
00183   * @}
00184   */ 
00185 
00186 /**
00187   * @}
00188   */ 
00189 
00190 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32