EasyManuals Logo

STMicroelectronics STM8 User Manual

STMicroelectronics STM8
126 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #88 background imageLoading...
Page #88 background image
GPIO_Init(GPIOC, GPIO_PIN_1, GPIO_MODE_OUT_PP_HIGH_FAST);
}
void TIM1_setup(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 1000, 1);
TIM1_OC1Init(TIM1_OCMODE_PWM1,
TIM1_OUTPUTSTATE_ENABLE,
TIM1_OUTPUTNSTATE_ENABLE,
1000,
TIM1_OCPOLARITY_LOW,
TIM1_OCNPOLARITY_LOW,
TIM1_OCIDLESTATE_RESET,
TIM1_OCNIDLESTATE_RESET);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
}
Explanation
This time we used the full 16MHz speed of HSI both for peripheral and CPU clocks:
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
….
….
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);
Like as with the previous example PWM output GPIOs are set as outputs:
void GPIO_setup(void)
{
GPIO_DeInit(GPIOB);
GPIO_Init(GPIOB, GPIO_PIN_0, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_DeInit(GPIOC);
GPIO_Init(GPIOC, GPIO_PIN_1, GPIO_MODE_OUT_PP_HIGH_FAST);
}
TIM1 and OC channel initialization is just like the previous example with some minor differences. The
time base generation part seems to have some additional arguments. These are because:
Unlike other timers, TIM1 prescaler value is not a fixed set of multiples of 2.
The counting mode is not just up mode counting. Counting mode can also be down counting.
TIM1 has additional repetition counter.
Except the basic timers all timers in STM8 are 16-bit timer.
If you open the header file for TIM1, you’ll see many functions. Many of these functions are not
available with other timers, expressing the power of an advance timer.

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the STMicroelectronics STM8 and is the answer not in the manual?

STMicroelectronics STM8 Specifications

General IconGeneral
BrandSTMicroelectronics
ModelSTM8
CategoryMicrocontrollers
LanguageEnglish

Related product manuals