你好,
我已经在我的系统上实现了上面的示例,并且没有在STM8S103F3上的Timer1 Channel1上获得任何输出,STM8S103F3是TSOP封装上的引脚16,其名称是PC6 / SPI_MOSI [TIM1_ CH1]。
我尝试修改极性并启用/禁用输出通道 - 似乎没有任何改变任何行为。
有谁知道为什么会这样?
这是TIM1_Config函数,它有一些小的修改来处理频率。
static void TIM11_Config(void)
{
uint16_t cr1 = 78; //这大约为100.8 kHz
uint16_t period =((cr1 + 1)* 2)-1; TIM1_DeInit();
/ *时基配置* /
/ *
TIM1_Period = 4095
TIM1_Prescaler = 0
TIM1_CounterMode = TIM1_COUNTERMODE_UP
TIM1_RepetitionCounter = 0
* / TIM1_TimeBaseInit(0,TIM1_COUNTERMODE_UP,句点,0);
/ *通道1,2,3和4在PWM模式下配置* /
/ *
TIM1_OCMode = TIM1_OCMODE_PWM2
TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
TIM1_Pulse = CCR1_Val
TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
* /
TIM1_OC1Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_DISABLE,TIM1_OUTPUTNSTATE_ENABLE,cr1,TIM1_OCPOLARITY_HIGH,TIM1_OCNPOLARITY_LOW,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR2_Val * /
TIM1_OC2Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_ENABLE,cr1,TIM1_OCPOLARITY_HIGH,TIM1_OCNPOLARITY_LOW,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR3_Val * /
TIM1_OC3Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,cr1,TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR4_Val * /
TIM1_OC4Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,cr1,TIM1_OCPOLARITY_LOW,TIM1_OCIDLESTATE_SET); / * TIM1计数器启用* /
TIM1_Cmd(ENABLE); / * TIM1主输出使能* /
TIM1_CtrlPWMOutputs(ENABLE);
这就是它的全部 - 非常直接。
以上来自于谷歌翻译
以下为原文
Hello,
I have implemented the above sample on my system and am NOT getting any output on Timer1 Channel1 on an STM8S103F3 which is Pin 16 on the TSOP package and the designation is PC6/ SPI_MOSI [TIM1_ CH1].
I've tried modifying the polarity and enable/disable of the output channels - nothing seems to change any behavior.
Does anyone know why this might be happening?
Here is the TIM1_Config function with a few small modifications to deal with frequency.
static void TIM11_Config(void)
{
uint16_t cr1 = 78; // this gives approximately 100.8 kHz
uint16_t period = ((cr1+1)*2)-1;TIM1_DeInit();
/* Time Base configuration */
/*
TIM1_Period = 4095
TIM1_Prescaler = 0
TIM1_CounterMode = TIM1_COUNTERMODE_UP
TIM1_RepetitionCounter = 0
*/TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, period, 0);
/* Channel 1, 2,3 and 4 Configuration in PWM mode */
/*
TIM1_OCMode = TIM1_OCMODE_PWM2
TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
TIM1_Pulse = CCR1_Val
TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
*/
TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_ENABLE,cr1, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET);/*TIM1_Pulse = CCR2_Val*/
TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, cr1, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);/*TIM1_Pulse = CCR3_Val*/
TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE,cr1, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);/*TIM1_Pulse = CCR4_Val*/
TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, cr1, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_SET);/* TIM1 counter enable */
TIM1_Cmd(ENABLE);/* TIM1 Main Output Enable */
TIM1_CtrlPWMOutputs(ENABLE);
}That's all there is to it - pretty straight forward.