This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
how to use FPU unit .i followed the example and run it .it was fine but when i tried to run my code by using FPUEnable and FPUlazystacking it is not working.
could you please guide me how to use FPU unit in codecomposer for tm4c
Hi,
What is the problem? What errors are you getting? Are you getting errors during compile or during runtime?
Your code is very hard to read without indentation. Please paste your code by clicking the 'Use rich formatting' at the lower right of the editor window and then select the tab 'Insert code using SyntaxHighighter.
I quickly glance through your code and are using a variable 'flag' that is not declared. It will not compile if this is the problem. See below snippet of your code. Where is the variable flag declared?
if (v[n]< 0.95) { vio[n]=0.96-v[n]; flag=1; } else if( v[n]> 1.05) { vio[n]=1.04-v[n]; flag=1; } } if(flag==1) // if True a violation exist {
Poster reports, "Not doing simple multiplication." (report at the (very) bottom of his post! Not the best location to insure notice.)
If indeed "simple multiplication" is the issue - would not a GREATLY abbreviated code listing - demonstrating that failure - have made (much) more sense? (i.e. SAVING poster's, yours & my time in reading/reviewing this barrage...)
Hi,
Several observations related to your code:
1) you need to make a project, and add the file startup_ccs.c to that project. Not explicitly stated that in your comments.
2) you need to generate listing file and a map file; from the listing file you should extract the info about stack usage and set a correct dimension for it. I suspect you have stack usage problems.
3) do not try to reinvent the wheel - there are matrix manipulation programs in C published on the web or in some books - look for "Numerical Recepies in C" second edition. Use them, they are already tested by others. (do not remember if CMSIS package has some, check anyway)
4) test on a PC your routines and if satisfactory move the source code on CCS.
5) do not be too short in your comments " there are errors" - what errors? we cannot guess, just copy/paste first ones and post them.
While the diagnostic efforts of both vendor's Charles & friend Petrei are correct & impressive - may I note that, "Posters benefit greatly when they present the "minimum code block" (to include definitions & configurations) which demonstrates their problem or issue."
Surgeons "drape" their "area of interest - that "tight focus" reduces/prevents distraction - which slows & complicates their mission/objective.
Our programming field benefits greatly from a similar, "locking-in" upon the objective. Reviewing several hundred (or thousand) lines of code is "over-whelming" - reducing the task to its ESSENCE greatly, "Speeds, Eases & Enhances" problem solving! And this "essence seeking" is effective in leading to a FAR better problem description than (famed - effort lite) "Does not Work!"
The extra focus which this disciplined method provides - best enables quick, more controlled & efficient issue resolution. (and proves especially true when "external assistance" is required...)
Hi Charles.
I run the code now there is no error but there are warnings related to dependency like
gmake: Circular ../tm4c123gh6pm.cmd.out <- ../tm4c123gh6pm.cmd dependency dropped.
gmake: Circular C:/ti/TivaWare_C_Series-2.1.2.111/driverlib/ccs/Debug/driverlib.lib.out <- C:/ti/TivaWare_C_Series-2.1.2.111/driverlib/ccs/Debug/driverlib.lib dependency dropped.
could you please tell me which variables you declared to compilation compile the code.
and how can i remove these dependency warnings.I am sending you my code again.
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include<stdlib.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/fpu.h"
#include "driverlib/sysctl.h"
void inverse(float[6][6],int,float[6][6]);
float determinant(float[6][6],int);
void cofactor(float[6][6],int,float[6][6]);
void transpose(float[6][6],float[6][6],int,float[6][6]);
int main(void)
{
FPULazyStackingEnable();
FPUEnable();
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
//int i[4]={2,3,5,4}; // Defines the critical power system to-node
//int j[4]={1,2,2,2};
float z[4]={0.003113,0.015709,6.951e-3,9.029e-3}; // Defines the critical power system from-node
float v[5]={0.962,0.952,0.963,0.946,0.937}; // Defines the critical power system node voltage obtained from the main power flow code
float Q=1.739; // Defines the agent reactive power obtained from the main power flow code
float P=1.449; //Defines the agent active power obtained from the main power flow code
float S=3.0; // Defines the agent maximum generation capacity
//int unknownsQ=1; // number of unknowns change of reactive power if another agent downstream will affect this zone
double aq=powf(S,2);
double bq=powf(P,2);
double abq=aq-bq;
float SF=7.0/93; // agent node senstivity factor
float nqj=0.1/3; //The agent droop coefficent
double Qmax=sqrtf(abq);
//float Qmax=powf(abq,0.5); // Finding the maximum avilable reactive power generation
//printf("Qmax= %f\n",Qmax);
float xo[6]={0}; // Initializing the unknowns
int flag=0; // Initialize the flage the indicate a viloation if exist=1
int priority=0; // Initialize the agent priority
//int DQ[4]={6,6,0,0}; // means that the change of reactive power flow between j(1) and i(1) is equal to x(6),
//or between i(3) and j (3) is nothing the change is equal zero
float a[6][6]={0};
float vio[5]={0};
float x[6]={0};
int loc;
int n,c;
//------------------------------- Checking for violation--------------------
for( n=0;n<5;n++)
{
if (v[n]< 0.95)
{
vio[n]=0.96-v[n];
flag=1;
}
else if( v[n]> 1.05)
{
vio[n]=1.04-v[n];
flag=1;
}
}
if(flag==1) // if True a violation exist
{
priority=priority+1;
//selecting the bus with maximum violation
int maximum = vio[0];
for (c = 1; c < 5; c++)
{
if (vio[c] > maximum)
{
maximum = vio[c];
loc = c;
}
}
x[loc+1]=vio[loc]; // indicating the needed soluation for maximum violation node
}
int act,k,l,m,q,s;
float b[6]={0, 0, 0 , 0, 0, vio[loc]};
float b1[6]={xo[5],0,0,0,0,vio[loc]};
float ff[6][6]={{1,0,0,0,0,-SF},
{v[0]/v[1],-1,0,0,0,-z[0]/v[1]},
{0,v[1]/v[2],-1,0,0,-z[1]/v[2]},
{0,v[1]/v[4],0,0,-1,0},
{0,v[1]/v[3],0,-1,0,0},
{0,0,0,0,1,0}};
float ff1[6][6]={{1,0,0,0,0,-nqj},
{v[0]/v[1],-1,0,0,0,-z[0]/v[1]},
{0,v[1]/v[2],-1,0,0,-z[1]/v[2]},
{0,v[1]/v[4],0,0,-1,0},
{0,v[1]/v[3],0,-1,0,0},
{0,0,0,0,1,0}};
float ff2[6][6]={{0,0,0,0,0,1},
{v[0]/v[1],-1,0,0,0,-z[0]/v[1]},
{0,v[1]/v[2],-1,0,0,-z[1]/v[2]},
{0,v[1]/v[4],0,0,-1,0},
{0,v[1]/v[3],0,-1,0,0},
{0,0,0,0,1,0}};
float bt[6][1];
float b1t[6][1];
for(n=0; n<6; n++)
{
bt[n][0]=b[n];
b1t[n][0]=b1[n];
}
for( act=0;act<3;act++)
{
float m_inverse[6][6];
if(act==0)
{
inverse(ff,6,m_inverse);
for( k=0;k < 6;k++)
{
x[k]=0;
for(l=0;l<6;l++)
{
x[k]=x[k]+(m_inverse[k][l]*bt[l][0]);
}
}
}
if(act==1)
{
inverse(ff1,6,m_inverse);
for( k=0;k < 6;k++)
{
x[k]=0;
for(l=0;l<6;l++)
{
x[k]=x[k]+(m_inverse[k][l]*bt[l][0]);
}
}
}
if(act==2)
{
inverse(ff2,6,m_inverse);
for( k=0;k < 6;k++)
{
x[k]=0;
for(l=0;l<6;l++)
{
x[k]=x[k]+(m_inverse[k][l]*b1t[l][0]);
}
}
}
for( m=0;m<=5;m++)
{
a[m][2*act]=x[m]; //storing the x values of a certain action in a matrix a
// checking for feasibilityof the founded solution for each action----
}
for(q=0;q<5;q++)
{
if((v[q]+x[q])<0.95)
{
a[q][2*act+1]=v[q]+x[q]-0.95;
}
else
{
if((v[q]+x[q])>1.05)
{
a[q][2*act+1]=v[q]+x[q]-1.05;
}
}
if((Q+x[5])>Qmax)
{
a[5][2*act]=(Q+x[5])-Qmax;
}
}
}
float sum1=0;
float sum2=0;
float sum3=0;
for( s=0;s<6;s++)
{
sum1=sum1+a[s][1];
sum2=sum2+a[s][3];
sum3=sum3+a[s][5];
}
float vstar;
if(sum1<fabsf(0.001))
{
//send msg
vstar=a[0][0]*(1+(nqj*a[5][0])/a[0][0]);
}
else if(sum2<fabsf(0.001))
{
//send msg
vstar=a[0][2]*(1+(nqj*a[5][2])/a[0][2]);
}
else if(sum3<fabsf(0.001))
{
//send msg
vstar=a[0][4]*(1+(nqj*a[5][4])/a[0][4]);
}
}
void inverse(float matrix[6][6], int size,float m_inverse[6][6])
{
float d;
int i,j;
float matrix_cofactor[6][6];
float m_transpose[6][6];
d=determinant(matrix,size);
cofactor(matrix,size,matrix_cofactor);
transpose(matrix,matrix_cofactor,size,m_transpose);
for (i=0;i<size;i++)
{
for (j=0;j<size;j++)
{
m_inverse[i][j]=m_transpose[i][j] / d;
}
}
}
/*For calculating Determinant of the Matrix . this function is recursive*/
float determinant(float matrix[6][6],int size)
{
float s=1,det=0,m_minor[6][6];
int i,j,m,n,c;
if (size==1)
{
return (matrix[0][0]);
}
else
{
det=0;
for (c=0;c<size;c++)
{
m=0;
n=0;
for (i=0;i<size;i++)
{
for (j=0;j<size;j++)
{
m_minor[i][j]=0;
if (i != 0 && j != c)
{
m_minor[m][n]=matrix[i][j];
if (n<(size-2))
n++;
else
{
n=0;
m++;
}
}
}
}
det=det + s * (matrix[0][c] * determinant(m_minor,size-1));
s=-1 * s;
}
}
return (det);
}
/*calculate cofactor of matrix*/
void cofactor(float matrix[6][6],int size,float matrix_cofactor[6][6])
{
float m_cofactor[6][6];
int p,q,m,n,i,j;
for (q=0;q<size;q++)
{
for (p=0;p<size;p++)
{
m=0;
n=0;
for (i=0;i<size;i++)
{
for (j=0;j<size;j++)
{
if (i != q && j != p)
{
m_cofactor[m][n]=matrix[i][j];
if (n<(size-2))
n++;
else
{
n=0;
m++;
}
}
}
}
matrix_cofactor[q][p]=pow(-1,q + p) * determinant(m_cofactor,size-1);
}
}
}
/*Finding transpose of cofactor of matrix*/
void transpose(float matrix[6][6],float matrix_cofactor[6][6],int size,float m_transpose[6][6])
{
int i,j;
for (i=0;i<size;i++)
{
for (j=0;j<size;j++)
{
m_transpose[i][j]=matrix_cofactor[j][i];
}
}
}
Hi,
Do you happen to have driverlib also in your project folder? If you linking the driverlib from the TivaWare then make sure you don't duplicate it in the project folder. See this similar post to see if you have the same problem. gmake dependency dropped error - Code Composer Studio forum - Code Composer Studio™︎ - TI E2E support...