mirror of
https://github.com/elua/elua.git
synced 2025-01-25 01:02:54 +08:00
Fix to allow STM32 PWM frequencies to go below 1100 Hz
This commit is contained in:
parent
957dab161d
commit
3e1248ebc6
@ -857,16 +857,22 @@ static u32 platform_pwm_set_clock( u32 clock )
|
||||
{
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
TIM_TypeDef* ptimer = PWM_TIMER_NAME;
|
||||
unsigned period, prescaler;
|
||||
|
||||
/* Time base configuration */
|
||||
TIM_TimeBaseStructure.TIM_Period = ( TIM_GET_BASE_CLK( PWM_TIMER_ID ) / clock ) - 1;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 0;
|
||||
period = TIM_GET_BASE_CLK( PWM_TIMER_ID ) / clock;
|
||||
|
||||
prescaler = (period / 0x10000) + 1;
|
||||
period /= prescaler;
|
||||
|
||||
TIM_TimeBaseStructure.TIM_Period = period - 1;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = prescaler - 1;
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000;
|
||||
TIM_TimeBaseInit( ptimer, &TIM_TimeBaseStructure );
|
||||
|
||||
return ( TIM_GET_BASE_CLK( PWM_TIMER_ID ) / ( TIM_TimeBaseStructure.TIM_Period + 1 ) ) ;
|
||||
return platform_pwm_get_clock();
|
||||
}
|
||||
|
||||
u32 platform_pwm_setup( unsigned id, u32 frequency, unsigned duty )
|
||||
@ -1164,13 +1170,13 @@ u32 platform_adc_setclock( unsigned id, u32 frequency )
|
||||
period = TIM_GET_BASE_CLK( id ) / frequency;
|
||||
|
||||
prescaler = (period / 0x10000) + 1;
|
||||
period /= prescaler;
|
||||
period /= prescaler;
|
||||
|
||||
timer_base_struct.TIM_Period = period - 1;
|
||||
timer_base_struct.TIM_Prescaler = prescaler - 1;
|
||||
timer_base_struct.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
timer_base_struct.TIM_CounterMode = TIM_CounterMode_Down;
|
||||
TIM_TimeBaseInit( timer[ d->timer_id ], &timer_base_struct );
|
||||
timer_base_struct.TIM_Period = period - 1;
|
||||
timer_base_struct.TIM_Prescaler = prescaler - 1;
|
||||
timer_base_struct.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
timer_base_struct.TIM_CounterMode = TIM_CounterMode_Down;
|
||||
TIM_TimeBaseInit( timer[ d->timer_id ], &timer_base_struct );
|
||||
|
||||
frequency = ( TIM_GET_BASE_CLK( id ) / ( TIM_GetPrescaler( timer[ d->timer_id ] ) + 1 ) ) / period;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user