92 lines
1.9 KiB
C
92 lines
1.9 KiB
C
#include "gassp72.h"
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <stdio.h>
|
|
|
|
#define taille 6
|
|
#define SYSTICK_PER 360000 // (360000 ticks équivaut à 5ms)
|
|
#define M2TIR 985988
|
|
|
|
extern short TabSig[];
|
|
int etat = 0x00020000;
|
|
|
|
|
|
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};
|
|
|
|
|
|
|
|
|
|
void checkCounter(void){
|
|
for(int i=0; i<taille; i++) {
|
|
if(compteurs[i] >= 13){
|
|
compteurs[i]=0;
|
|
scores[i]++;
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
for(int i=0; i<6; i++){
|
|
compteurs[i] = 0;
|
|
scores[i] = 0 ;
|
|
}
|
|
|
|
|
|
// activation de la PLL qui multiplie la fréquence du quartz par 9
|
|
CLOCK_Configure();
|
|
// PA2 (ADC voie 2) = entrée analog
|
|
GPIO_Configure(GPIOA, 2, INPUT, ANALOG);
|
|
// PB1 = sortie pour profilage à l'oscillo
|
|
GPIO_Configure(GPIOB, 1, OUTPUT, OUTPUT_PPULL);
|
|
// PB14 = sortie pour LED
|
|
GPIO_Configure(GPIOB, 14, OUTPUT, OUTPUT_PPULL);
|
|
|
|
// 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){
|
|
|
|
}
|
|
|
|
}
|