2016-09-20 02:54 AM
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,&sharpinclude ''STM8S003k3.h''
&sharpifndef BIT
&sharpdefine BIT(n) (1 << (n))
&sharpendif
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 #stm8s-tim1_ch12017-06-08 09:56 AM
Did you get this issue? I am also struggling to solve it, I could make Channel 3 and 4 work but not 1 and 2.
2017-10-01 02:41 PM
Hello !
Well June is quite a while ago ....I'm also using the 20 pin version and it did not work at first try either - although the setting of the option bit seemed correct it was not set properly by the programmer. So i think that is what likely happened to you too.
This option flags reside in flash at address 0x4803 and 0x4804 and values should be 0x01 and 0xFE (the complement). In debugger open a memory window and inspect content:
004800 00 00 FF 01 FE 00 FF 00 ........ <- should look like this
004800 00 00 FF 00 FF 00 FF 00 ........ <- this is default with AFR1 reset (SPI instead of TIMER channels)
You cannot change these at runtime (easily) but have to set the options bits correctly in the IDE.
Tom
2017-12-06 12:54 PM
Tom thank you for the reply, I am also struggling to get TIM1 to work. What is the best way to reconfigure the programmer to update 0x4803 and 0x4804.