STM8 programming [TIM1 multiplex PWM output option byte (Option Byte) operation and IO multiplexing]

TIM1 multi-channel PWM output option byte (Option Byte) operation and IO multiplexing

This article is excerpted from: https://blog.csdn.net/freeape/article/details/47008033 It is just for learning backup, and there is no intention of plagiarism. If you have any doubts, please contact me!
The code should use TIME1 to output 3-way PWM, the code is as follows:

void timer1_init(void)
{
    
    
  TIM1_DeInit();  
  
  TIM1_TimeBaseInit(0x0000, TIM1_COUNTERMODE_UP, 1600, 0x00);//16000000/160=10000=10K

  TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,400, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
  TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,800, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
  TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,1200, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
  TIM1_Cmd(ENABLE);
  TIM1_CtrlPWMOutputs(ENABLE);
}

But I don’t know why there is no output from channel 1 and channel 2, only channel 3 has output:
insert image description here
After checking from Baidu, I finally saw this article: https://blog.csdn.net/freeape/article/details/47008033
insert image description here
You need to configure AFR0. After knowing that you need to use stvp to modify Option Byte: https://download.csdn.net/download/rui22/12885187
insert image description here
After the operation is successful, you can read back the configuration to see if it is successful:
insert image description here
insert image description here
after configuration, channel 1 and Channel 2 finally has PWM output:
insert image description here

Guess you like

Origin blog.csdn.net/chengdong1314/article/details/132372465
Recommended