2020-08-06 07:40 AM
void PWM(void)//timer1 channel4
{
TIM1_ARRH = 0x03; // Reload counter = 960
TIM1_ARRL = 0xc0;
TIM1_PSCRH|= 0; // Prescalar = 0 (i.e. 1)
TIM1_PSCRL |= 0;
//TIM1_CR1 = 0; // Up counter.
TIM1_CR1|= 0; // Edge aligned counter.
TIM1_RCR |= 0; // No repetition.
//
// Now configure Timer 1, channel 4.
//
TIM1_CCMR4|= 0X80; // Set up to use PWM mode 2.
TIM1_CCER2|= 0X10; // Output is enabled.
TIM1_CCER2|= 0X20; // Active is defined as high.
TIM1_CCR4H|= 0x01; // 480 = 50% duty cycle (based on TIM1_ARR).
TIM1_CCR4L|= 0xe0;
TIM1_BKR|= 0X80;//1; // Enable the main output.
//
// Uncomment the following line to produce a single pulse.
TIM1_CR1|=0x01;// Enable counter
}
Solved! Go to Solution.
2020-08-06 12:22 PM
Compare your code with SPL library for your MCU. In SPL there are examples to test PWM.
2020-08-06 11:16 AM
Hi!
With only the code you posted we cannot say much. Did you enable the clock for TIM1 in CLK_PCKEN register? Is the port output enabled?
Does your timer run? How are you debugging?
2020-08-06 12:22 PM
Compare your code with SPL library for your MCU. In SPL there are examples to test PWM.
2020-08-06 09:12 PM
Please share SPL libary for PWM on Timer 1 channel 4 for stm8s001j3
2020-08-06 09:16 PM
enable the clock for TIM1 in CLK_PCKEN register & Is the port output ;besic timer 4 is running at 4 ms interrupt.using stm8-so8-disco for debug.