Ajouter servo et IT
This commit is contained in:
parent
1fbbaacfea
commit
8b95eeb0a5
4 changed files with 117 additions and 0 deletions
11
Pilotes/Include/IT.h
Normal file
11
Pilotes/Include/IT.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef IT_H_
|
||||
#define IT_H_
|
||||
#include <stm32f10x.h>
|
||||
static void (*p_IT_functions[4])(void);
|
||||
void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void));
|
||||
void TIM1_CC_IRQHandler(void);
|
||||
void TIM1_UP_IRQHandler(void);
|
||||
void TIM2_IRQHandler(void);
|
||||
void TIM3_IRQHandler(void);
|
||||
void TIM4_IRQHandler(void);
|
||||
#endif // IT_H_
|
||||
7
Pilotes/Include/Servo.h
Normal file
7
Pilotes/Include/Servo.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef SERVO_H_
|
||||
#define SERVO_H_
|
||||
#include <stm32f10x.h>
|
||||
void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel);
|
||||
extern void initServo(TIM_TypeDef * Timer, int Channel);
|
||||
|
||||
#endif // SERVO_H_
|
||||
73
Pilotes/Source/IT.c
Normal file
73
Pilotes/Source/IT.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include "IT.h"
|
||||
|
||||
static void (*p_IT_functions[4])(void); // Pour créer l'array des fonctions
|
||||
|
||||
void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void)) {
|
||||
//Enable interruption requisition
|
||||
Timer->DIER |= TIM_DIER_UIE; // Update interrupt enable
|
||||
|
||||
//Id the interruption timer routine
|
||||
IRQn_Type IRQn;
|
||||
|
||||
int timer_index = -1; // Indice pour notre array des pointeurs
|
||||
if (Timer == TIM2) {
|
||||
IRQn = TIM2_IRQn;
|
||||
timer_index = 0;
|
||||
} else if (Timer == TIM3) {
|
||||
IRQn = TIM3_IRQn;
|
||||
timer_index = 1;
|
||||
} else if (Timer == TIM4) {
|
||||
IRQn = TIM4_IRQn;
|
||||
timer_index = 2;
|
||||
}
|
||||
// Keep the pointer of the valid timer function
|
||||
if (timer_index != -1) {
|
||||
p_IT_functions[timer_index] = IT_function; // index the function
|
||||
} else {
|
||||
return; // Timer invalid
|
||||
}
|
||||
// set interruption priority
|
||||
NVIC_SetPriority(IRQn, Prio);
|
||||
// Enable routine
|
||||
NVIC_EnableIRQ(IRQn);
|
||||
}
|
||||
|
||||
|
||||
void TIM2_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM2->SR &= ~TIM_SR_UIF; // Drapeau d'interuption
|
||||
//Call function
|
||||
if (p_IT_functions[0] != 0) {
|
||||
p_IT_functions[0](); // Execute fonction
|
||||
}
|
||||
};
|
||||
void TIM3_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM3->SR &= ~TIM_SR_UIF;
|
||||
//Call function
|
||||
if (p_IT_functions[1] != 0) {
|
||||
p_IT_functions[1](); // Execute function
|
||||
}
|
||||
};
|
||||
void TIM4_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM4->SR &= ~TIM_SR_UIF;
|
||||
//Call function
|
||||
if (p_IT_functions[2] != 0) {
|
||||
p_IT_functions[2](); // Execute function
|
||||
}
|
||||
};
|
||||
// IT PWM
|
||||
void TIM1_CC_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM1 -> DIER &= ~TIM_DIER_CC1IE;
|
||||
//Set bit
|
||||
GPIOA -> ODR |= (0x1 << 8);
|
||||
};
|
||||
|
||||
void TIM1_UP_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM1-> DIER &= ~TIM_DIER_TIE;
|
||||
//Reset bit
|
||||
GPIOA -> ODR &= ~(0x1 << 8);
|
||||
};
|
||||
26
Pilotes/Source/Servo.c
Normal file
26
Pilotes/Source/Servo.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "Servo.h"
|
||||
#include "DriverGPIO.h"
|
||||
#include "PWM.h"
|
||||
#include "Timer.h"
|
||||
|
||||
void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur
|
||||
int dutyCycle = (5* angle + 5*90)/90;
|
||||
PWM_Set_DutyCycle(Timer, Channel, dutyCycle);
|
||||
}
|
||||
|
||||
void initServo(TIM_TypeDef * Timer, int Channel){ // Config du moteur servo
|
||||
if (Timer == TIM4) {
|
||||
EnableTimer(TIM4);
|
||||
MyTimer_Base_Init(TIM4, 20000 - 1, 71); //Claire m'a
|
||||
if (Channel == 3){
|
||||
MyGPIO_Init(GPIOB, 8, AltOut_Ppull);
|
||||
}
|
||||
else{
|
||||
//printf("Cet pilôte n'existe pas");
|
||||
}
|
||||
}
|
||||
else{
|
||||
//printf("Cet pilôte n'existe pas");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue