daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Apr 21st, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int16_t capture[FFT_N];         /* Wave captureing buffer */
  2. complex_t bfly_buff[FFT_N];     /* FFT buffer */
  3. uint16_t spektrum[FFT_N/2];
  4.  
  5. void capture_wave (int16_t *buffer, uint16_t count)
  6. {
  7.     ADMUX = _BV(REFS0)|_BV(ADLAR)|_BV(MUX2)|_BV(MUX1)|_BV(MUX0);    // channel
  8.  
  9.     do {
  10.         ADCSRA = _BV(ADEN)|_BV(ADSC)|_BV(ADATE)|_BV(ADIF)|_BV(ADPS2)|_BV(ADPS1);
  11.         while(bit_is_clear(ADCSRA, ADIF));
  12.         *buffer++ = ADC - 32768;
  13.     } while(--count);
  14.  
  15.     ADCSRA = 0;
  16. }
  17.  
  18. int main (void)
  19. {
  20.     initGLCD();
  21.  
  22.     xy_point p1, p2;
  23.     uint16_t m, n, s;
  24.  
  25.     TCCR1B = 3; /* clk/64 */
  26.  
  27.     uint16_t mp = 63;
  28.  
  29.     // should be clocked at 6-10 hz with interrupts in the real application
  30.     while(TRUE) {
  31.         capture_wave(capture, FFT_N);
  32.  
  33.         fft_input(capture, bfly_buff);
  34.         fft_execute(bfly_buff);
  35.         fft_output(bfly_buff, spektrum);
  36.  
  37.         fillGLCDScreen(0x00);
  38.        
  39.         for (n = 0; n < FFT_N / 2; n++) {
  40.             s = spektrum[n];
  41.             s /= 512;
  42.            
  43.             p1.x = n;
  44.             p1.y = mp;
  45.  
  46.             p2.x = n;
  47.             p2.y = mp - s;
  48.  
  49.             fillRect(p1, p2, &invertPixelGLCD);
  50.         }
  51.  
  52.         asm("nop");
  53.         asm("nop");
  54.         asm("nop");
  55.         asm("nop");
  56.         asm("nop");
  57.     }
  58.  
  59.     return 0;
  60. }
RAW Paste Data
Top