cancel
Showing results for 
Search instead for 
Did you mean: 

i set timer1 channel1 registers as the same as timer1 channel 2,3,4 but it does'nt work

Ocohe
Associate
 
2 REPLIES 2

Ok, and how do you think the cause can be determined with that level of detail? ​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Ocohe
Associate

i uses the spl from the st.com for stm8s-discuvery with the 7 pwm example for timer 1 .

after calling the function i can read in the debugger the next register value , it looks like ok i think but not working

this example set pwm in timer 1 2 3 4

2,4 works , 1 does'nt work.

TIM1->CCRE1 = 0x77

TIM1->CCMR1 = 0x70

TIM1->OISR = 0x5F

TIM1->CR1 = 0x01

TIM1->BKR = 0x80

in the main() file :

  TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0);

   TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,

        CCR2_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,

        TIM1_OCNIDLESTATE_RESET);

in the tim1.c file

void TIM1_TimeBaseInit(uint16_t TIM1_Prescaler,

            TIM1_CounterMode_TypeDef TIM1_CounterMode,

            uint16_t TIM1_Period,

            uint8_t TIM1_RepetitionCounter)

{

 /* Check parameters */

 assert_param(IS_TIM1_COUNTER_MODE_OK(TIM1_CounterMode));

  

 /* Set the Autoreload value */

 TIM1->ARRH = (uint8_t)(TIM1_Period >> 8);

 TIM1->ARRL = (uint8_t)(TIM1_Period);

  

 /* Set the Prescaler value */

 TIM1->PSCRH = (uint8_t)(TIM1_Prescaler >> 8);

 TIM1->PSCRL = (uint8_t)(TIM1_Prescaler);

  

 /* Select the Counter Mode */

 TIM1->CR1 = (uint8_t)((uint8_t)(TIM1->CR1 & (uint8_t)(~(TIM1_CR1_CMS | TIM1_CR1_DIR)))

            | (uint8_t)(TIM1_CounterMode));

  

 /* Set the Repetition Counter value */

 TIM1->RCR = TIM1_RepetitionCounter;

}

void TIM1_OC1Init(TIM1_OCMode_TypeDef TIM1_OCMode,

         TIM1_OutputState_TypeDef TIM1_OutputState,

         TIM1_OutputNState_TypeDef TIM1_OutputNState,

         uint16_t TIM1_Pulse,

         TIM1_OCPolarity_TypeDef TIM1_OCPolarity,

         TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity,

         TIM1_OCIdleState_TypeDef TIM1_OCIdleState,

         TIM1_OCNIdleState_TypeDef TIM1_OCNIdleState)

{

  

 /* Disable the Channel 1: Reset the CCE Bit, Set the Output State , 

 the Output N State, the Output Polarity & the Output N Polarity*/

 TIM1->CCER1 &= (uint8_t)(~( TIM1_CCER1_CC1E | TIM1_CCER1_CC1NE 

               | TIM1_CCER1_CC1P | TIM1_CCER1_CC1NP));

 /* Set the Output State & Set the Output N State & Set the Output Polarity &

 Set the Output N Polarity */

 TIM1->CCER1 |= (uint8_t)((uint8_t)((uint8_t)(TIM1_OutputState & TIM1_CCER1_CC1E)

                   | (uint8_t)(TIM1_OutputNState & TIM1_CCER1_CC1NE))

              | (uint8_t)( (uint8_t)(TIM1_OCPolarity & TIM1_CCER1_CC1P)

                    | (uint8_t)(TIM1_OCNPolarity & TIM1_CCER1_CC1NP)));

  

 /* Reset the Output Compare Bits & Set the Output Compare Mode */

 TIM1->CCMR1 = (uint8_t)((uint8_t)(TIM1->CCMR1 & (uint8_t)(~TIM1_CCMR_OCM)) | 

             (uint8_t)TIM1_OCMode);

  

 /* Reset the Output Idle state & the Output N Idle state bits */

 TIM1->OISR &= (uint8_t)(~(TIM1_OISR_OIS1 | TIM1_OISR_OIS1N));

 /* Set the Output Idle state & the Output N Idle state configuration */

 TIM1->OISR |= (uint8_t)((uint8_t)( TIM1_OCIdleState & TIM1_OISR_OIS1 ) | 

             (uint8_t)( TIM1_OCNIdleState & TIM1_OISR_OIS1N ));

  

 /* Set the Pulse value */

 TIM1->CCR1H = (uint8_t)(TIM1_Pulse >> 8);

 TIM1->CCR1L = (uint8_t)(TIM1_Pulse);

}