r28 can not be used in asm here

Arduino に関するご質問などはこちらへ。

r28 can not be used in asm here

投稿記事by p_p » 2014年1月13日(月) 13:13

はじめまして。

現在arduinoでフォトダイオードによって照度を取得し、その値をFFTしたいと考えております。
そこでFFTライブラリを利用しようとしたのですが、「r28 can not used in asm here」というエラーが出てしまいました。

このエラーを解決しようと自分なりに調べ、最適化をオンにすれば直るという情報を見つけたのですが具体的にどうすればいいのかわかりません。

このエラーを修復するにはどうしたらいいのか、また具体的にどうすればよいのか教えていただけないでしょうか。

よろしくお願いします。
p_p
 
記事: 4
登録日時: 2014年1月12日(日) 21:18

Re: r28 can not be used in asm here

投稿記事by yamaguch » 2014年1月14日(火) 14:27

p_p さん、

Arduino の機種は何ですか。
FFT ライブラリは Arduino 用のものですか?

山口
yamaguch
 
記事: 482
登録日時: 2010年7月06日(火) 17:37

Re: r28 can not be used in asm here

投稿記事by p_p » 2014年1月14日(火) 15:22

arduinoはarduino uno、FFTライブラリは”http://wiki.openmusiclabs.com/wiki/ArduinoFFT”のページにあるものを使いました。
p_p
 
記事: 4
登録日時: 2014年1月12日(日) 21:18

Re: r28 can not be used in asm here

投稿記事by yamaguch » 2014年1月16日(木) 11:12

examples に含まれている fft_adc はコンパイルできましたか?

すみませんが、質問のときは(http://www.senio.co.jp/bbs/viewtopic.php?f=1&t=188&start=0)を参考にしてください。

山口
yamaguch
 
記事: 482
登録日時: 2010年7月06日(火) 17:37

Re: r28 can not be used in asm here

投稿記事by p_p » 2014年1月19日(日) 22:36

サンプルはちゃんとコンパイルすることができました。ただこちらのページ"http://arms22.blog91.fc2.com/blog-entry-416.html"の照度計プログラムと組み合わせた時にエラーが出てしまうという状態です。

必要事項などを記入し忘れてしまい大変申し訳ありませんでした。ソースコードを添付しました。

よろしくお願いします。
添付ファイル
arduino.zip
(1.28 KiB) ダウンロード数: 1916 回
p_p
 
記事: 4
登録日時: 2014年1月12日(日) 21:18

Re: r28 can not be used in asm here

投稿記事by yamaguch » 2014年1月20日(月) 12:19

p_p さん、こんにちは、

今後はできればソースコードは Code タグを使ってこんな風に掲示板の中に書いてください。
(余分な空行を取り除いたり、最後にあった establishContact() を前に持ってきたりしていますが、本質的には何も変えていません)
コード: 全て選択
#define NUM 1
#define LIN_OUT 1 // use the lin output function
#define FFT_N 32 // set number of point fft
#include <FFT.h> // include the library
#include <TimerOne.h>

volatile int i;    // index for data points
volatile int inByte;

const int voutPin = 0;
void timerIsr() {
    while(!(ADCSRA & 0x10)); // wait for adc to be ready
    ADCSRA = 0xf5; // restart adc
    byte m = ADCL; // fetch adc data
    byte j = ADCH;
    int k = (j << 8) | m; // form into an int
    k -= 0x0200; // form into a signed int
    k <<= 6; // form into a 16b signed int
    fft_input[i] = k; // put real data into even bins
    fft_input[i+1] = 0; // set odd bins to 0
    i += 2;
}

void establishContact(){
    while(Serial.available() <= 0){
        Serial.println("0,0");
        delay(300);
    }
}

void setup(){
    Serial.begin(115200);//シリアル速度
    TIMSK0 = 0; // turn off timer0 for lower jitter
    ADCSRA = 0xe5; // set the adc to free running mode
    ADMUX = 0x40; // use adc0
    DIDR0 = 0x01; // turn off the digital input for adc0
    i = 0;

    Timer1.initialize(1000); // set a timer of length 100 microseconds (10000Hz)
    Timer1.attachInterrupt( timerIsr ); // attach the service routine here
    inByte = 0;

    establishContact();
}

void loop(){ 
    while(i < FFT_N*2) {
    }

    cli();  // UDRE interrupt slows this way down on arduino1.0
    fft_window(); // window the data for better frequency response
    fft_reorder(); // reorder the data before doing the fft
    fft_run(); // process the data in the fft
    fft_mag_lin(); // take the output of the fft
    i = 0;

    for (int l=0; l<FFT_N/2; l++){
        Serial.print(fft_lin_out[l]); // send out the data
        Serial.print(",");
    }

    Serial.println();   

    sei();
    // R1の電圧を取得
    int reading = analogRead(voutPin);
    // AD値をmVに変換
    float voltage = ((long)reading * 5000) / 1024;
    // 電圧から電流を求める I=E/R (R=1200)
    float microamp = (voltage * 1000) / 1200;
    // 電流をlxに変換
    //1.0mA/100lx
    float lx = microamp / (1000 / 100);
    int lx2 = (int)lx;
    String lx3 = (String)lx2;
    if(Serial.available() > 0){//processingにデータを送信
        inByte = Serial.read();
        for(int j = 0; j <NUM; j++){
            Serial.print(lx3);
            if(j < NUM - 1){
                Serial.print(",");
            }
            else{
                Serial.print('¥n');
            }
        }
    }
}

「何でも作っちゃうかも」さんのページのスケッチも FFT の exampleもいずれも正しくコンパイルできるけれど、組み合わせると
sketch_jan20a:88: error: r28 cannot be used in asm here
sketch_jan20a:88: error: r29 cannot be used in asm here
というようなエラーが出るということですね。
ちょうど loop() の最後の } のあたりで怒られています。
おもしろいエラーですね ;)

スケッチのどの部分がコンパイラの気に入らないかを突き止める必要がありますが、それには、先ずコンパイルできる状態までスケッチをコメントアウトして、その後、少しずつコメントを外していって、どこで叱られるかを調べてみるといいと思います。

とりあえず、loop() の中の 9 行めの i = 0 以降 loop の終わりまでをコメントアウトするとコンパイルできますね。
この状態からコメントを少しずつ外して、どこで、コンパイルエラーが出るかやってみてはいかがですか?

山口
yamaguch
 
記事: 482
登録日時: 2010年7月06日(火) 17:37


Return to Arduino 質問箱

cron