107 lines
2.6 KiB
C
107 lines
2.6 KiB
C
#include "gassp72.h"
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <stdio.h>
|
|
#include "etat.h"
|
|
|
|
#define TAILLE 6
|
|
#define periode_tick_pwm 360 // (360000 ticks équivaut à 5ms)
|
|
#define SYSTICK_PER 360000 // (360000 ticks équivaut à 5ms)
|
|
#define M2TIR 985988
|
|
|
|
extern short Son[];
|
|
extern void timer_callback(void);
|
|
extern int LongueurSon;
|
|
extern int PeriodeSonMicroSec;
|
|
|
|
|
|
extern short TabSig[];
|
|
|
|
extern int calcul_carre(int);
|
|
extern int calcul_dft(unsigned short *, int);
|
|
|
|
int res_dft = 0;
|
|
unsigned short dma_buf[64];
|
|
int compteurs[TAILLE];
|
|
int scores[TAILLE];
|
|
int k_values[] = {17,18,19,20,23,24};
|
|
|
|
type_etat etat;
|
|
|
|
|
|
void checkCounter(void){
|
|
for(int i=0; i<TAILLE; i++) {
|
|
if(compteurs[i] >= 13){
|
|
compteurs[i]=0;
|
|
scores[i]++;
|
|
etat.position = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
void sys_callback(void){
|
|
// Démarrage DMA pour 64 points
|
|
Start_DMA1(64);
|
|
Wait_On_End_Of_DMA1();
|
|
Stop_DMA1;
|
|
|
|
for(int i=0; i<TAILLE; i++){
|
|
res_dft = calcul_dft(dma_buf, k_values[i]);
|
|
if(res_dft > M2TIR){
|
|
compteurs[i]++;
|
|
}else{
|
|
compteurs[i] = 0;
|
|
}
|
|
}
|
|
|
|
checkCounter();
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
|
|
// activation de la PLL qui multiplie la fréquence du quartz par 9
|
|
CLOCK_Configure();
|
|
|
|
// config port PB0 pour être utilisé par TIM3-CH3
|
|
GPIO_Configure(GPIOB, 0, OUTPUT, ALT_PPULL);
|
|
// config TIM3-CH3 en mode PWM
|
|
etat.resolution = PWM_Init_ff( TIM3, 3, periode_tick_pwm);
|
|
|
|
etat.taille = LongueurSon;
|
|
etat.periode_ticks = PeriodeSonMicroSec*72;
|
|
etat.son = Son;
|
|
etat.position = 0;
|
|
|
|
// initialisation du timer 4
|
|
// Periode_en_Tck doit fournir la durée entre interruptions,
|
|
// exprimée en périodes Tck de l'horloge principale du STM32 (72 MHz)
|
|
Timer_1234_Init_ff( TIM4, etat.periode_ticks);
|
|
// enregistrement de la fonction de traitement de l'interruption timer
|
|
// ici le 2 est la priorité, timer_callback est l'adresse de cette fonction, a créér en asm,
|
|
// cette fonction doit être conforme à l'AAPCS
|
|
Active_IT_Debordement_Timer( TIM4, 2, timer_callback );
|
|
// lancement du timer
|
|
Run_Timer( TIM4 );
|
|
|
|
|
|
// activation ADC, sampling time 1us
|
|
Init_TimingADC_ActiveADC_ff( ADC1, 0x33 );
|
|
Single_Channel_ADC( ADC1, 2 );
|
|
// Déclenchement ADC par timer2, periode (72MHz/320kHz)ticks
|
|
Init_Conversion_On_Trig_Timer_ff( ADC1, TIM2_CC2, 225 );
|
|
// Config DMA pour utilisation du buffer dma_buf (a créér)
|
|
Init_ADC1_DMA1( 0, dma_buf );
|
|
|
|
// Config Timer, période exprimée en périodes horloge CPU (72 MHz)
|
|
Systick_Period_ff( SYSTICK_PER );
|
|
// enregistrement de la fonction de traitement de l'interruption timer
|
|
// ici le 3 est la priorité, sys_callback est l'adresse de cette fonction, a créér en C
|
|
Systick_Prio_IT( 3, sys_callback );
|
|
SysTick_On;
|
|
SysTick_Enable_IT;
|
|
|
|
while(1){
|
|
}
|
|
|
|
}
|