打印
[STM8]

stm8s003f/103f的tim2 3路pwm都无输出

[复制链接]
2656|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zfutech|  楼主 | 2016-2-18 11:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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****/

沙发
仙女山| | 2016-2-18 16:55 | 只看该作者
先测试一下你的timer有没有正常运行

使用特权

评论回复
板凳
xmshao| | 2016-2-18 22:46 | 只看该作者
确认下 已经定义了 STM8S003或STM8S103

typedef struct TIM2_struct
{
  __IO uint8_t CR1;   /*!< control register 1 */
#if defined(STM8S103) || defined(STM8S003)
        uint8_t RESERVED1; /*!< Reserved register */
        uint8_t RESERVED2; /*!< Reserved register */
#endif
  __IO uint8_t IER;   /*!< interrupt enable register */
  __IO uint8_t SR1;   /*!< status register 1 */
  __IO uint8_t SR2;   /*!< status register 2 */

使用特权

评论回复
地板
zfutech|  楼主 | 2016-2-19 13:55 | 只看该作者
To xmshao :  从st下载的库和例程,并在IAR中定义了芯片类型,编译都ok,timer1输出没问题。就timer2无输出,一路也没。
To 仙女山 : 测试了, 使用timer2中断例程有动作,代码未变更。

使用特权

评论回复
5
xmshao| | 2016-2-19 14:33 | 只看该作者
既然这样
可能管脚有问题,还有大家为什么总是不说完整芯片型号呢
是否有管脚需要额外OPTION配置的,若果是20脚的003/103,不做OPTION AFR配置就出不来。

使用特权

评论回复
6
xiaobai1号| | 2019-7-13 08:56 | 只看该作者
请问楼主这个问题解决了吗,我也遇到了同样的问题,求楼主指点

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝