Ajout de PWM input
This commit is contained in:
parent
4ca6136473
commit
7cf96b23f2
1 changed files with 34 additions and 0 deletions
|
@ -165,7 +165,41 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
|
|||
/****************************************************************************
|
||||
* PWM INPUT
|
||||
***************************************************************************/
|
||||
void PWMi_conf(TIM_TypeDef * TIMx, uint32_t channels){
|
||||
//Periode à recuperer dans TIMx_CCR1, duty cycle dans TIMx_CCR2
|
||||
// Validation horloge locale
|
||||
if (TIMx == TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
else if (TIMx == TIM2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
else if (TIMx == TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||||
else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||
|
||||
//LL_TIM_CC_EnableChannel(TIMx, channels);
|
||||
//LL_TIM_IC_Init
|
||||
TIMx -> CCMR1 |= TIM_CCMR1_CC1S_0; //01
|
||||
//TIM_CCMR1_IC1F_0; Potentiellement utile, à voir plus tard
|
||||
TIMx -> CCER &= ~(TIM_CCER_CC1P); //0 = Rising edge
|
||||
TIMx -> CCMR1 &= ~(TIM_CCMR1_IC1PSC);
|
||||
|
||||
TIMx -> CCMR1 |= TIM_CCMR1_CC2S_1;
|
||||
TIMx -> CCER |= TIM_CCER_CC2P;
|
||||
TIMx -> SMCR |= TIM_SMCR_TS_0 | TIM_SMCR_TS_2; //101
|
||||
TIMx -> SMCR |= TIM_SMCR_SMS_2; //100
|
||||
|
||||
TIMx -> CCER |= TIM_CCER_CC1E;
|
||||
TIMx -> CCER |= TIM_CCER_CC2E;
|
||||
TIMx -> DIER |= TIM_DIER_CC1IE;
|
||||
//TIM_DIER_CC1DE_Pos; Probablement pas utile
|
||||
}
|
||||
|
||||
int get_input_period(TIM_TypeDef * TIMx) {
|
||||
|
||||
return TIMx -> CCR1;
|
||||
}
|
||||
|
||||
int get_input_duty_cycle(TIM_TypeDef * TIMx) {
|
||||
|
||||
return TIMx -> CCR2;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* PWM OUTPUT
|
||||
|
|
Loading…
Reference in a new issue