diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index fad46b2..040c6c6 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -345,7 +345,7 @@
0
DLGDARM
- (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=1554,213,1920,450,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=-1,-1,-1,-1,0)(121=1509,217,1920,660,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=1336,105,1920,897,0)(133=1148,116,1732,908,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=915,87,1508,879,0)(151=-1,-1,-1,-1,0)
+ (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=1554,213,1920,450,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=129,555,687,1080,0)(121=1509,217,1920,660,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=150,46,938,969,0)(133=1148,116,1732,908,0)(160=1046,190,1640,699,1)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=130,96,930,1019,0)(151=127,38,927,961,0)
0
@@ -382,9 +382,25 @@
0
0
- 84
+ 20
1
- 134226236
+ 134226220
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ..\Services\RFEmitter.c
+
+ \\NUCLEO_F103RB\../Services/RFEmitter.c\20
+
+
+ 1
+ 0
+ 43
+ 1
+ 134231406
0
0
0
@@ -393,14 +409,62 @@
1
../Src/main.c
- \\NUCLEO_F103RB\../Src/main.c\84
+ \\NUCLEO_F103RB\../Src/main.c\43
+
+
+ 2
+ 0
+ 82
+ 1
+ 134231536
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ../Src/main.c
+
+ \\NUCLEO_F103RB\../Src/main.c\82
+
+
+ 3
+ 0
+ 44
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ ../Src/main.c
+
+
+
+
+ 4
+ 0
+ 87
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ ../Src/main.c
+
+
0
1
- counter,0x10
+ msCounter,0x0A
1
@@ -417,6 +481,31 @@
1
angle,0x0A
+
+ 4
+ 1
+ displayStr
+
+
+ 5
+ 1
+ adcStatus
+
+
+ 6
+ 1
+ val1
+
+
+ 7
+ 1
+ val2
+
+
+ 8
+ 1
+ message
+
0
@@ -424,7 +513,7 @@
0
1
- 1
+ 0
0
0
0
@@ -438,7 +527,7 @@
0
0
0
- 1
+ 0
0
0
0
@@ -464,9 +553,19 @@
0
((PORTB & 0x00000100) >> 8 & 0x100) >> 8
- FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254422026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1300000000000000000000000000000000000000AE110008
+ FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254422026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1700000000000000000000000000000000000000AE110008
+
+
+ System Viewer\ADC1
+ 35904
+
+
+ System Viewer\ADC2
+ 35905
+
+
1
0
@@ -603,7 +702,7 @@
2
10
1
- 0
+ 1
0
0
..\Services\RFEmitter.c
diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx
index 04a36be..254be84 100644
--- a/MDK-ARM/Project.uvprojx
+++ b/MDK-ARM/Project.uvprojx
@@ -185,7 +185,6 @@
0
0
0
- 0
0
0
8
@@ -352,7 +351,7 @@
0
0
0
- 4
+ 0
@@ -559,7 +558,7 @@
Simulateur
0x4
ARM-ADS
- 5060750::V5.06 update 6 (build 750)::.\ARMCC
+ 5060750::V5.06 update 6 (build 750)::ARMCC
0
@@ -734,7 +733,6 @@
0
0
0
- 0
0
0
8
@@ -901,7 +899,7 @@
0
0
0
- 4
+ 0
@@ -1120,19 +1118,4 @@
-
-
-
- <Project Info>
-
-
-
-
-
- 0
- 1
-
-
-
-
diff --git a/MyDrivers/ADC.c b/MyDrivers/ADC.c
index de5b8a5..d8c7ba0 100644
--- a/MyDrivers/ADC.c
+++ b/MyDrivers/ADC.c
@@ -18,8 +18,6 @@ void ADC_conf(ADC_TypeDef *adc)
// Fixe le nombre de conversion à 1
adc->SQR1 &= ADC_SQR1_L;
-
-
// Calibration
adc->CR2 |= ADC_CR2_CAL_Msk;
while ((adc->CR2 & ADC_CR2_CAL_Msk));
@@ -31,16 +29,15 @@ void ADC_start(ADC_TypeDef *adc)
adc->CR2 |= ADC_CR2_ADON;
}
-
uint16_t ADC_readRaw(ADC_TypeDef *adc, int channel)
{
// Indique la voie a convertir
adc->SQR3 = channel;
// Lancement de la conversion
adc->CR2 |= ADC_CR2_ADON;
- while(!(ADC1->SR & ADC_SR_EOC)) {}
+ while(!(adc->SR & ADC_SR_EOC)) {}
- return ADC1->DR & ADC_DR_DATA_Msk;
+ return adc->DR & ADC_DR_DATA_Msk;
}
diff --git a/Services/RFEmitter.c b/Services/RFEmitter.c
index c20e91d..02c7c64 100644
--- a/Services/RFEmitter.c
+++ b/Services/RFEmitter.c
@@ -1,7 +1,11 @@
#include "RFEmitter.h"
+#include "GPIO.h"
-void RFEmitter_conf(USART_TypeDef * usart)
+void RFEmitter_conf(USART_TypeDef * usart, GPIO_TypeDef *gpioTXEnable, int pinTXEnable)
{
+ // Configuration du pin TXEnable
+ GPIO_conf(gpioTXEnable, pinTXEnable, LL_GPIO_MODE_OUTPUT, LL_GPIO_OUTPUT_PUSHPULL, 0);
+ // Configuration de l'USART
Usart_conf(usart);
}
@@ -10,7 +14,15 @@ void RFEmitter_start(USART_TypeDef * usart)
Usart_enable(usart);
}
-void RFEmitter_send(USART_TypeDef * usart, char * message, int longueur)
+void RFEmitter_send(USART_TypeDef * usart, char * message, int longueur, GPIO_TypeDef *gpioTXEnable, int pinTXEnable)
{
+ // set PA11 (TXEnable)
+ GPIO_setPin(gpioTXEnable, pinTXEnable, 1);
+
+ // Envoi du message
Usart_send(usart, message, longueur);
+
+ // reset PA11 (TXEnable)
+ GPIO_setPin(gpioTXEnable, pinTXEnable, 0);
+
}
diff --git a/Services/RFEmitter.h b/Services/RFEmitter.h
index 29ac108..3a8ab43 100644
--- a/Services/RFEmitter.h
+++ b/Services/RFEmitter.h
@@ -3,11 +3,11 @@
#include "USART.h"
-void RFEmitter_conf(USART_TypeDef * usart);
+void RFEmitter_conf(USART_TypeDef * usart, GPIO_TypeDef *gpioTXEnable, int pinTXEnable);
void RFEmitter_start(USART_TypeDef * usart);
-void RFEmitter_send(USART_TypeDef * usart, char * message, int longueur);
+void RFEmitter_send(USART_TypeDef * usart, char * message, int longueur, GPIO_TypeDef *gpioTXEnable, int pinTXEnable);
#endif
diff --git a/Services/Voltage.c b/Services/Voltage.c
index abeb27d..8e11b63 100644
--- a/Services/Voltage.c
+++ b/Services/Voltage.c
@@ -17,5 +17,6 @@ void Voltage_start(ADC_TypeDef * adc)
float Voltage_getVoltage(ADC_TypeDef * adc, int channel)
{
- return ADC_readVolt(adc, channel);
+ // 13 * la valeur de l'ADC, car pont diviseur de tension en amont de l'ADC
+ return 13.0f * ADC_readVolt(adc, channel);
}
diff --git a/Src/Display.c b/Src/Display.c
index 9ae682f..f0ff35b 100644
--- a/Src/Display.c
+++ b/Src/Display.c
@@ -1,18 +1,23 @@
#include "Display.h"
#include "Voltage.h"
#include "RFEmitter.h"
+#include "Sail.h"
+#include "stdio.h"
+#include "string.h"
USART_TypeDef * EMITTER_USART = USART1;
+GPIO_TypeDef * EMITTER_GPIO = GPIOA;
+const int EMITTER_PIN = LL_GPIO_PIN_11;
ADC_TypeDef * VOLTAGE_ADC = ADC2;
-const int VOLTAGE_CHANNEL = LL_ADC_CHANNEL_12;
+const int VOLTAGE_CHANNEL = 12;
GPIO_TypeDef * VOLTAGE_GPIO = GPIOC;
const int VOLTAGE_PIN = LL_GPIO_PIN_2;
void Display_conf()
{
Voltage_conf(VOLTAGE_ADC, VOLTAGE_GPIO, VOLTAGE_PIN);
- RFEmitter_conf(EMITTER_USART);
+ RFEmitter_conf(EMITTER_USART, EMITTER_GPIO, EMITTER_PIN);
}
void Display_start()
@@ -21,7 +26,30 @@ void Display_start()
RFEmitter_start(EMITTER_USART);
}
-void Display_background()
+
+void Display_background(int secCounter)
{
- float voltage = Voltage_getVoltage(ADC2, LL_ADC_CHANNEL_12);
+ static int previousEmergencyState = 0;
+ static int prevSendSec = 0;
+
+ const int emergency = Sail_getEmergencyState();
+
+ if (secCounter - prevSendSec == 3 || (emergency && !previousEmergencyState)) {
+ prevSendSec = secCounter;
+
+ const float voltage = Voltage_getVoltage(VOLTAGE_ADC, VOLTAGE_CHANNEL);
+ const int sailAngle = Sail_getSailAngle();
+ const int relativeAngle = sailAngle >= 180 ? 360 - sailAngle : sailAngle;
+ const int sailPercent = (90 - relativeAngle) * 100 / 90;
+
+ char displayStr[100];
+
+ sprintf(displayStr, "Bordage actuel = %d%%\nTension de la batterie = %fV\n", sailPercent, voltage);
+ if (emergency)
+ sprintf(displayStr, "Limite de roulis atteinte !\n%s", displayStr);
+
+ RFEmitter_send(EMITTER_USART, displayStr, strlen(displayStr), EMITTER_GPIO, EMITTER_PIN);
+ }
+
+ previousEmergencyState = emergency;
}
diff --git a/Src/Display.h b/Src/Display.h
index c11ac27..9d2dad2 100644
--- a/Src/Display.h
+++ b/Src/Display.h
@@ -5,6 +5,6 @@ void Display_conf(void);
void Display_start(void);
-void Display_background(void);
+void Display_background(int msCounter);
#endif
diff --git a/Src/Roll.c b/Src/Roll.c
index 05a39b9..d1154e8 100644
--- a/Src/Roll.c
+++ b/Src/Roll.c
@@ -3,9 +3,9 @@
#include "Accelerometer.h"
#include "stdlib.h"
-ADC_TypeDef * ROLL_ADC = ADC1;
-const int ROLL_X_CHANNEL = LL_ADC_CHANNEL_11;
-const int ROLL_Y_CHANNEL = LL_ADC_CHANNEL_10;
+ADC_TypeDef * ROLL_ADC = ADC2;
+const int ROLL_X_CHANNEL = 11;
+const int ROLL_Y_CHANNEL = 10;
GPIO_TypeDef * ROLL_GPIO = GPIOC;
const int ROLL_X_PIN = LL_GPIO_PIN_0;
const int ROLL_Y_PIN = LL_GPIO_PIN_1;
diff --git a/Src/Sail.c b/Src/Sail.c
index ced4b71..97553f8 100644
--- a/Src/Sail.c
+++ b/Src/Sail.c
@@ -28,7 +28,7 @@ void Sail_start()
IncrementalEncoder_start(ENCODER_TIMER);
}
-int getSailAngle(int windAngle)
+int windToSailAngle(int windAngle)
{
if (windAngle > 180)
return 90 * (windAngle - 45) / 135;
@@ -36,6 +36,12 @@ int getSailAngle(int windAngle)
return 360 - 90 * ((360 - windAngle) - 45) / 135;
}
+int Sail_getSailAngle(void)
+{
+ return ServoMotor_getAngle(MOTOR_TIMER, MOTOR_CHANNEL);
+}
+
+
void Sail_background()
{
if (Sail_isEmergencyState)
@@ -46,7 +52,7 @@ void Sail_background()
if (windAngle < 45 || windAngle > 315)
ServoMotor_setAngle(MOTOR_TIMER, MOTOR_CHANNEL, 0);
else
- ServoMotor_setAngle(MOTOR_TIMER, MOTOR_CHANNEL, getSailAngle(windAngle));
+ ServoMotor_setAngle(MOTOR_TIMER, MOTOR_CHANNEL, windToSailAngle(windAngle));
}
void Sail_setEmergency(int state)
@@ -55,3 +61,8 @@ void Sail_setEmergency(int state)
if (Sail_isEmergencyState)
ServoMotor_setAngle(MOTOR_TIMER, MOTOR_CHANNEL, RESET_ANGLE);
}
+
+int Sail_getEmergencyState()
+{
+ return Sail_isEmergencyState;
+}
diff --git a/Src/Sail.h b/Src/Sail.h
index 1973501..46c3851 100644
--- a/Src/Sail.h
+++ b/Src/Sail.h
@@ -25,6 +25,10 @@ void Sail_background(void);
*/
void Sail_setEmergency(int state);
+int Sail_getEmergencyState(void);
+
+int Sail_getSailAngle(void);
+
/**
* @brief Réinitialise la voile à sa position initiale
* @note
diff --git a/Src/main.c b/Src/main.c
index 166fdcd..de97676 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -29,44 +29,34 @@
#include "ADC.h"
#include "GPIO.h"
#include "Accelerometer.h"
+#include "RFEmitter.h"
+#include "stdio.h"
void SystemClock_Config(void);
+int secCounter = 0;
+
/* Private functions ---------------------------------------------------------*/
-int counter = 1;
-int adcRaw1 = 0;
-int adcRaw2 = 0;
-double adcVolt1 = 0.0;
-double adcVolt2 = 0.0;
-
-int angle = 0;
-
void backgroundTask()
{
- counter++;
+ static int msCounter;
+ msCounter++;
+ if (msCounter == 1000) {
+ msCounter = 0;
+ secCounter++;
+ }
Sail_background();
Roll_background();
Orientation_background();
-
-
- // DEBUG
- angle = Accelerometer_getAngle(ADC1, LL_ADC_CHANNEL_11);
-
- adcRaw1 = ADC_readRaw(ADC1, LL_ADC_CHANNEL_11);
- adcRaw2 = ADC_readRaw(ADC1, LL_ADC_CHANNEL_10);
- adcVolt1 = ADC_convertToVolt(adcRaw1);
- adcVolt2 = ADC_convertToVolt(adcRaw2);
}
void configurePeripherals()
{
Sail_conf();
Roll_conf();
+ Display_conf();
Orientation_conf();
-
- // DEBUG
- ADC_conf(ADC1);
}
void startPeripherals()
@@ -74,9 +64,6 @@ void startPeripherals()
Sail_start();
Roll_start();
Display_start();
-
- // DEBUG
- ADC_start(ADC1);
}
/**
@@ -85,7 +72,7 @@ void startPeripherals()
* @retval None
*/
int main(void)
-{
+{
/* Configure the system clock to 72 MHz */
SystemClock_Config();
@@ -97,8 +84,24 @@ int main(void)
Scheduler_start();
while (1) {
- Display_background();
+ Display_background(secCounter);
}
+
+
+//// ADC 2 marche niquel, ADC1 ne marche pas :(
+// ADC_conf(ADC1);
+// ADC_start(ADC1);
+//
+// ADC_conf(ADC2);
+// ADC_start(ADC2);
+
+//
+// while (1) {
+// val1 = ADC_readRaw(ADC1, 10);
+// val2 = ADC_readRaw(ADC2, 10);
+// }
+
+
}
@@ -177,8 +180,8 @@ void SystemClock_Config(void)
*/
void assert_failed(uint8_t *file, uint32_t line)
{
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d", file, line) */
+ /* User can add his own implementation to report the file name and line number*/
+ printf("Wrong parameters value: file %s on line %d", file, line);
/* Infinite loop */
while (1)