Reecriture de PWM input et ecriture des fonctions RFReiceiver

This commit is contained in:
Marino Benassai 2020-11-11 16:46:17 +01:00
parent 45c2080a92
commit 491fd3af6b
4 changed files with 59 additions and 16 deletions

View file

@ -165,29 +165,50 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
/**************************************************************************** /****************************************************************************
* PWM INPUT * PWM INPUT
***************************************************************************/ ***************************************************************************/
void PWMi_conf(TIM_TypeDef * TIMx, uint32_t channels){ void PWMi_conf(TIM_TypeDef * TIMx, int channel){
//Periode à recuperer dans TIMx_CCR1, duty cycle dans TIMx_CCR2
//Periode à recuperer dans TIMx_CCR1, duty cycle dans TIMx_CCR2. Seul les 2 premiers channels peuvent être utilisés (cf 315).
// Validation horloge locale // Validation horloge locale
if (TIMx == TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1); 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 == TIM2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
else if (TIMx == TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3); else if (TIMx == TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4); 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; if (channel == 1) {
TIMx -> CCER |= TIM_CCER_CC2P; //
TIMx -> SMCR |= TIM_SMCR_TS_0 | TIM_SMCR_TS_2; //101 TIMx -> CCMR1 |= TIM_CCMR1_CC1S_0;
TIMx -> SMCR |= TIM_SMCR_SMS_2; //100 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; else {
TIMx -> CCER |= TIM_CCER_CC2E; TIMx -> CCMR1 |= TIM_CCMR1_CC1S_1;
TIMx -> DIER |= TIM_DIER_CC1IE; 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 //TIM_DIER_CC1DE_Pos; Probablement pas utile
} }

View file

@ -59,7 +59,7 @@ void Timer_stop(TIM_TypeDef * timer);
* PWM INPUT * 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); int PWMi_getDutyCycle(TIM_TypeDef * timer);

View file

@ -1 +1,17 @@
#include "RFReceiver.h" #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;
}

View file

@ -1,4 +1,10 @@
#ifndef RFRECEIVER_H #ifndef RFRECEIVER_H
#define RFRECEIVER_H #define RFRECEIVER_H
#include "Timer.c"
void RFReceiver_conf(void);
double RFReceiver_getData(void);
#endif #endif