I got an error message about registers

sketch_mar23a.ino: In function 'void loop()':
sketch_mar23a:164: error: r28 cannot be used in asm here
sketch_mar23a:164: error: r29 cannot be used in asm here

I just dont understand what kind of error it is? and how to solve it? I checked my program many times and its not a syntax error. I think this is probably with registers. I attached my code below in replies...please have a look....I'm running out of time.

Any help is appriciated.

Thank you

Hello and welcome

It would help if you showed your code... :wink:

The problem appears to be in line 164.

Here is my code. This code is lengthy one. My project is to estimate speed of induction motor my processing stator current signal using Neural Networks. And display the result on serial LCD. Hope this may help you…Thank you for reply and welcome wishes

MS_Entire_project.ino (5.79 KB)

I don’t know why you didn’t just post the code.

#include <LiquidCrystal.h>

#include <FFT.h>
#define LOG_OUT 1 // use the log output function
#define FFT_N 2048// set to 2048 point fft
 
 
 /*                                   Function Defination                           */



//////////////////////////////////////////////Neural Network Function///////////////////////////////////////////
float Neural_network(float Diff)
{
 float I,O1,O2,O3,O,Output; 
 I=0.3158*Diff-3.3158;
 O1=transferfunction(-0.0107*I-0.9841);
 O2=transferfunction(0.1121*I-0.3253);
 O3=transferfunction(-0.0082*I-1.5041);
 O=(-0.3716*O1)+(-0.1043*O2)+(0.7287*O3);
 Output=0.000055556*O;
 return Output;
}



/////////////////////////////////////////////tanh(sigma) function////////////////////////////////////////
float transferfunction(float i)
{
  float s,t;
  s=1/(1+exp(-i));
  t=(exp(s)-exp(-s))/(exp(s)+exp(-s));
  return t;
}


/////////////////////////////////////////////LCD_Display function//////////////////////////////////////////////
//  *  Control a Serial LCD Display
//  *  Tested on a Matrix Orbital model LCD0821 display.
//  *  Other diplays will work but may have slightly different 
//  *  command codes and hardware setups. 
void LCD_display(double S)
{
  backlightOn(0);  // turn the backlight on all the time
  Serial.write(12);//clear LCD
  cursorSet(1,1);
  Serial.write("Speed:");
  cursorSet(1,8);
  Serial.println(S);  // print text to the current cursor position                                  
 }
//cursor position
 void cursorSet(int xpos, int ypos){  
  Serial.write(254);
  Serial.write(71);               
  Serial.write(xpos);   //Column position   
  Serial.write(ypos); //Row position 
} 

// turn on backlight
void backlightOn(int minutes){
  Serial.write(254); 
  Serial.write(66);   
  Serial.write(minutes); // use 0 minutes to turn the backlight on indefinitely   
}

// turn off backlight
void backlightOff(){
  Serial.write(254); 
  Serial.write(70);   
}



/////////////////////////////////////////////Finding maximum of an array//////////////////////////////
double Maximum(double a[])
{
  double s;
  for (int i = 0; i < sizeof(a) - 1; i++){
    if(s<a[i])
    {
      s=a[i];
    }
  }
 return s;
}

/////////////////////////////////////////MAIN FUNCTION////////////////////////////////////////
void setup(){
    Serial.begin(9600); // era beginSerial
    }
void loop()
{
  double x[2047]; //input sampled signal from pin
//////////////////////////////////////Reading Pin and Storing the values in an array//////////////
for(int i=0;i<2047;i++)
{
  x[i]=analogRead(0);
  delay(1);
}
/////////////////////////////////Passing the signal through Digital low pass filter///////////////
 
double Speed,Speed1;


/////////////////////////////////////FFT and Filter function////////////////////////////////////
 double fft_lin_out[1023];
    for (int i = 0 ; i < 4096 ; i += 2) { // save 256 samples
      fft_input[i] = x[i]; // put real data into even bins
      fft_input[i+1] = 0; // set odd bins to 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();
    //fft_lin_out[];// contains only 1024 points because it is symmetrical about Y-axis

///////////////////////////Averaging or smoothening the spectrum obtained///////////////////////
double Data4[1023],Data5[50];
for (int i=3;i<=1022;i++){
Data4[i]=(fft_lin_out[i-2]+fft_lin_out[i-1]+fft_lin_out[i]+fft_lin_out[i+1]+fft_lin_out[i+2])/5;
}
for (int i=270;i<320;i++){
Data5[i-270]=Data4[i];
}

///////////////////////////////////finding harmonic frequencies/////////////////////////////
/* Original data x[], fft_lin_out[], Averaged Data4 can be deleted by this point 
and there are varibles below which are defined as double. They may have to change to float */
float difference;
double Max;
Max=Maximum(Data5);
double threshold=0.5*Max; //program to find maximum of Data5

float max1=0;
float max2=0;
int max1_point,max2_point;
boolean s=0;
boolean s1=0;
boolean s2=0;
boolean s3=0;
while(max1==0)
{
 
  
  for (int i=0;i<50;i++){
    if (threshold>Data5[i]){
       Data5[i]=0;
       }
  }
 
for (int i=0;i<50;i++){
  if (s==0){
    
    if (Data5[i]>0 && s2==0){  
      s2=1;
    }
    
    if (s2==1 && max2<Data5[i]){
      max2=Data5[i];
      max2_point=i;
    }
    
    if (s2==1&&Data5[i]==0){
       s2=0;
       s=1;
    }
    
  }
    
  if (s==1){
        if (Data5[i]>0 && s2==0){
           s1=1;
        }
    
         if (s1==1 && max2<Data5[i]){
           max1=Data5[i];
           max1_point=i;
         }
    
         if (s1==1 && Data5[i]==0){
            s1=0;
         }
  }
  
}
//////////////////////////For special cases//////////////////////////
if (max1==0){
  /////////////////////////////////////////trying by increase the threshold
    if (threshold<0.95*Max && s3==0){
    threshold=threshold+0.1*Max;
    }
    if (threshold>=Max){
        s3=1;
        threshold=0.5*Max;
        
    }
   ////////////////////////////////////////trying by decrease the threshold
    if (s3==1 && threshold>0.25*Max){
        threshold=threshold-0.1*Max;
      }
    if (s3==1 && threshold<=0.25*Max){
        s3=0;
        max1=max2;
        max1_point=max2_point;
        break;
    }  
          
  }
}///////////////////////////////////////////End of While Loop/////////////////////////////////////////////////




////////////////////////////////Passing the results to Neural Network ////////////////////////////////////////
if (Max==max1||Max==max2)
{ 
difference= (max1_point-max2_point)/2;
Speed1=Speed;
Speed=Neural_network(difference);
LCD_display((0.8*Speed)+(0.2*Speed1));
}
else
{
 backlightOn(0);  // turn the backlight on all the time
  Serial.write(12);//clear LCD
  Serial.write("ERROR");
}



}///////////////////////////End of void loop//////////////////////////////////////////////////////////
  double s;
  for (int i = 0; i < sizeof(a) - 1; i++){
    if(s<a[i])

And the initial value of “s” is . . ?

double Maximum(double a[])
{
  double s;
  for (int i = 0; i < sizeof(a) - 1; i++) {

And the size of a pointer to double is . . ?

There are some awfully big data sets in this sketch - what are you hoping to run it on?
Too many magic numbers too.

  O=(-0.3716*O1)+(-0.1043*O2)+(0.7287*O3);

You aren't troubled, I gather, by having a variable named "O"? It looks very much like a zero.

  double x[2047]; //input sampled signal from pin

What Arduino are you running this on?

I'm running out of time.

Sorry to hear that. Time can be hard to manage.

Hi sridhar_reddy

Can you post a link to the FFT library you are using.

Thanks

Ray