Skip to main content
Visitor II
August 6, 2020
Solved

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

  • August 6, 2020
  • 2 replies
  • 1377 views

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

}

    This topic has been closed for replies.
    Best answer by prain

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

    2 replies

    Visitor II
    August 6, 2020

    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?

    Visitor II
    August 7, 2020

    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.

    prainAnswer
    Visitor II
    August 6, 2020

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

    Visitor II
    August 7, 2020

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