cancel
Showing results for 
Search instead for 
Did you mean: 

I am using STM8S001J3 for PWM at TIMER 1 channel 4(PC4) PIN NO 7,but not getting pwm..pls.suggest.

Pravin kumar
Associate II

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

}

1 ACCEPTED SOLUTION

Accepted Solutions
prain
Senior III

Compare your code with SPL library for your MCU. In SPL there are examples to test PWM.

View solution in original post

4 REPLIES 4
Cristian Gyorgy
Senior III

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?

prain
Senior III

Compare your code with SPL library for your MCU. In SPL there are examples to test PWM.

Please share SPL libary for PWM on Timer 1 channel 4 for stm8s001j3

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.