STM8L152C6T6 - PWM output compare
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2013-12-16 4:26 PM
Posted on December 17, 2013 at 01:26
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-pwm
This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2013-12-17 1:51 AM
Posted on December 17, 2013 at 10:51
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