74 lines
1.8 KiB
C
74 lines
1.8 KiB
C
#include "gassp72.h"
|
|
#include "stdlib.h"
|
|
|
|
|
|
const int SYSTICK_PER = 5*72000;
|
|
const int N = 64;
|
|
|
|
// Fe = 320 kHz donc pasFreq = 5 kHz
|
|
// F1 = 85 kHz -> k = 17
|
|
// F2 = 90 kHz -> k = 18
|
|
// F3 = 95 kHz -> k = 19
|
|
// F4 = 100 kHz -> k = 20
|
|
// F5 = 115 kHz -> k = 23
|
|
// F6 = 120 kHz -> k = 24
|
|
const int kFreq[6] = {17, 18, 19, 20, 23, 24};
|
|
|
|
int dft(unsigned short *sig, int k);
|
|
|
|
unsigned short *bufferDMA;
|
|
int counters[6];
|
|
int debug_result[6];
|
|
const int M2TIR = 10000;
|
|
|
|
int time = 0;
|
|
|
|
|
|
void callbackTimer(void) {
|
|
// Démarrage DMA pour 64 points
|
|
Start_DMA1(64);
|
|
Wait_On_End_Of_DMA1();
|
|
Stop_DMA1;
|
|
for (int i = 0; i < 6; ++i) {
|
|
int k = kFreq[i];
|
|
debug_result[i] = dft(bufferDMA, k);
|
|
if (debug_result[i] > M2TIR) {
|
|
++counters[i];
|
|
} else {
|
|
counters[i] = 0;
|
|
}
|
|
}
|
|
time += 5;
|
|
}
|
|
|
|
|
|
int main(void) {
|
|
bufferDMA = malloc(N * sizeof(short));
|
|
|
|
// 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, 72 );
|
|
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, bufferDMA );
|
|
|
|
// 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, callbackTimer );
|
|
SysTick_On;
|
|
SysTick_Enable_IT;
|
|
|
|
while(1){}
|
|
}
|