Changement batterie et transmission
This commit is contained in:
parent
9bda2e8891
commit
30b6ef8c92
7 changed files with 63 additions and 22 deletions
|
|
@ -14,22 +14,33 @@ void MyBatterie_Init(void){
|
||||||
MyADC_Init(ADC1,14); // Init ADC channel 14 pour convertir valeur
|
MyADC_Init(ADC1,14); // Init ADC channel 14 pour convertir valeur
|
||||||
MyADC_ActiveIT(ADC1,15,&handler_ADC); // Init interruption quand conversion finie
|
MyADC_ActiveIT(ADC1,15,&handler_ADC); // Init interruption quand conversion finie
|
||||||
|
|
||||||
My_USART_Init(USART1); // Init USART pour envoyer batterie
|
//My_USART_Init(USART1); // Init USART pour envoyer batterie
|
||||||
|
|
||||||
start_conversion(ADC1); // Premiere conversion
|
start_conversion(ADC1); // Premiere conversion
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler_ADC (void){
|
void handler_ADC (void){
|
||||||
//last2++;
|
//last2++;
|
||||||
if (tickms - last2 >= 2000) {
|
//if (tickms - last2 >= 2000) {
|
||||||
last2 = tickms;
|
//last2 = tickms;
|
||||||
d = ADC1->DR &~ (0xF << 12); // Retourne valeur numérique
|
d = ADC1->DR &~ (0xF << 12); // Retourne valeur numérique
|
||||||
d = d*3.3/4096;
|
d = d*3.3/4096;
|
||||||
d = d*13*100/12;
|
d = d*13*100/12;
|
||||||
send_USART_String(USART1,"Batterie : ");
|
//send_USART_String(USART1,"Batterie : ");
|
||||||
send_USART(USART1,((int)d/10) + '0'); // Envoie le chiffre des dizaines
|
//send_USART(USART1,((int)d/10) + '0'); // Envoie le chiffre des dizaines
|
||||||
send_USART(USART1,((int)d%10) + '0'); // Envoie le chiffre des unités
|
//send_USART(USART1,((int)d%10) + '0'); // Envoie le chiffre des unités
|
||||||
send_USART_String(USART1,"%\n");
|
//send_USART_String(USART1,"%\n");
|
||||||
|
//}
|
||||||
|
//start_conversion(ADC1); // Recommence la conversion pour le prochain
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gestion_Conversion_ADC(void){
|
||||||
|
if (tickms - last2 >= 1000) {
|
||||||
|
last2 = tickms;
|
||||||
|
start_conversion(ADC1);
|
||||||
}
|
}
|
||||||
start_conversion(ADC1); // Recommence la conversion pour le prochain
|
}
|
||||||
|
|
||||||
|
int MyBatterie_val(){
|
||||||
|
return (int)d;
|
||||||
}
|
}
|
||||||
|
|
@ -5,5 +5,7 @@
|
||||||
|
|
||||||
void MyBatterie_Init(void);
|
void MyBatterie_Init(void);
|
||||||
void handler_ADC(void);
|
void handler_ADC(void);
|
||||||
|
void Gestion_Conversion_ADC(void);
|
||||||
|
int MyBatterie_val();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
extern uint32_t tickms;
|
extern uint32_t tickms;
|
||||||
uint32_t last1 = 0;
|
uint32_t last1 = 0;
|
||||||
|
uint32_t last3 = 0;
|
||||||
|
|
||||||
void Transmission_Init(void){
|
void Transmission_Init(void){
|
||||||
My_USART_Init(USART1);
|
My_USART_Init(USART1);
|
||||||
|
|
@ -20,4 +21,19 @@ void Transmission_allure(int angle_voiles){
|
||||||
else if (angle_voiles <= 90) send_USART_String(USART1,"Le bateau navigue vent arriere. \n");
|
else if (angle_voiles <= 90) send_USART_String(USART1,"Le bateau navigue vent arriere. \n");
|
||||||
else send_USART_String(USART1,"ERREUR DANS L'ANGLE!! \n");
|
else send_USART_String(USART1,"ERREUR DANS L'ANGLE!! \n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transmission_batterie(int batterie){
|
||||||
|
if (tickms-last3 >= 5000){
|
||||||
|
last3 = tickms;
|
||||||
|
if(batterie > 50){
|
||||||
|
send_USART_String(USART1,"Batterie : ");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
send_USART_String(USART1, "ATTENTION LA BATTERIE EST SOUS LES 50% : ");
|
||||||
|
}
|
||||||
|
send_USART(USART1,(batterie/10) + '0'); // Envoie le chiffre des dizaines
|
||||||
|
send_USART(USART1,(batterie%10) + '0'); // Envoie le chiffre des unités
|
||||||
|
send_USART_String(USART1,"%\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,5 +3,6 @@
|
||||||
|
|
||||||
void Transmission_Init(void);
|
void Transmission_Init(void);
|
||||||
void Transmission_allure(int angle_voiles);
|
void Transmission_allure(int angle_voiles);
|
||||||
|
void Transmission_batterie(int batterie);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -37,11 +37,6 @@ void MyRoulis_Init(void){
|
||||||
void MyRoulis_Data(void){
|
void MyRoulis_Data(void){
|
||||||
|
|
||||||
// Récupération des registred DATAX0..DATAZ1 (6 registres)
|
// Récupération des registred DATAX0..DATAZ1 (6 registres)
|
||||||
// MySPI_Clear_NSS(); // Début transmission X
|
|
||||||
// MySPI_Send((0x32)|(0<<7)|(1<<6)); // On veut lire les 2 bytes DATAX
|
|
||||||
// x1 = MySPI_Read(); // premier byte
|
|
||||||
// x2 = MySPI_Read(); // deuxième byte
|
|
||||||
// MySPI_Set_NSS(); // Fin transmission X
|
|
||||||
|
|
||||||
MySPI_Clear_NSS(); // Début transmission Y
|
MySPI_Clear_NSS(); // Début transmission Y
|
||||||
MySPI_Send((0x34)|(1<<7)|(1<<6)); // On veut lire les 2 bytes DATAY
|
MySPI_Send((0x34)|(1<<7)|(1<<6)); // On veut lire les 2 bytes DATAY
|
||||||
|
|
@ -58,11 +53,10 @@ void MyRoulis_Data(void){
|
||||||
|
|
||||||
float MyRoulis_Angle(){
|
float MyRoulis_Angle(){
|
||||||
//Calcul de l'angle alpha
|
//Calcul de l'angle alpha
|
||||||
//int x = x1 + (x2 << 8);
|
|
||||||
y = y1 + (y2 << 8);
|
y = y1 + (y2 << 8);
|
||||||
z = z1 + (z2 << 8);
|
z = z1 + (z2 << 8);
|
||||||
a = (float)z*32.0/(float)(1<<10);
|
a = (float)z*32.0/(float)(1<<10); // Doit être compris entre -1 et 1
|
||||||
b = (float)y*32.0/(float)(1<<10);
|
b = (float)y*32.0/(float)(1<<10); // Egalement : Pour vérifier que l'on récupère des valeurs cogérentes
|
||||||
alpha = atan((float)y/(float)z);
|
alpha = atan((float)y/(float)z);
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
|
|
@ -8,13 +8,15 @@ void MyADC_Init(ADC_TypeDef *ADC, char channel){
|
||||||
else if (ADC == ADC2) RCC->APB2ENR |= RCC_APB2ENR_ADC2EN;
|
else if (ADC == ADC2) RCC->APB2ENR |= RCC_APB2ENR_ADC2EN;
|
||||||
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; // Passage de l'horloge a 12MHz
|
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; // Passage de l'horloge a 12MHz
|
||||||
ADC->CR2 |= ADC_CR2_ADON; // Démarrage ADC
|
ADC->CR2 |= ADC_CR2_ADON; // Démarrage ADC
|
||||||
ADC->SQR1 &= ADC_SQR1_L; // Fixe nb de conversion à faire : 1
|
ADC->SQR1 &=~ ADC_SQR1_L; // Fixe nb de conversion à faire : 1
|
||||||
ADC->SQR3 = channel; // Fixe la voie à convertir
|
ADC->SQR3 = channel; // Fixe la voie à convertir
|
||||||
|
ADC->CR2 |= ADC_CR2_EXTTRIG;
|
||||||
|
ADC->CR2 |= ADC_CR2_EXTSEL_0 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_conversion(ADC_TypeDef *ADC){
|
void start_conversion(ADC_TypeDef *ADC){
|
||||||
ADC->CR2 |= ADC_CR2_EXTSEL;
|
//ADC->CR2 |= ADC_CR2_EXTSEL;
|
||||||
ADC->CR2 |= ADC_CR2_EXTTRIG; // Permettre le démarage externe
|
//ADC->CR2 |= ADC_CR2_EXTTRIG; // Permettre le démarage externe
|
||||||
ADC->CR2 |= ADC_CR2_SWSTART; // demander une conversion externe
|
ADC->CR2 |= ADC_CR2_SWSTART; // demander une conversion externe
|
||||||
//Si on veut faire par scrutation et non par intéruption, laisser les lignes suivantes
|
//Si on veut faire par scrutation et non par intéruption, laisser les lignes suivantes
|
||||||
//while(!(ADC->SR & ADC_SR_EOC)); // attendre la fin (EOC = 1)
|
//while(!(ADC->SR & ADC_SR_EOC)); // attendre la fin (EOC = 1)
|
||||||
|
|
|
||||||
21
readme.txt
21
readme.txt
|
|
@ -21,8 +21,23 @@ prio interruption timer2 : 0
|
||||||
Batterie :
|
Batterie :
|
||||||
|
|
||||||
?PC4 : Floating input (ADC12 CHANNEL14)
|
?PC4 : Floating input (ADC12 CHANNEL14)
|
||||||
!PA9 : Alternate output push pull (UART1 TX)
|
|
||||||
prio interruption ADC : 15
|
prio interruption ADC : 15
|
||||||
|
|
||||||
Fonctionnement de la batterie okay, il faut voir quand est-ce qu'on recommence la conversion ou quand est-ce qu'on envoie la batterie.
|
|
||||||
Il faudrait vérifier le driver SPI qui ne fonctionne pas.
|
Transmission :
|
||||||
|
|
||||||
|
!PA9 : Alternate output push pull (UART1 TX)
|
||||||
|
Transmet allure du bateau et batterie à UART
|
||||||
|
|
||||||
|
|
||||||
|
Systick :
|
||||||
|
|
||||||
|
Créer un timer qui compte par ms avec systick du systeme
|
||||||
|
|
||||||
|
|
||||||
|
Le service plateau envoie la PWM et le bit de sens en permanence
|
||||||
|
Le service roulis renvoie l'angle de roulis
|
||||||
|
Le service batterie permet maintenant de renvoyer la batterie, nouvelle conversion toutes les Xms
|
||||||
|
Le service transmission utilise la valeur de la batterie et la valeur de l'angle des voiles pour envoyer à UART toutes les Xms
|
||||||
|
|
||||||
|
Le SPI ne marche toujours pas
|
||||||
Loading…
Reference in a new issue