Batterie v1
This commit is contained in:
parent
9e198138da
commit
af2ac44314
5 changed files with 40 additions and 8 deletions
22
Services/Batterie.c
Normal file
22
Services/Batterie.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#include <stm32f10x.h>
|
||||||
|
#include <Batterie.h>
|
||||||
|
#include <GPIO.h>
|
||||||
|
#include <ADC.h>
|
||||||
|
#include <USART.h>
|
||||||
|
|
||||||
|
int a;
|
||||||
|
|
||||||
|
void MyBatterie_Init(void){
|
||||||
|
MyGPIO_Init(GPIOC,4,In_Floating); // Init PORT pour recevoir tension
|
||||||
|
MyADC_Init(ADC1,14); // Init ADC pour convertir valeur
|
||||||
|
My_USART_Init(USART2); // Init USART pour envoyer batterie
|
||||||
|
MyGPIO_Init(GPIOA,2,AltOut_Ppull); // Init PORT pour envoyer pourcentage batterie
|
||||||
|
MyADC_ActiveIT(ADC1,15,&handler_ADC); // Init interruption quand conversion finie
|
||||||
|
}
|
||||||
|
|
||||||
|
void handler_ADC (void){
|
||||||
|
a = ADC1->DR &~ (0xF << 12); // Retourne valeur numérique
|
||||||
|
send_USART(USART2,a*13*100/12); // Envoie la valeur numérique*13
|
||||||
|
send_USART(USART2,'%');
|
||||||
|
start_conversion(ADC1); // Recommence la conversion pour le prochain
|
||||||
|
}
|
||||||
7
Services/Batterie.h
Normal file
7
Services/Batterie.h
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef MYBATTERIE_H
|
||||||
|
#define MYBATTERIE_H
|
||||||
|
|
||||||
|
void MyBatterie_Init(void);
|
||||||
|
void handler_ADC(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -53,11 +53,11 @@ void MyRoulis_Data(void){
|
||||||
MySPI_Set_NSS(); // Fin transmission Z
|
MySPI_Set_NSS(); // Fin transmission Z
|
||||||
}
|
}
|
||||||
|
|
||||||
float MyRoulis_Angle(){
|
int MyRoulis_Angle(){
|
||||||
//Calcul de l'angle alpha
|
//Calcul de l'angle alpha
|
||||||
//int x = x1 + (x2 << 8);
|
//int x = x1 + (x2 << 8);
|
||||||
int y = y1 + (y2 << 8);
|
int y = y1 + (y2 << 8);
|
||||||
int z = z1 + (z2 << 8);
|
int z = z1 + (z2 << 8);
|
||||||
float alpha = atan(y / z); //sqrtf(x*x + y*y)
|
int alpha = atan(y / z); //sqrtf(x*x + y*y)
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
|
|
@ -9,6 +9,6 @@ Ou sinon sur interruption d'un timer a 100HZ
|
||||||
|
|
||||||
void MyRoulis_Init(void);
|
void MyRoulis_Init(void);
|
||||||
void MyRoulis_Data(void);
|
void MyRoulis_Data(void);
|
||||||
float MyRoulis_Angle();
|
int MyRoulis_Angle();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
13
readme.txt
13
readme.txt
|
|
@ -1,4 +1,4 @@
|
||||||
Il faut vérifier le driver SPI sur carte et finir roulis
|
Driver SPI normalement bon, roulis a tester
|
||||||
|
|
||||||
Port map carte nucléo :
|
Port map carte nucléo :
|
||||||
|
|
||||||
|
|
@ -6,13 +6,13 @@ Plateau :
|
||||||
|
|
||||||
Timer 3 (channel 3)
|
Timer 3 (channel 3)
|
||||||
? PA1 : Output push pull (bit sens)
|
? PA1 : Output push pull (bit sens)
|
||||||
! PA9 : Alternate output push pull (ligne TX UART1, not used)
|
! PA9 : Alternate output push pull (UART1 TX, not used)
|
||||||
! PA10 : Floating input (ligne RX UART1)
|
! PA10 : Floating input (lUART1 RX)
|
||||||
! PB0 : Alternate output push pull (PWM)
|
! PB0 : Alternate output push pull (PWM)
|
||||||
prio interruption usart1 : 6
|
prio interruption usart1 : 6
|
||||||
|
|
||||||
|
|
||||||
SPI / roulis :
|
Roulis :
|
||||||
|
|
||||||
! PA4 : Output push pull (SPI1 NSS)
|
! PA4 : Output push pull (SPI1 NSS)
|
||||||
! PA5 : Alternate output push pull (SPI1 SCK)
|
! PA5 : Alternate output push pull (SPI1 SCK)
|
||||||
|
|
@ -20,4 +20,7 @@ SPI / roulis :
|
||||||
! PA7 : Alternate output push pull (SPI1 MOSI)
|
! PA7 : Alternate output push pull (SPI1 MOSI)
|
||||||
prio interruption timer2 : 0
|
prio interruption timer2 : 0
|
||||||
|
|
||||||
Pour le roulis, je ne suis pas sur de comment retourner l'angle , il faut vérifier que le calcul soit bon aussi
|
Batterie :
|
||||||
|
|
||||||
|
?PC4 : Floating input (ADC12 CHANNEL14)
|
||||||
|
!PA2 : Alternate output push pull (UART2 TX)
|
||||||
Loading…
Reference in a new issue