chti23_grpe_genty_pitault/soft/PjtKEIL_Fin/Src/principal.c
2023-05-22 12:11:20 +02:00

72 lines
1.9 KiB
C

#include "DriverJeuLaser.h"
#include "GestionSon.h"
extern int DFT_ModuleAuCarre(short int* Signal64ech, char k);
extern int16_t LeSignal;
unsigned int test = 0;
short int dma_buf[64];
int coeff[7];
int score[6];
int attendre[6];
void mesure() {
Start_DMA1(64);
Wait_On_End_Of_DMA1();
Stop_DMA1;
coeff[0] = DFT_ModuleAuCarre(&(dma_buf[0]), 17);
coeff[1] = DFT_ModuleAuCarre(&(dma_buf[0]), 18);
coeff[2] = DFT_ModuleAuCarre(&(dma_buf[0]), 19);
coeff[3] = DFT_ModuleAuCarre(&(dma_buf[0]), 20);
coeff[4] = DFT_ModuleAuCarre(&(dma_buf[0]), 23);
coeff[5] = DFT_ModuleAuCarre(&(dma_buf[0]), 24);
coeff[6] = DFT_ModuleAuCarre(&(dma_buf[0]), 21);
}
int main(void)
{
// ===========================================================================
// ============= INIT PERIPH (faites qu'une seule fois) =====================
// ===========================================================================
// Après exécution : le coeur CPU est clocké à 72MHz ainsi que tous les timers
CLOCK_Configure();
Init_TimingADC_ActiveADC_ff(ADC1, 72);
Single_Channel_ADC(ADC1, 2);
Init_Conversion_On_Trig_Timer_ff(ADC1, TIM2_CC2, 225);
Init_ADC1_DMA1(0, dma_buf);
Systick_Period_ff(72000000 * 5 / 1000);
Systick_Prio_IT(0, mesure);
SysTick_On;
SysTick_Enable_IT;
GPIO_Configure(GPIOB, 0, OUTPUT, ALT_PPULL);
PWM_Init_ff(TIM3, 3, 720); // f_PWM = 72MHz/720 = 100kHz
Timer_1234_Init_ff(TIM4, 6552); // periode_son/f_CPU = (91*10^-6)*(72*10^6) = 6552
Active_IT_Debordement_Timer(TIM4, 2, CallbackSon);
//============================================================================
for (int i = 0; i < 6; i++) {
score[i] = 0;
attendre[i] = 0;
}
while (1)
{
if (coeff[6] < 10000000)
for (int i = 0; i < 6; i++) {
if (attendre[i] == 0 && coeff[i] > 10000000) {
StartSon();
score[i]++;
attendre[i] = 1;
}
else if (attendre[i] == 1 && coeff[i] < 10000000)
attendre[i] = 0;
}
}
}