Ajout girouette/bordage
This commit is contained in:
parent
e03f060a5a
commit
0669098ea8
4 changed files with 105 additions and 0 deletions
51
Services/Girouette.c
Normal file
51
Services/Girouette.c
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include <stm32f10x.h>
|
||||||
|
#include <Girouette.h>
|
||||||
|
#include <MyTimer.h>
|
||||||
|
#include <GPIO.h>
|
||||||
|
|
||||||
|
void (*Ptr_fct_girouette) (void);
|
||||||
|
|
||||||
|
void Timer_Counter (TIM_TypeDef *Timer) {
|
||||||
|
Timer->CCMR1 |= TIM_CCMR1_CC1S_0;
|
||||||
|
Timer->CCMR1 |= TIM_CCMR1_CC2S_0;
|
||||||
|
|
||||||
|
Timer->CCER &= ~(TIM_CCER_CC1P);
|
||||||
|
Timer->CCER &= ~(TIM_CCER_CC1NP);
|
||||||
|
Timer->CCMR1 &= ~(TIM_CCMR1_IC1F);
|
||||||
|
|
||||||
|
Timer->CCER &= ~(TIM_CCER_CC2P);
|
||||||
|
Timer->CCER &= ~(TIM_CCER_CC2NP);
|
||||||
|
Timer->CCMR1 &= ~(TIM_CCMR1_IC2F);
|
||||||
|
Timer->SMCR |= 0x0003;
|
||||||
|
Timer->CR1 |= TIM_CR1_CEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init_girouette (){
|
||||||
|
MyTimer_Init(TIM4, 1440, 1);
|
||||||
|
MyTimer_Base_Start(TIM4);
|
||||||
|
MyGPIO_Init(GPIOB, 6, In_Floating);
|
||||||
|
MyGPIO_Init(GPIOB, 7, In_Floating);
|
||||||
|
MyGPIO_Init(GPIOA, 12, In_Floating);
|
||||||
|
Init_Interrupt(3, LafonctGirouette);
|
||||||
|
Timer_Counter(TIM4);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fonctio girouette appeler pour l'interruption
|
||||||
|
void LafonctGirouette(){
|
||||||
|
TIM4->CNT = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init_Interrupt(char Prio, void (*IT_function) (void)){
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
|
||||||
|
AFIO->EXTICR[3] &= ~(0xF);
|
||||||
|
EXTI->IMR |= 1<<12;
|
||||||
|
EXTI->RTSR |= 1<<12;
|
||||||
|
NVIC->ISER[1] |= NVIC_ISER_SETENA_8; // exti 12 on s'est trompé mais normalement c'est bo mtn
|
||||||
|
Ptr_fct_girouette = IT_function;
|
||||||
|
NVIC->IPR[40] = Prio<<4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EXTI15_10_IRQHandler (){
|
||||||
|
EXTI->PR |= 1 << 12;
|
||||||
|
Ptr_fct_girouette();
|
||||||
|
}
|
||||||
15
Services/Girouette.h
Normal file
15
Services/Girouette.h
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef GIROUETTE_H
|
||||||
|
#define GIROUETTE_H
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
|
||||||
|
void Init_Interrupt(char Prio, void (*IT_function) (void));
|
||||||
|
|
||||||
|
void EXTI0_IRQHandler();
|
||||||
|
|
||||||
|
void LafonctGirouette ();
|
||||||
|
|
||||||
|
void Init_girouette ();
|
||||||
|
|
||||||
|
void LafonctGirouette();
|
||||||
|
#endif
|
||||||
30
Services/bordage.c
Normal file
30
Services/bordage.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
#include <GPIO.h>
|
||||||
|
#include <bordage.h>
|
||||||
|
#include <MyTimer.h>
|
||||||
|
|
||||||
|
void Init_bordage(TIM_TypeDef *Timer, char channel, unsigned short ValARR, unsigned short ValPSC){
|
||||||
|
MyTimer_Init(Timer,ValARR,ValPSC);
|
||||||
|
Mytimer_PWM(Timer, channel);
|
||||||
|
MyTimer_Base_Start(Timer);
|
||||||
|
MyGPIO_Init(GPIOA, 0, AltOut_Ppull);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update_bodage (TIM_TypeDef *Timer, char channel){
|
||||||
|
float val;
|
||||||
|
val = TIM4->CNT;
|
||||||
|
if (val <4.0*45.0 || val > 4.0*(360.0-45.0)) {
|
||||||
|
Mytimer_PWM_cycle(Timer, channel, 9);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (val <= 720.0) {
|
||||||
|
val/= -108.0;
|
||||||
|
val+= 35.0/3.0;
|
||||||
|
Mytimer_PWM_cycle(Timer, channel, (int) val);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
val/= 108.0;
|
||||||
|
val+= -5.0/3.0;
|
||||||
|
Mytimer_PWM_cycle(Timer, channel, (int) val);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Services/bordage.h
Normal file
9
Services/bordage.h
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef BORDAGE_H
|
||||||
|
#define BORDAGE_H
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
void Init_bordage(TIM_TypeDef *Timer, char channel, unsigned short ValARR, unsigned short ValPSC);
|
||||||
|
|
||||||
|
void Update_bodage (TIM_TypeDef *Timer, char channel);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in a new issue