diff --git a/MyDrivers/Timer.c b/MyDrivers/Timer.c index 2b29356..311e027 100644 --- a/MyDrivers/Timer.c +++ b/MyDrivers/Timer.c @@ -165,29 +165,50 @@ 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 +void PWMi_conf(TIM_TypeDef * TIMx, int channel){ + + //Periode à recuperer dans TIMx_CCR1, duty cycle dans TIMx_CCR2. Seul les 2 premiers channels peuvent être utilisés (cf 315). + // 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 + if (channel == 1) { + // + TIMx -> CCMR1 |= TIM_CCMR1_CC1S_0; + TIMx -> CCMR1 |= TIM_CCMR1_CC2S_1; + + //TIM_CCMR1_IC1F_0; Potentiellement utile, à voir plus tard + + //On met le channel principal en rising edge, le secondaire en falling edge + TIMx -> CCER &= ~TIM_CCER_CC1P; + 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; + else { + TIMx -> CCMR1 |= TIM_CCMR1_CC1S_1; + TIMx -> CCMR1 |= TIM_CCMR1_CC2S_0; + + TIMx -> CCER |= TIM_CCER_CC1P; + TIMx -> CCER &= ~TIM_CCER_CC2P; + + TIMx -> SMCR |= TIM_SMCR_TS_1 | TIM_SMCR_TS_2; //110 + TIMx -> SMCR |= TIM_SMCR_SMS_2; //100 + } + + //On met les prescalers à 0, on veut compter chaque transition + TIMx -> CCMR1 &= ~TIM_CCMR1_IC1PSC; + TIMx -> CCMR1 &= ~TIM_CCMR1_IC2PSC; + + TIMx -> CCER |= TIM_CCER_CC1E | TIM_CCER_CC2E; + + //TIMx -> DIER |= TIM_DIER_CC1IE; gestion des interrupts, probablement pas utile //TIM_DIER_CC1DE_Pos; Probablement pas utile } diff --git a/MyDrivers/Timer.h b/MyDrivers/Timer.h index 800446c..f106812 100644 --- a/MyDrivers/Timer.h +++ b/MyDrivers/Timer.h @@ -59,7 +59,7 @@ void Timer_stop(TIM_TypeDef * timer); * PWM INPUT ***************************************************************************/ -void PWMi_conf(TIM_TypeDef * timer, uint32_t channel); +void PWMi_conf(TIM_TypeDef * timer, int channel); int PWMi_getDutyCycle(TIM_TypeDef * timer); diff --git a/Services/RFReceiver.c b/Services/RFReceiver.c index c560906..87a3d81 100644 --- a/Services/RFReceiver.c +++ b/Services/RFReceiver.c @@ -1 +1,17 @@ #include "RFReceiver.h" + +void RFReceiver_conf() { + + PWMi_conf(TIM4, 1); + + } + +double RFReceiver_getData(){ + + int duty_cycle = PWMi_getDutyCycle(TIM4); + int period = PWMi_getPeriod(TIM4); + double duree_impulsion = duty_cycle * period; + + return (duree_impulsion -1) * 200 - 100; + +} \ No newline at end of file diff --git a/Services/RFReceiver.h b/Services/RFReceiver.h index e14454b..ce84ce4 100644 --- a/Services/RFReceiver.h +++ b/Services/RFReceiver.h @@ -1,4 +1,10 @@ #ifndef RFRECEIVER_H #define RFRECEIVER_H +#include "Timer.c" + +void RFReceiver_conf(void); + +double RFReceiver_getData(void); + #endif