AnsweredAssumed Answered

STM8L152C6T6 - PWM output compare

Question asked by lo_re.gilberto on Dec 17, 2013
Latest reply on Dec 17, 2013 by sung.chen_chung
Hi everyone,
I need to generate a square wave and I've written some code but it doesn't work as i want. Can anyone help me with my doubts please?

first of all: I'm not sure that the following registers are in hexadecimal.. any ideas?
second: I didn't undestand what are the complementary output states PRACTICALLY.
third: any advices on this code? 

Thanks a lot for every help,
Gilberto

uint16_t TIM1_Prescaler=4;
uint16_t TIM1_Period=320; 
uint8_t TIM1_RepetitionCounter = 0;
uint16_t TIM1_Pulse = 190;

     CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
     TIM1_DeInit();
     TIM1_TimeBaseInit(TIM1_Prescaler,TIM1_CounterMode_Up,TIM1_Period,TIM1_RepetitionCounter);
     TIM1_OC1Init(          TIM1_OCMode_PWM1,
                  TIM1_OutputState_Enable,
                  TIM1_OutputNState_Disable,
                                             TIM1_Pulse,
                  TIM1_OCPolarity_High,
                  TIM1_OCNPolarity_Low,
                  TIM1_OCIdleState_Set,
                  TIM1_OCNIdleState_Reset);
                                             
     TIM1_OC1PreloadConfig(ENABLE);
     TIM1_ARRPreloadConfig(ENABLE);
     TIM1_Cmd(ENABLE);

Outcomes