2013-12-16 04:26 PM
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,Gilbertouint16_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); #stm8l-stm8-pwm2013-12-17 01:51 AM
Hi
''I'm not sure that the following registers are in hexadecimal.. any ideas?'' In general, if you do not specify the number format the compiler will assume the number is in decimal. So ''uint16_t TIM1_Prescaler=4;
uint16_t TIM1_Period=320; uint8_t TIM1_RepetitionCounter = 0; uint16_t TIM1_Pulse = 190;'' This code will set the registers to 4 320 0 190 all in decimal. To specify the number in hexadecimal add '0x' in front of the number eg 0x0 = 0 decimal 0xf = 15 decimal. Sorry, cannot help with the timer setup - I work on stm32 not stm8