AnsweredAssumed Answered

Configuring channel 1 of Timer1 for PWM signal (STM8S controller)

Question asked by bhakta.vivek on Sep 20, 2016
Latest reply on Dec 6, 2017 by Philip Haasnoot
Hi,

We are working on STM8S003f3 microcontroller. We have successfully configured Channel 3 of the microcontroller.

When Tim1- Channel1 is configured in similar way, it does not produce PWM ouptput on the pin.

We have also enabled Option byte -AFR0 for selecting alternative function in 'ST Visual develop tool'.

Please refer code below for reference,


#include "STM8S003k3.h"


#ifndef BIT 
#define BIT(n) (1 << (n)) 
#endif

void PWM_OC1_25_OC2_50_OC3_75(void) 

TIM1_CR1&=~BIT(0); // Close TIM1

TIM1_PSCRH = 0; 
TIM1_PSCRL = 0; // undivided

TIM1_ARRH = 0; 
TIM1_ARRL = 99; 

TIM1_CCR1H = 0; 
TIM1_CCR1L = 25; // 25% duty cycle (25 / (99 + 1)) 
TIM1_CCMR1 = 0x60; // PWM mode 1 
TIM1_CCER1|=BIT(0); // Enable OC1 

TIM1_CCR3H = 0; 
TIM1_CCR3L = 75; // duty cycle of 75% (75 / (99 + 1)) 
TIM1_CCMR3 = 0x60; // PWM mode 1 
TIM1_CCER2|=BIT(0); // enable OC3 

TIM1_CR1|=BIT(0); // Enable TIM1 
TIM1_BKR|=BIT(7); // ban brakes 
}

main()
{
    PWM_OC1_25_OC2_50_OC3_75();    
    while (1);


Any help would be greatly appreciated.

Thanks and Kind Regards,
Vivek 

Outcomes