Other Parts Discussed in Thread: CONTROLSUITE
Hi everyone,
I'm currently working on the motor control application. I want to replace PI controller by a fuzzy-neural network controller. In each interruption, I need to perform 3 matrices multiplication and use tanhf() to calculate the result.
In the code, I multiplied element by element and use tanhf() from the math.lib. But the interruption can not be finished within 0.1 ms. Is there any way I can optimize the code or I need to change to a better microchip?
Thanks
Yang Sun
// Matrix_multiply(*W1,inputlayer,hiddenlayer1,6,5);
p=&W1[0][0];
q=&inputlayer[0];
hiddenlayer1[0]= *p**q + *(p+1)**(q+1) + *(p+2)**(q+2) + *(p+3)**(q+3) + *(p+4)**(q+4);
hiddenlayer1[1]= *(p+5)**q + *(p+6)**(q+1) + *(p+7)**(q+2) + *(p+8)**(q+3) + *(p+9)**(q+4);
hiddenlayer1[2]= *(p+10)**q + *(p+11)**(q+1) + *(p+12)**(q+2) + *(p+13)**(q+3) + *(p+14)**(q+4);
hiddenlayer1[3]= *(p+15)**q + *(p+16)**(q+1) + *(p+17)**(q+2) + *(p+18)**(q+3) + *(p+19)**(q+4);
hiddenlayer1[4]= *(p+20)**q + *(p+21)**(q+1) + *(p+22)**(q+2) + *(p+23)**(q+3) + *(p+24)**(q+4);
hiddenlayer1[5]= *(p+25)**q + *(p+26)**(q+1) + *(p+27)**(q+2) + *(p+28)**(q+3) + *(p+29)**(q+4);
hiddenlayer1[0]=(float)tanhf(hiddenlayer1[0]);
hiddenlayer1[1]=(float)tanhf(hiddenlayer1[1]);
hiddenlayer1[2]=(float)tanhf(hiddenlayer1[2]);
hiddenlayer1[3]=(float)tanhf(hiddenlayer1[3]);
hiddenlayer1[4]=(float)tanhf(hiddenlayer1[4]);
hiddenlayer1[5]=(float)tanhf(hiddenlayer1[5]);
// the 2nd hidden layer
//Matrix_multiply(*W2, hiddenlayer1, hiddenlayer2,6,7);
p=&W2[0][0];
q=&hiddenlayer1[0];
hiddenlayer2[0]= *p**q + *(p+1)**(q+1) + *(p+2)**(q+2) + *(p+3)**(q+3) + *(p+4)**(q+4)+ *(p+5)**(q+5)+ *(p+6)**(q+6);
hiddenlayer2[1]= *(p+7)**q + *(p+8)**(q+1) + *(p+9)**(q+2) + *(p+10)**(q+3) + *(p+11)**(q+4)+ *(p+12)**(q+5)+ *(p+13)**(q+6);
hiddenlayer2[2]= *(p+14)**q + *(p+15)**(q+1) + *(p+16)**(q+2) + *(p+17)**(q+3) + *(p+18)**(q+4)+ *(p+19)**(q+5)+ *(p+20)**(q+6);
hiddenlayer2[3]= *(p+21)**q + *(p+22)**(q+1) + *(p+23)**(q+2) + *(p+24)**(q+3) + *(p+25)**(q+4)+ *(p+26)**(q+5)+ *(p+27)**(q+6);
hiddenlayer2[4]= *(p+28)**q + *(p+29)**(q+1) + *(p+30)**(q+2) + *(p+31)**(q+3) + *(p+32)**(q+4)+ *(p+33)**(q+5)+ *(p+34)**(q+6);
hiddenlayer2[5]= *(p+35)**q + *(p+36)**(q+1) + *(p+37)**(q+2) + *(p+38)**(q+3) + *(p+39)**(q+4)+ *(p+40)**(q+5)+ *(p+41)**(q+6);
hiddenlayer2[0]=(float)tanhf(hiddenlayer2[0]);
hiddenlayer2[1]=(float)tanhf(hiddenlayer2[1]);
hiddenlayer2[2]=(float)tanhf(hiddenlayer2[2]);
hiddenlayer2[3]=(float)tanhf(hiddenlayer2[3]);
hiddenlayer2[4]=(float)tanhf(hiddenlayer2[4]);
hiddenlayer2[5]=(float)tanhf(hiddenlayer2[5]);
// the 3rd hidden layer
p=&W3[0][0];
q=&hiddenlayer2[0];
outputlayer[0]= *p**q + *(p+1)**(q+1) + *(p+2)**(q+2) + *(p+3)**(q+3) + *(p+4)**(q+4)+ *(p+5)**(q+5)+ *(p+6)**(q+6);
outputlayer[1]= *(p+7)**q + *(p+8)**(q+1) + *(p+9)**(q+2) + *(p+10)**(q+3) + *(p+11)**(q+4)+ *(p+12)**(q+5)+ *(p+13)**(q+6);
outputlayer[0]=(float)tanhf(outputlayer[0])*25.719642299223366;
outputlayer[1]=(float)tanhf(outputlayer[1])*25.719642299223366;