Merge remote-tracking branch 'origin/MB'
This commit is contained in:
commit
61b90609c2
12 changed files with 195 additions and 1 deletions
|
@ -165,7 +165,62 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* PWM INPUT
|
* PWM INPUT
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
int PWMi_getPeriod(TIM_TypeDef * TIMx) {
|
||||||
|
|
||||||
|
return TIMx -> CCR1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PWMi_getDutyCycle(TIM_TypeDef * TIMx) {
|
||||||
|
|
||||||
|
return TIMx -> CCR2;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* PWM OUTPUT
|
* PWM OUTPUT
|
||||||
|
|
|
@ -61,7 +61,9 @@ void Timer_stop(TIM_TypeDef * timer);
|
||||||
|
|
||||||
void PWMi_conf(TIM_TypeDef * timer, int channel);
|
void PWMi_conf(TIM_TypeDef * timer, int channel);
|
||||||
|
|
||||||
int PWMi_getDutyCycle(TIM_TypeDef * timer, int channel);
|
int PWMi_getDutyCycle(TIM_TypeDef * timer);
|
||||||
|
|
||||||
|
int PWMi_getPeriod(TIM_TypeDef * TIMx);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* PWM OUTPUT
|
* PWM OUTPUT
|
||||||
|
|
|
@ -1 +1,32 @@
|
||||||
#include "DCMotor.h"
|
#include "DCMotor.h"
|
||||||
|
|
||||||
|
void DCMotor_conf() {
|
||||||
|
|
||||||
|
//On règle la vitesse en valeur absolue, ici à 0
|
||||||
|
Timer_pwmo_conf(TIM2, LL_TIM_CHANNEL_CH2, 50, 0);
|
||||||
|
|
||||||
|
//On règle le sens du moteur, ici sens direct (?)
|
||||||
|
GPIO_conf(GPIOA, LL_GPIO_PIN_2, LL_GPIO_MODE_OUTPUT, LL_GPIO_OUTPUT_OPENDRAIN, LL_GPIO_PULL_DOWN);
|
||||||
|
GPIO_setPin(GPIOA, LL_GPIO_PIN_2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DCMotor_setSpeed(double speed) {
|
||||||
|
|
||||||
|
double speedAbs = (speed > 0.) ? speed : -speed;
|
||||||
|
int sens = (speed > 0.) ? 1 : 0;
|
||||||
|
|
||||||
|
Timer_pwmo_setDutyCycle(TIM2, LL_TIM_CHANNEL_CH2, speedAbs);
|
||||||
|
GPIO_setPin(GPIOA, LL_GPIO_PIN_2, sens);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double DCMotor_getSpeed(){
|
||||||
|
|
||||||
|
double speedAbs = Timer_pwmo_getDutyCycle(TIM2, LL_TIM_CHANNEL_CH2);
|
||||||
|
int sens = GPIO_readPin(GPIOA, LL_GPIO_PIN_2);
|
||||||
|
|
||||||
|
double speed = (sens) ? speedAbs : -speedAbs;
|
||||||
|
|
||||||
|
return speed;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
#ifndef DCMOTOR_H
|
#ifndef DCMOTOR_H
|
||||||
#define DCMOTOR_H
|
#define DCMOTOR_H
|
||||||
|
|
||||||
|
#include "GPIO.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
|
void DCMotor_conf(void);
|
||||||
|
|
||||||
|
void DCMotor_setSpeed(double speed);
|
||||||
|
|
||||||
|
double DCMotor_getSpeed(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1 +1,18 @@
|
||||||
#include "RFEmitter.h"
|
#include "RFEmitter.h"
|
||||||
|
|
||||||
|
|
||||||
|
void RFEmitter_conf() {
|
||||||
|
|
||||||
|
//On configure l'USART
|
||||||
|
Usart_conf(USART1);
|
||||||
|
|
||||||
|
//On active l'USART
|
||||||
|
Usart_enable(USART1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void RFEmitter_send(char * message, int longueur) {
|
||||||
|
|
||||||
|
Usart_send(USART1, message, longueur);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
#ifndef RFEMITTER_H
|
#ifndef RFEMITTER_H
|
||||||
#define RFEMITTER_H
|
#define RFEMITTER_H
|
||||||
|
|
||||||
|
#include "USART.h"
|
||||||
|
|
||||||
|
void RFEmitter_conf(void);
|
||||||
|
|
||||||
|
void RFEmitter_send(char * message, int longueur);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
#ifndef RFRECEIVER_H
|
#ifndef RFRECEIVER_H
|
||||||
#define RFRECEIVER_H
|
#define RFRECEIVER_H
|
||||||
|
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
|
void RFReceiver_conf(void);
|
||||||
|
|
||||||
|
double RFReceiver_getData(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1 +1,21 @@
|
||||||
#include "Voltage.h"
|
#include "Voltage.h"
|
||||||
|
|
||||||
|
|
||||||
|
void Voltage_conf() {
|
||||||
|
|
||||||
|
//On configure le pin qui recevra le signal, ici PC2
|
||||||
|
GPIO_conf(GPIOC, LL_GPIO_PIN_2, LL_GPIO_MODE_ANALOG, 0, 0);
|
||||||
|
|
||||||
|
//On configure l'ADC
|
||||||
|
ADC_conf(ADC2, 12);
|
||||||
|
|
||||||
|
//On démarre l'ADC
|
||||||
|
ADC_start(ADC2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double Voltage_getVoltage() {
|
||||||
|
|
||||||
|
return ADC_readVolt(ADC2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
#ifndef VOLTAGE_H
|
#ifndef VOLTAGE_H
|
||||||
#define VOLTAGE_H
|
#define VOLTAGE_H
|
||||||
|
|
||||||
|
#include "ADC.h"
|
||||||
|
#include "GPIO.h"
|
||||||
|
|
||||||
|
void Voltage_conf(void);
|
||||||
|
|
||||||
|
double Voltage_getVoltage(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1 +1,19 @@
|
||||||
#include "Orientation.h"
|
#include "Orientation.h"
|
||||||
|
#define SEUIL 30
|
||||||
|
|
||||||
|
void Orientation_conf() {
|
||||||
|
|
||||||
|
DCMotor_conf();
|
||||||
|
RFReceiver_conf();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Orientation_background(){
|
||||||
|
|
||||||
|
double speed = RFReceiver_getData();
|
||||||
|
|
||||||
|
//Si la vitesse (en valeur absolue) ne dépasse pas un certain seuil, on ne démarre pas le moteur
|
||||||
|
if (-SEUIL<speed && SEUIL>speed) DCMotor_setSpeed(0);
|
||||||
|
else DCMotor_setSpeed(speed);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
#ifndef ORIENTATION_H
|
#ifndef ORIENTATION_H
|
||||||
#define ORIENTATION_H
|
#define ORIENTATION_H
|
||||||
|
|
||||||
|
#include "DCMotor.h"
|
||||||
|
#include "RFReceiver.h"
|
||||||
|
|
||||||
|
void Orientation_conf(void);
|
||||||
|
|
||||||
|
void Orientation_background(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue