diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index 1b7de35..a59d46a 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -55,3 +55,11 @@ void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int else LL_TIM_OC_SetCompareCH4(Timer, CompareValue); } +int MyPWM_Duty_Cycle_Permilles(TIM_TypeDef * Timer, int channel1, int channel2) { + if(channel1 == LL_TIM_CHANNEL_CH1 && channel2 == LL_TIM_CHANNEL_CH2) { + return LL_TIM_IC_GetCaptureCH2(Timer) / LL_TIM_IC_GetCaptureCH1(Timer) * 1000; + } + else { + return -1; + } +} diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h index 562cb06..1905014 100644 --- a/MyDrivers/MyPWM.h +++ b/MyDrivers/MyPWM.h @@ -10,4 +10,6 @@ void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2); void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel); +int MyPWM_Duty_Cycle_Permilles(TIM_TypeDef * Timer, int channel1, int channel2); + #endif