stm8s003f/103f的tim2 3路pwm都无输出,使用的是st 提供的库,option byte也设置了。代码如下:
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
/**
* @addtogroup TIM2_PWM_DutyCycleConfiguration
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint16_t CCR1_Val = 500;
uint16_t CCR2_Val = 250;
uint16_t CCR3_Val = 125;
/* Private function prototypes -----------------------------------------------*/
static void TIM2_Config(void);
/* Private functions ---------------------------------------------------------*/
/* Public functions ----------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
void main(void)
{
/* TIM2 configuration -----------------------------------------*/
TIM2_Config();
while (1)
{}
}
/**
* @brief Configure TIM2 peripheral in PWM mode
* @param None
* @retval None
*/
static void TIM2_Config(void)
{
/* Time base configuration */
TIM2_TimeBaseInit(TIM2_PRESCALER_1, 999);
/* PWM1 Mode configuration: Channel1 */
TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH);
TIM2_OC1PreloadConfig(ENABLE);
/* PWM1 Mode configuration: Channel2 */
TIM2_OC2Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH);
TIM2_OC2PreloadConfig(ENABLE);
/* PWM1 Mode configuration: Channel3 */
TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH);
TIM2_OC3PreloadConfig(ENABLE);
TIM2_ARRPreloadConfig(ENABLE);
/* TIM2 enable counter */
TIM2_Cmd(ENABLE);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|