Possible to do spectrum analyzing (fft) with M0?

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ledbear
 
Posts: 24
Joined: Thu May 31, 2018 4:57 pm

Possible to do spectrum analyzing (fft) with M0?

Post by ledbear »

Hi, I have been trying to find any code that would do fast Fourier transform with a ATSAMD21E18 M0+ (a Gemma M0 in my case), but all examples I've found use avr boards. I get stuck on "error: 'ADMUX' was not declared in this scope" and such, which I understood is because it assumes those be declared but they're not since my Gemma M0 isn't a AVR board (its a ARM one if I got it right).

So, is this impossible to do? Or just few people have been using these boards and hence there are no example code up anywhere?
I have tried the piccolo example on adafruit, but just got this

Code: Select all

Piccolo:231: error: expected constructor, destructor, or type conversion before '(' token
 ISR(ADC_vect) { // Audio-sampling interrupt
     ^
/Users//Documents/Arduino/Piccolo/Piccolo.pde: In function 'void setup()':
Piccolo:131: error: 'ADMUX' was not declared in this scope
   ADMUX  = ADC_CHANNEL; // Channel sel, right-adj, use AREF pin
   ^
Piccolo:132: error: 'ADCSRA' was not declared in this scope
   ADCSRA = _BV(ADEN)  | // ADC enable
   ^
Piccolo:132: error: 'ADEN' was not declared in this scope
   ADCSRA = _BV(ADEN)  | // ADC enable
                ^
Piccolo:132: error: '_BV' was not declared in this scope
   ADCSRA = _BV(ADEN)  | // ADC enable
                    ^
Piccolo:133: error: 'ADSC' was not declared in this scope
            _BV(ADSC)  | // ADC start
                ^
Piccolo:134: error: 'ADATE' was not declared in this scope
            _BV(ADATE) | // Auto trigger
                ^
Piccolo:135: error: 'ADIE' was not declared in this scope
            _BV(ADIE)  | // Interrupt enable
                ^
Piccolo:136: error: 'ADPS2' was not declared in this scope
            _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); // 128:1 / 13 = 9615 Hz
                ^
Piccolo:136: error: 'ADPS1' was not declared in this scope
            _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); // 128:1 / 13 = 9615 Hz
                             ^
Piccolo:136: error: 'ADPS0' was not declared in this scope
            _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); // 128:1 / 13 = 9615 Hz
                                          ^
Piccolo:137: error: 'ADCSRB' was not declared in this scope
   ADCSRB = 0;                // Free run mode, no high MUX bit
   ^
Piccolo:138: error: 'DIDR0' was not declared in this scope
   DIDR0  = 1 << ADC_CHANNEL; // Turn off digital input for ADC pin
   ^
Piccolo:139: error: 'TIMSK0' was not declared in this scope
   TIMSK0 = 0;                // Timer0 off
   ^
Piccolo:141: error: 'sei' was not declared in this scope
   sei(); // Enable interrupts
       ^
/Users//Documents/Arduino/Piccolo/Piccolo.pde: In function 'void loop()':
Piccolo:149: error: 'ADCSRA' was not declared in this scope
   while(ADCSRA & _BV(ADIE)); // Wait for audio sampling to finish
         ^
Piccolo:149: error: 'ADIE' was not declared in this scope
   while(ADCSRA & _BV(ADIE)); // Wait for audio sampling to finish
                      ^
Piccolo:149: error: '_BV' was not declared in this scope
   while(ADCSRA & _BV(ADIE)); // Wait for audio sampling to finish
                          ^
Piccolo:153: error: 'ADCSRA' was not declared in this scope
   ADCSRA |= _BV(ADIE);             // Resume sampling interrupt
   ^
Piccolo:153: error: 'ADIE' was not declared in this scope
   ADCSRA |= _BV(ADIE);             // Resume sampling interrupt
                 ^
Piccolo:153: error: '_BV' was not declared in this scope
   ADCSRA |= _BV(ADIE);             // Resume sampling interrupt
                     ^
/Users//Documents/Arduino/Piccolo/Piccolo.pde: At global scope:
Piccolo:231: error: expected constructor, destructor, or type conversion before '(' token
 ISR(ADC_vect) { // Audio-sampling interrupt
    ^
exit status 1
expected constructor, destructor, or type conversion before '(' token
I wish I knew enough C to understand whats going on in the areas that have the errors, but I don't at the moment. So is this a lost cause (get a Gemma V2) or am I missing something?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Possible to do spectrum analyzing (fft) with M0?

Post by adafruit_support_mike »

You're right that the SAMD21E belongs to a different microcontroller family than the ATmega family. The registers that control the chips will be completely different.

We have an FFT library for the SAMD21 here:

https://github.com/adafruit/Adafruit_ZeroFFT

User avatar
ledbear
 
Posts: 24
Joined: Thu May 31, 2018 4:57 pm

Re: Possible to do spectrum analyzing (fft) with M0?

Post by ledbear »

Thanks Mike, I'll have a look and see what I can make of it =)

/Ledbear

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”