![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
acs integration working
Revision 0:e91ee0e99213, committed 2015-04-07
- Comitter:
- sakthipriya
- Date:
- Tue Apr 07 16:11:54 2015 +0000
- Commit message:
- acs integration working
Changed in this revision
diff -r 000000000000 -r e91ee0e99213 ACS.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ACS.cpp Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,566 @@ +#include "ACS.h" +#include "MPU3300.h" +#include "pin_config.h" +#include "math.h" + +Serial pc1(USBTX, USBRX); +SPI spi_acs (PIN16, PIN17, PIN15); // mosi, miso, sclk PTE18,19,17 +DigitalOut SSN_MAG (PIN61); // ssn for magnetometer PTB11 +DigitalInOut DRDY (PIN47); // drdy for magnetometer PTA17 +DigitalOut ssn_gyr (PIN62); //Slave Select pin of gyroscope PTB16 +InterruptIn dr(PIN81); //Interrupt pin for gyro PTC5 +PwmOut PWM1(PIN93); //Functions used to generate PWM signal +PwmOut PWM2(PIN94); +PwmOut PWM3(PIN88); //PWM output comes from pins p6 +Ticker tr; //Ticker function to give values for limited amount of time for gyro +Timeout tr_mag; +uint8_t trflag_mag; +uint8_t trFlag; //ticker Flag for gyro +uint8_t drFlag; //data-ready interrupt flag for gyro +float pwm1; +float pwm2; +float pwm3; +//--------------------------------TORQUE ROD--------------------------------------------------------------------------------------------------------------// + +void FUNC_ACS_GENPWM(float M[3]) +{ + + printf("\n\rEnterd PWMGEN function\n"); + for(int i = 0 ; i<3;i++) + { + printf(" %f \t ",M[i]); + } + float timep = 0.02 ; //Time period is set to 0.02s + + + float DCx = 0; //Duty cycle of Moment in x direction + float ix = 0; //Current sent in x TR's + float Mx=M[0]; //Moment in x direction + ix = Mx * 0.3 ; //Moment and Current always have the linear relationship + if( ix>0&& ix < 0.006 )//Current and Duty cycle have the linear relationship between 1% and 100% + { + DCx = 6*1000000*pow(ix,4) - 377291*pow(ix,3) + 4689.6*pow(ix,2) + 149.19*ix - 0.0008; + PWM1.period(timep); + PWM1 = DCx/100 ; + } + else if( ix >= 0.006&& ix < 0.0116) + { + DCx = 1*100000000*pow(ix,4) - 5*1000000*pow(ix,3) + 62603*pow(ix,2) - 199.29*ix + 0.7648; + PWM1.period(timep); + PWM1 = DCx/100 ; + } + else if (ix >= 0.0116&& ix < 0.0624) + { + DCx = 212444*pow(ix,4) - 33244*pow(ix,3) + 1778.4*pow(ix,2) + 120.91*ix + 0.3878; + PWM1.period(timep); + PWM1 = DCx/100 ; + } + else if(ix >= 0.0624&& ix < 0.555) + { + printf("\n\rACS entered if\n\r"); //gotta check what this means + DCx = 331.15*pow(ix,4) - 368.09*pow(ix,3) + 140.43*pow(ix,2) + 158.59*ix + 0.0338; + PWM1.period(timep); + PWM1 = DCx/100 ; + } + else if(ix==0) + { + printf("\n \r ix====0"); + DCx = 75; + PWM1.period(timep); + PWM1 = DCx/100 ; + } + else //not necessary + { + // printf("!!!!!!!!!!Error!!!!!!!!!"); + } + pwm1 = PWM1; + printf("\n\r icx :%f pwm : %f \n\r",ix,pwm1); + + + float DCy = 0; //Duty cycle of Moment in y direction + float iy = 0; //Current sent in y TR's + float My=M[1]; //Moment in y direction + iy = My * 0.3 ; //Moment and Current always have the linear relationship + if( iy>0&& iy < 0.006 )//Current and Duty cycle have the linear relationship between 1% and 100% + { + DCy = 6*1000000*pow(iy,4) - 377291*pow(iy,3) + 4689.6*pow(iy,2) + 149.19*iy - 0.0008; + PWM2.period(timep); + PWM2 = DCy/100 ; + } + else if( iy >= 0.006&& iy < 0.0116) + { + DCy = 1*100000000*pow(iy,4) - 5*1000000*pow(iy,3) + 62603*pow(iy,2) - 199.29*iy + 0.7648; + PWM2.period(timep); + PWM2 = DCy/100 ; + } + else if (iy >= 0.0116&& iy < 0.0624) + { + DCy = 212444*pow(iy,4) - 33244*pow(iy,3) + 1778.4*pow(iy,2) + 120.91*iy + 0.3878; + PWM2.period(timep); + PWM2 = DCy/100 ; + } + else if(iy >= 0.0624&& iy < 0.555) + { + printf("\n\rACS entered if\n\r"); + DCy = 331.15*pow(iy,4) - 368.09*pow(iy,3) + 140.43*pow(iy,2) + 158.59*iy + 0.0338; + PWM2.period(timep); + PWM2 = DCy/100 ; + } + else if(iy==0) + { + DCy = 0; + PWM2.period(timep); + PWM2 = DCy/100 ; + } + else + { + // printf("!!!!!!!!!!Error!!!!!!!!!"); + } + pwm2 = PWM2; + printf("\n\r icy :%f pwm : %f \n\r",iy,pwm2); + + + float DCz = 0; //Duty cycle of Moment in z direction + float iz = 0; //Current sent in z TR's + float Mz=M[2]; //Moment in z direction + iz = Mz * 0.3 ; //Moment and Current always have the linear relationship + if( iz>0&& iz < 0.006 )//Current and Duty cycle have the linear relationship between 1% and 100% + { + DCz = 6*1000000*pow(iz,4) - 377291*pow(iz,3) + 4689.6*pow(iz,2) + 149.19*iz - 0.0008; + PWM3.period(timep); + PWM3 = DCz/100 ; + } + else if( iz >= 0.006&& iz < 0.0116) + { + DCz = 1*100000000*pow(iz,4) - 5*1000000*pow(iz,3) + 62603*pow(iz,2) - 199.29*iz + 0.7648; + PWM3.period(timep); + PWM3 = DCz/100 ; + } + else if (iz >= 0.0116&& iz < 0.0624) + { + DCz = 212444*pow(iz,4) - 33244*pow(iz,3) + 1778.4*pow(iz,2) + 120.91*iz + 0.3878; + PWM3.period(timep); + PWM3 = DCz/100 ; + } + else if(iz >= 0.0624&& iz < 0.555) + { + printf("\n\rACS entered if\n\r"); + DCz = 331.15*pow(iz,4) - 368.09*pow(iz,3) + 140.43*pow(iz,2) + 158.59*iz + 0.0338; + PWM3.period(timep); + PWM3 = DCz/100 ; + } + else if(iz==0) + { + DCz = 0; + PWM3.period(timep); + PWM3 = DCz/100 ; + } + else + { + // printf("!!!!!!!!!!Error!!!!!!!!!"); + } + pwm3 = PWM3; + printf("\n\r icy :%f pwm : %f \n\r",iz,pwm3); + + printf("\n\rExited PWMGEN function\n\r"); +} +/*------------------------------------------------------------------------------------------------------------------------------------------------------- +-------------------------------------------MAGNETOMETER-------------------------------------------------------------------------------------------------*/ + +void trsub_mag() +{ + trflag_mag=0; +} + +void FUNC_ACS_MAG_INIT() +{ + DRDY = 0; + int a ; + a=DRDY; + printf("\n\r DRDY is %d\n\r",a); + SSN_MAG=1; //pin is disabled + spi_acs.format(8,0); //8bits,Mode 0 + spi_acs.frequency(100000); //clock frequency + SSN_MAG=0; // Selecting pin + wait_ms(10); //accounts for delay.can be minimised. + spi_acs.write(0x83); + wait_ms(10); + unsigned char i; + for(i=0;i<3;i++) //initialising values. + { + spi_acs.write(0x00); //MSB of X,y,Z + spi_acs.write(0xc8); //LSB of X,Y,z;pointer increases automatically. + } + SSN_MAG=1; +} + +void FUNC_ACS_MAG_EXEC(float mag_field[]) +{ + printf("\n\rEntered magnetometer function\n\r"); + DRDY.write(0); + int a; + a = DRDY; + printf("\n\r DRDY is %d\n\r",a); + SSN_MAG=0; //enabling slave to measure the values + wait_ms(10); + spi_acs.write(0x82); //initiates measurement + wait_ms(10); + spi_acs.write(0x01); //selecting x,y and z axes, measurement starts now + SSN_MAG=1; + wait_ms(10); + + trflag_mag=1; + tr_mag.attach(&trsub_mag,1); //runs in background,makes trflag_mag=0 after 1s + DRDY.input(); + while(trflag_mag) /*initially flag is 1,so loop is executed,if DRDY is high,then data is retrieved and programme ends,else + loop runs for at the max 1s and if still DRDY is zero,the flag becomes 0 and loop is not executed and + programme is terminated*/ + { + wait_ms(5); + if(DRDY==1) + { + printf("\n\r DRDY is high\n"); + SSN_MAG=0; + spi_acs.write(0xc9); //command byte for retrieving data + unsigned char axis; + float Bnewvalue[3]={0.0,0.0,0.0}; + int32_t Bvalue[3]={0,0,0}; + int32_t a= pow(2.0,24.0); + int32_t b= pow(2.0,23.0); + for(axis=0;axis<3;axis++) + { + Bvalue[axis]=spi_acs.write(0x00)<<16; //MSB 1 is send first + wait_ms(10); + Bvalue[axis]|=spi_acs.write(0x00)<<8; //MSB 2 is send next + wait_ms(10); + Bvalue[axis]|=spi_acs.write(0x00); //LSB is send.....total length is 24 bits(3*8bits)...which are appended to get actual bit configuration + if((Bvalue[axis]&b)==b) + { + Bvalue[axis]=Bvalue[axis]-a; //converting 2s complement to signed decimal + + } + Bnewvalue[axis]=(float)Bvalue[axis]*22.0*pow(10.0,-3.0); //1 LSB=(22nT)...final value of field obtained in micro tesla + wait_ms(10); + + mag_field[axis] = Bnewvalue[axis]; + printf("\t%lf\n\r",mag_field[axis]); + } + SSN_MAG=1; + printf("\n\r exited magnetometer function\n"); + //return Bnewvalue; //return here? doubt.. + + break; + } + } +} +/*------------------------------------------------------------------------------------------------------------------------------------------------------ +-------------------------------------------torque to moment conversion------------------------------------------------------------------------------------------*/ +void moment_calc (float tauc[3], float b[3], float moment[3]) +{ + float b1; + b1 = pow(b[0],2) + pow(b[1],2) +pow(b[2],2) ; + printf("\nvalue of b is %f\n",b1); + moment[0] = ((tauc[1]*b[2])-(tauc[2]*b[1]))/b1; + moment[1] = ((tauc[2]*b[0])-(tauc[0]*b[2]))/b1; + moment[2] = ((tauc[0]*b[1])-(tauc[1]*b[0]))/b1; + +} + + +/*------------------------------------------------------------------------------------------------------------------------------------------------------ +-------------------------------------------CONTROL ALGORITHM------------------------------------------------------------------------------------------*/ + +void FUNC_ACS_CNTRLALGO(float *b,float *omega,float tauc[3]) +{ + + float db[3]; // inputs + //initialization + float bb[3] = {0, 0, 0}; + float d[3] = {0, 0, 0}; + float Jm[3][3] = {{0.2730, 0, 0}, {0, 0.3018, 0}, {0, 0, 0.3031}}; + float den = 0; + float den2; + int i, j; //temporary variables + float Mu[2], z[2], dv[2], v[2], u[2]; //outputs + float invJm[3][3]; + float kmu2 = 0.07, gamma2 = 1.9e4, kz2 = 0.4e-2, kmu = 0.003, gamma = 5.6e4, kz = 0.1e-4; + printf("\n\r Entered cntrl algo\n\r"); + for(int i=0; i<3; i++) + { + printf("%f\t",omega[i]); + } + for(int i=0; i<3; i++) + { + printf("%f\t",b[i]); + } + //structure parameters + void inverse (float mat[3][3], float inv[3][3]); + void getInput (float x[9]); + tauc[0] =tauc[1] =tauc[2]=0 ; + + den = sqrt((b[0]*b[0]) + (b[1]*b[1]) + (b[2]*b[2])); + den2 = (b[0]*db[0]) + (b[1]*db[1]) + (b[2]*db[2]); + for(i=0;i<3;i++) + { + db[i] = (db[i]*den*den-b[i]*den2) / (pow(den,3)); + //db[i]/=den*den*den; + } + for(i=0;i<3;i++) //gotta check what is this + { + printf("\n\rreached here\n\r"); + if(den!=0) + b[i]=b[i]/den; //there is a problem here. The code gets stuck here. Maf value is required + } + + // select kz, kmu, gamma + if(b[0]>0.9 || b[0]<-0.9) + { + kz = kz2; + kmu = kmu2; + gamma = gamma2; + } + // calculate Mu, v, dv, z, u + for(i=0;i<2;i++) + { + Mu[i] = b[i+1]; + v[i] = -kmu*Mu[i]; + dv[i] = -kmu*db[i+1]; + z[i] = db[i+1] - v[i]; + u[i] = -kz*z[i] + dv[i]-(Mu[i] / gamma); + } + inverse(Jm, invJm); + // calculate cross(omega,J*omega)for(i=0;i<3;i++) + for(i=0; i<3; i++) // for loop included after checking original code + { + for(j=0;j<3;j++) + bb[i] += omega[j]*(omega[(i+1)%3]*Jm[(i+2)%3][j] - omega[(i+2)%3]*Jm[(i+1)%3][j]); + } + // calculate invJm*cross(omega,J*omega) store in d + for(i=0;i<3;i++) + { + for(j=0;j<3;j++) + d[i] += bb[j]*invJm[i][j]; + } + // calculate d = cross(invJm*cross(omega,J*omega),b) -cross(omega,db) + // bb =[0;u-d(2:3)] + // store in bb + bb[1] = u[0] + (d[0]*b[2])-(d[2]*b[0])-(omega[0]*db[2]) + (omega[2]*db[0]); + bb[2] = u[1]-(d[0]*b[1]) + (d[1]*b[0]) + (omega[0]*db[1])-(omega[1]*db[0]); + bb[0] = 0; + // calculate N + // reusing invJm as N + for(i=0;i<3;i++) + { + d[i] = invJm[1][i]; + invJm[ 1][i] = b[2]*invJm[0][i] - b[0]*invJm[2][i]; + invJm[2][i] = -b[1]*invJm[0][i] + b[0]*d[i]; + invJm[0][i] = b[i]; + } + // calculate inv(N) store in Jm + inverse(invJm, Jm); + // calculate tauc + printf("\n \r calculatin tauc"); + for(i=0;i<3;i++) + { + for(j=0;j<3;j++) + tauc[i] += Jm[i][j]*bb[j]; + printf(" %f \t",tauc[i]); + } +} + + +void inverse(float mat[3][3], float inv[3][3]) +{ +int i, j; +float det = 0; +for(i=0;i<3;i++) +{ for(j=0;j<3;j++) +inv[j][i] = (mat[(i+1)%3][(j+1)%3]*mat[(i+2)%3][(j+2)%3]) - (mat[(i+2)%3] +[(j+1)%3]*mat[(i+1)%3][(j+2)%3]); +} +det += (mat[0][0]*inv[0][0]) + (mat[0][1]*inv[1][0]) + (mat[0][2]*inv[2][0]); +for(i=0;i<3;i++) +{ for(j=0;j<3;j++) +inv[i][j] /= det; +} +} + + +/*------------------------------------------------------------------------------------------------------------------------------------------------------- +-------------------------------------------GYROSCOPE-------------------------------------------------------------------------------------------------*/ + +void trSub(); +void drSub(); +void init_gyro(); +float * FUNC_ACS_EXEC_GYR(); + +void drSub() //In this function we setting data-ready flag to 1 +{ + drFlag=1; + //printf("\n dr interrupt detected"); +} +void trSub() //In this function we are setting ticker flag to 0 +{ + trFlag=0; +} +void FUNC_ACS_INIT_GYR() +{ + uint8_t response; + ssn_gyr=1; //Deselecting the chip + spi_acs.format(8,0); // Spi format is 8 bits, and clock mode 3 + spi_acs.frequency(1000000); //frequency to be set as 1MHz + drFlag=0; //Intially defining data-ready flag to be 0 + dr.mode(PullDown); + dr.rise(&drSub); + __disable_irq(); + + /*initializing the register and changing its configuration*/ + ssn_gyr=0; //Selecting chip(Mpu-3300) + spi_acs.write(USER_CTRL|READFLAG); //sending USER_CTRL address with read bit + response=spi_acs.write(DUMMYBIT); //sending dummy bit to get default values of the register + + ssn_gyr=1; //Deselecting the chip + wait(0.1); //waiting according the product specifications + + ssn_gyr=0; //again selecting the chip + spi_acs.write(USER_CTRL); //sending USER_CTRL address without read bit + spi_acs.write(response|BIT_I2C_IF_DIS); //disabling the I2C mode in the register + ssn_gyr=1; //deselecting the chip + wait(0.1); // waiting for 100ms before going for another register + + ssn_gyr=0; + spi_acs.write(PWR_MGMT_1|READFLAG); //Power Management register-1 + response=spi_acs.write(DUMMYBIT); + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(PWR_MGMT_1); + response=spi_acs.write(response|BIT_CLKSEL_X); //Selecting the X axis gyroscope as clock as mentioned above + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(GYRO_CONFIG|READFLAG); //sending GYRO_CONFIG address with read bit + response=spi_acs.write(DUMMYBIT); + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(GYRO_CONFIG); //sending GYRO_CONFIG address to write to register + spi_acs.write(response&(~(BITS_FS_SEL_3|BITS_FS_SEL_4))); //selecting a full scale mode of +/=225 deg/sec + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(CONFIG|READFLAG); //sending CONFIG address with read bit + response=spi_acs.write(DUMMYBIT); + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(CONFIG); //sending CONFIG address to write to register + spi_acs.write(response|BITS_DLPF_CFG); //selecting a bandwidth of 42 hz and delay of 4.8ms + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(SMPLRT_DIV|READFLAG); //sending SMPLRT_DIV address with read bit + response=spi_acs.write(DUMMYBIT); + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(SMPLRT_DIV); //sending SMPLRT_DIV address to write to register + spi_acs.write(response&BITS_SMPLRT_DIV); //setting the sampling rate division to be 0 to make sample rate = gyroscopic output rate + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(INT_ENABLE|READFLAG); //sending address of INT_ENABLE with readflag + response=spi_acs.write(DUMMYBIT); //sending dummy byte to get the default values of the + // regiser + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(INT_ENABLE); //sending INT_ENABLE address to write to register + spi_acs.write(response|BIT_DATA_RDY_ENABLE); //Enbling data ready interrupt + ssn_gyr=1; + wait(0.1); + + __enable_irq(); +} + +void FUNC_ACS_EXEC_GYR(float*omega) +{ + printf("\n\rEntered gyro\n\r"); + uint8_t response; + uint8_t MSB,LSB; + int16_t bit_data; + float data[3],error[3]={0,0,0}; //declaring error array to add to the values when required + float senstivity = 145.6; //senstivity is 145.6 for full scale mode of +/-225 deg/sec + ssn_gyr=0; + spi_acs.write(PWR_MGMT_1|READFLAG); //sending address of INT_ENABLE with readflag + response=spi_acs.write(DUMMYBIT); // + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(PWR_MGMT_1); //sending PWR_MGMT_1 address to write to register + response=spi_acs.write(response&(~(BIT_SLEEP))); //waking up the gyroscope from sleep + ssn_gyr=1; + wait(0.1); + + trFlag=1; + tr.attach(&trSub,1); //executes the function trSub afer 1sec + + while(trFlag) + { + // printf("\n\r check1"); + wait_ms(5); //This is required for this while loop to exit. I don't know why. + if(drFlag==1) + { + //printf("\n\r check2"); + ssn_gyr=0; + spi_acs.write(GYRO_XOUT_H|READFLAG); //sending address of PWR_MGMT_1 with readflag + for(int i=0;i<3;i++) + { + MSB = spi_acs.write(DUMMYBIT); //reading the MSB values of x,y and z respectively + LSB = spi_acs.write(DUMMYBIT); //reading the LSB values of x,y and z respectively + bit_data= ((int16_t)MSB<<8)|LSB; //concatenating to get 16 bit 2's complement of the required gyroscope values + data[i]=(float)bit_data; + data[i]=data[i]/senstivity; //dividing with senstivity to get the readings in deg/sec + data[i]+=error[i]; //adding with error to remove offset errors + } + ssn_gyr=1; + for (int i=0;i<3;i++) + { + printf("%f\t",data[i]); //printing the angular velocity values + omega[i] = data[i]; + } + printf("\n\r"); + break; + } + drFlag=0; + } + ssn_gyr=0; + spi_acs.write(PWR_MGMT_1|READFLAG); //sending address of PWR_MGMT_1 with readflag + response=spi_acs.write(DUMMYBIT); + ssn_gyr=1; + wait(0.1); + + ssn_gyr=0; + spi_acs.write(PWR_MGMT_1); //sending PWR_MGMT_1 address to write to register + response=spi_acs.write(response|BIT_SLEEP); //setting the gyroscope in sleep mode + ssn_gyr=1; + wait(0.1); + printf("\n\rExited gyro\n\r"); + +} + + + + + +
diff -r 000000000000 -r e91ee0e99213 ACS.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ACS.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,12 @@ +#include "mbed.h" +#include "math.h" + +void FUNC_ACS_GENPWM(float *); +void FUNC_ACS_MAG_EXEC(float *); +void FUNC_ACS_MAG_INIT(); +//void Read_data_acs() +void moment_calc (float* , float* , float* ); +void FUNC_ACS_CNTRLALGO(float*,float*,float a[]); +void FUNC_ACS_EXEC_GYR(float*); +void FUNC_ACS_INIT_GYR(); +
diff -r 000000000000 -r e91ee0e99213 HK.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HK.cpp Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,190 @@ +#include "HK.h" +#include "pin_config.h" + + +//GPIO pins used=> D2-D12, A0-A1 + +DigitalOut SelectLinesA[]={PIN43,PIN44,PIN45,PIN46}; //to mux1=>voltage mux , PTA 13-16 , CHNGE TO PIN43 LATER +DigitalOut SelectLinesB[]={PIN56,PIN57,PIN58,PIN59}; //to mux2=>current mux(differential mux) , PTB 3,7,8,9 +DigitalOut SelectLinesC[]={PIN64,PIN65,PIN66,PIN67}; //to mux3=>temp mux PTB 18-21 + +//--------------------------------------------MSB is SelectLines[0],LSB is SelectLines[3]-------------------------------- + +AnalogIn CurrentInput(PIN54); // output from Current Mux PTB0 +AnalogIn VoltageInput(PIN53); // output from Voltage Multiplexer PTB1 +AnalogIn TemperatureInput(PIN55); /*PTB2 output from Temperature Multiplexer,thermistor Multiplexer- same multiplexer for both(lines 1-4 for thermistor,line 0 for temperature sensor)*/ + + + +int quantiz(float start,float step,float x) // accepts min and measured values and step->quantises on a scale 0-15..(4 bit quantisation) +{ + int y=(x-start)/step; + if(y<=0)y=0; + if(y>=15)y=15; + return y; +} + +void init_beacon(ShortBeacy* x,SensorDataQuantised y) +{ + (*x).Voltage[0]=2; //quantised value + (*x).Temp[0]=y.PanelTemperature[0]; //quantised value + (*x).Temp[1]=y.PanelTemperature[1]; //quantised value + (*x).AngularSpeed[0]=y.AngularSpeed[0]; + (*x).AngularSpeed[1]=y.AngularSpeed[1]; + + (*x).SubsystemStatus[0]=145; //dummy values----------to be changed------------------- + (*x).ErrorFlag[0]=3; //dummy values----------to be changed------------------- +} + +SensorData Sensor; +SensorDataQuantised SensorQuantised; +ShortBeacy Shortbeacon; +void FUNC_HK_MAIN() +{ + //define structure variables + + //initialise all selectlines to zeroes->1st line of muxes selected + SelectLinesA[0]=SelectLinesA[1]=SelectLinesA[2]=SelectLinesA[3]=0; + SelectLinesB[0]=SelectLinesB[1]=SelectLinesB[2]=0; + SelectLinesC[0]=SelectLinesC[1]=SelectLinesC[2]=SelectLinesC[3]=0; + + int LoopIterator; + int SelectLineIterator; + + float resistance_thermistor,voltage_thermistor;//for thermistor + + //measurement from voltage sensor=> 16 sensors in place + for(LoopIterator=0; LoopIterator<16; LoopIterator++) + { + //read the sensor values and stores them in 'SensorData' structure's variable 'Sensor' + Sensor.Voltage[LoopIterator]=(VoltageInput.read()*3.3*5.545454);//resistors in voltage divider=>15Mohm,3.3Mohm + + if(LoopIterator%2==0) + SensorQuantised.Voltage[LoopIterator/2]=quantiz(vstart,vstep,Sensor.Voltage[LoopIterator]); + + else + SensorQuantised.Voltage[(LoopIterator)/2]=SensorQuantised.Voltage[(LoopIterator)/2]<<4+quantiz(vstart,vstep,Sensor.Voltage[LoopIterator]); + + //iterate the select lines from 0 to 15 + for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--) + { + if(SelectLinesA[SelectLineIterator]==0) + { + SelectLinesA[SelectLineIterator]=1; + break; + } + else SelectLinesA[SelectLineIterator]=0; + } + + wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + } + + + //measurement from current sensor=> 8 sensors in place + for(LoopIterator=0; LoopIterator<8; LoopIterator++) + { + //read the sensor values and stores them in 'SensorData' structure variable 'Sensor' + Sensor.Current[LoopIterator]=(CurrentInput.read()*3.3/(50*rsens)); + if(LoopIterator%2==0) + SensorQuantised.Current[LoopIterator/2]=quantiz(cstart,cstep,Sensor.Current[LoopIterator]); + else + SensorQuantised.Current[(LoopIterator)/2]=SensorQuantised.Current[(LoopIterator)/2]<<4+quantiz(cstart,cstep,Sensor.Current[LoopIterator]); + + //iterate the select lines from 0 to 7 + for(SelectLineIterator=2;SelectLineIterator>=0;SelectLineIterator--) + { + if(SelectLinesB[SelectLineIterator]==0) + { + SelectLinesB[SelectLineIterator]=1; + break; + } + else SelectLinesB[SelectLineIterator]=0; + + } + + wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + } + + + //measurement of temperature + //temperature measurement=> 4 thermistors, 1 temperature sensor + //mux line 1=>temp sensor, mux lines 2 to 5 =>thermistors + + for(LoopIterator=0; LoopIterator<5; LoopIterator++) + { + //read the sensor values and stores them in 'SensorData' structure variable 'Sensor' + Sensor.Temperature[LoopIterator]=(-90.7*3.3*TemperatureInput.read()+190.1543); + voltage_thermistor=TemperatureInput.read()*3.3;//voltage across thermistor + resistance_thermistor=24000*voltage_thermistor/(3.3-voltage_thermistor);//resistance of thermistor + if (LoopIterator==0) + { + printf(" \n\rTemp =%f",-90.7*3.3*TemperatureInput.read()+190.1543); + } + + if(LoopIterator%2==0) + { + if(LoopIterator<1) //->corresponding to temperature sensor + SensorQuantised.Temperature[(LoopIterator)/2]=quantiz(tstart,tstep,Sensor.Temperature[LoopIterator]); + + else //->corresponding to thermistor + { + if(voltage_thermistor<1.378) //Temperature>12 degC + Sensor.PanelTemperature[(LoopIterator-1)]=(3694/log(24.032242*resistance_thermistor)); + + else + Sensor.PanelTemperature[(LoopIterator-1)]=(3365.4792/log(7.60404*resistance_thermistor)); + + + SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=quantiz(tstart_thermistor,tstep_thermistor,Sensor.PanelTemperature[(LoopIterator-1)]); + + } + } + else + { + if(LoopIterator<1) + SensorQuantised.Temperature[(LoopIterator)/2]=SensorQuantised.Temperature[(LoopIterator)/2]<<4+quantiz(tstart,tstep,Sensor.Temperature[LoopIterator]); + + else + { + if(voltage_thermistor<1.378) //Temperature>12 degC + Sensor.PanelTemperature[LoopIterator-1]=(3694/log(24.032242*resistance_thermistor)); + else + Sensor.PanelTemperature[LoopIterator-1]=(3365.4792/log(7.60404*resistance_thermistor)); + + SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=SensorQuantised.PanelTemperature[(LoopIterator-1)/2]<<4+quantiz(tstart_thermistor,tstep_thermistor,Sensor.PanelTemperature[LoopIterator-1]); + } + } + // The following lines are used to iterate the select lines from 0 to 4 + for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--) + { + if(SelectLinesC[SelectLineIterator]==0) + { + SelectLinesC[SelectLineIterator]=1; + break; + } + else SelectLinesC[SelectLineIterator]=0; + } + + wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + } + + + //update magnetometer data-> + //populate values in structure variable 'Sensor' from data to be given by Green + SensorQuantised.AngularSpeed[0]=quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[1]); + SensorQuantised.AngularSpeed[0]=SensorQuantised.AngularSpeed[0]<<4+quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[0]); + SensorQuantised.AngularSpeed[1]=quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[2]); + + //update gyro data-> + //populate values in structure variable 'Sensor' from data to be given by Green + SensorQuantised.Bnewvalue[0]=quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[1]); + SensorQuantised.Bnewvalue[0]=SensorQuantised.Bnewvalue[0]<<4+quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[0]); + SensorQuantised.Bnewvalue[1]=quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[2]); + + //update beacon structure + init_beacon(&Shortbeacon,SensorQuantised);//Shortbeacon is passed + printf("\n here temperature :%d",SensorQuantised.Temperature); +} + + +
diff -r 000000000000 -r e91ee0e99213 HK.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HK.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,69 @@ +//to be saved as HK.h + +#include "mbed.h" +#define tstart -40 +#define tstep 8 +#define tstep_thermistor 8//verify!! +#define tstart_thermistor -40 +#define vstart 3.3 +#define vstep 0.84667 +#define cstart 0.0691 +#define cstep 0.09133 +#define rsens 0.095 +#define Bnewvalue_start -100//in microTesla...max possible field is .0001 T +#define Bnewvalue_step 13.333 +#define AngularSpeed_start -10//max possible ang. velocity in space is 10 deg/sec +#define AngularSpeed_step 1.3333 + + + +typedef struct SensorData +{ + float Voltage[16]; + float Current[8]; + float Temperature[1]; + float PanelTemperature[4]; + float BatteryTemperature; //to be populated + char faultpoll; //polled faults + char faultir; //interrupted faults + char power_mode; //power modes + + float AngularSpeed[3]; //in order x,y,z + float Bnewvalue[3]; //in order Bx,By,Bz + + +} SensorData; + + +typedef struct SensorDataQuantised { + char Voltage[8]; + char Current[4]; + char Temperature[1]; + char PanelTemperature[2];//read by the 4 thermistors on solar panels + char BatteryTemperature; //to be populated + char faultpoll; //polled faults + char faultir; //interrupted faults + char power_mode; //power modes + char AngularSpeed[2]; + char Bnewvalue[2]; + + //float magnetometer,gyro=>to be addes +} SensorDataQuantised; + + +typedef struct ShortBeacon +{ + char Voltage[1]; //battery voltage from gauge, needs to be quantised + char AngularSpeed[2]; //all the 3 data + char SubsystemStatus[1]; //power modes + char Temp[2]; //temp of solar panel + //Temp[0]'s LSB=> PanelTemperature[0], Temp[0]'s MSB=> PanelTemperature[1], Temp[1]'s LSB=> PanelTemperature[2], Temp[1]'s MSB=> PanelTemperature[3] + char ErrorFlag[1]; //fault +}ShortBeacy; + + + +void FUNC_HK_MAIN(); + +int quantiz(float start,float step,float x); +void init_beacon(ShortBeacy* x,SensorDataQuantised y);
diff -r 000000000000 -r e91ee0e99213 MPU3300.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MPU3300.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,26 @@ +//MPU 3300 registers +#define SMPLRT_DIV 0x19 +#define CONFIG 0x1A +#define GYRO_CONFIG 0x1B +#define GYRO_XOUT_H 0x43 +#define GYRO_XOUT_L 0x44 +#define GYRO_YOUT_H 0x45 +#define GYRO_YOUT_L 0x46 +#define GYRO_ZOUT_H 0x47 +#define GYRO_ZOUT_L 0x48 +#define USER_CTRL 0x6A +#define PWR_MGMT_1 0x6B +#define INT_ENABLE 0x38 + +//MPU configuration bits +#define READFLAG 0x80 +#define DUMMYBIT 0x00 +#define BITS_DLPF_CFG 0x07 +#define BITS_FS_SEL_3 0x08 +#define BITS_FS_SEL_4 0x10 +#define BIT_I2C_IF_DIS 0x10 +#define BITS_SMPLRT_DIV 0x00 +#define BIT_SLEEP 0x40 +#define BIT_DATA_RDY_ENABLE 0x01 +#define BIT_DATA_RDY_INT 0x01 +#define BIT_CLKSEL_X 0x01
diff -r 000000000000 -r e91ee0e99213 beacon.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beacon.cpp Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,200 @@ +//switch off the sync!!!!!!! +//switch off the preamble!!!!!!! +/*for crc in tx: +regIrq2(0x28) : + +regpacketconfig 1(0x37) : +set crc detection/calc. on : | 0x10 +crcautoclearoff : | 0x08 + +for data whitening : regpacketconfig 1(0x37) :| 0x40 +for + + + +*/ +// 6CC000 for 435 MHz +//set all values as FF for checking on spectrum analyzer +#include "beacon.h" +#include "HK.h" +Serial chavan(USBTX, USBRX); // tx, rx +SPI spi(PIN2,PIN1,PIN3); // mosi, miso, sclk +DigitalOut cs_bar(PIN6); //slave select or chip select +//InterruptIn button(p9); +//#define TIMES 16 +//Timer t; + +/*void interrupt_func() +{ + chavan.printf("INTERRUPT_FUNC TRIGGERED\n wait for 3 secs\n"); + wait(3); + +}*/ + +extern ShortBeacy Shortbeacon; +void writereg(uint8_t reg,uint8_t val) +{ + cs_bar = 0; + spi.write(reg | 0x80); + spi.write(val); + cs_bar = 1; +} +uint8_t readreg(uint8_t reg) +{ + uint8_t val; + cs_bar = 0; + spi.write(reg & ~0x80); + val = spi.write(0); + cs_bar = 1; + return val; +} + +void FUNC_BEA() { + + //button.rise(&interrupt_func); //interrupt enabled ( rising edge of pin 9) + printf("\n\rBeacon function entered\n\r"); + wait(0.02); //takes 10 ms for POR event + 10ms for safety + + uint8_t byte_counter = 0; + + /*struct Short_beacon{ + uint8_t Voltage[1]; + uint8_t AngularSpeed[2]; + uint8_t SubsystemStatus[1]; + uint8_t Temp[3]; + uint8_t ErrorFlag[1]; + }Shortbeacon = { {0x22}, {0x22, 0x33} , {0x00},{0x00,0x00,0x00}, {0xFE} }; + */ + //filling hk data + //ShortBeacon Shortbeacon; + uint8_t short_beacon[] = { 0xAB, 0x8A, 0xE2, 0xBB, 0xB8, 0xA2, 0x8E,Shortbeacon.Voltage[0],Shortbeacon.AngularSpeed[0], Shortbeacon.AngularSpeed[1],Shortbeacon.SubsystemStatus[0],Shortbeacon.Temp[0],Shortbeacon.Temp[1],Shortbeacon.Temp[2],Shortbeacon.ErrorFlag[0]}; + + //mask + //uint8_t mask[] = {0x80, 0x40, 0x20,0x10,0x8,0x4,0x2,0x1}; + + for(int i = 0; i < 15 ; i++) + { + chavan.printf("0x%X\n\r",(short_beacon[i])); + } + + spi.format(8,0); + spi.frequency(10000000); //10MHz SCLK frequency(its max for rfm69hcw) + cs_bar = 1; // Chip must be deselected + + //initialization + //Common configuration registers + writereg(0x01,0x04); //sequencer on,standby mode + writereg(0x02,0x08); //packet-mode used , ook modultion , no dc-shaping + writereg(0x03,0x68); //1200bps datarate + writereg(0x04,0x2B); //1200bps datarate + writereg(0x07,0x6C); //Frequency MSB + writereg(0x08,0xC0); //Frequency MID + writereg(0x09,0x00); //Frequency LSB ....6C C0 00 for 435 MHZ + + //Transmitter registers + // RegPaLevel(default +13 dBm) + + //IRQ and Pin Mapping Registers + //no DIO mapped yet + //regirq1(0x27): modeready (8th bit) will be checked for interrupts + //regIrq2(0x28): fifothresh (5th bit) ,packetsent(3rd bit) will be checked for interrupts + + //Packet Engine Registers + writereg(0x2C,0x00); //set preamble + writereg(0x2D,0x0A); //set preamble + writereg(0x2E,0x80); //sync off + writereg(0x2F,0x5E); //sync word 1 + writereg(0x37,0x08 | 0x40);// | 0x10); //packetconfig1, 0x40 for data whitening (only for testing) + writereg(0x38,0x00); //payload length = 0 ... unlimited payload mode + writereg(0x3C,0xB0); //fifothresh = 48 because we want it cleared once its 40!!!! + //Initialization complete + + //while(chavan.getc() == 't'){ + //t.start(); + //Filling Data into FIFO 64 BYTES : eff.32 bits = 4bytes //fread + cs_bar = 0; + spi.write(0x80);//fifo write access + for(byte_counter=0 ; byte_counter<4; byte_counter++) + { + for(int i=7; i>=0 ; i--) + { + if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!=0) + //if((short_beacon[byte_counter] & mask[i]) != 0) + { + spi.write(0xFF); + spi.write(0xFF); + } + else + { + spi.write(0x00); + spi.write(0x00); + } + } + } + cs_bar = 1; //cs_bar + + //Check for fifoThresh + printf("\n\rfor loop executed\n\r"); + while((readreg(0x28) & 0x20) != 0x20); + printf("\n\rwhile loop executed\n\r"); + //Highpower settings + writereg(0x11,0x7F); //RegPalevel (20db) //~ + writereg(0x13,0x0F); //RegOCP + writereg(0x5A,0x5D); //RegTestPa1 + writereg(0x5C,0x7C); //RegTestPa2 + + //Set to Tx mode + writereg(0x01,0x0C); + + printf("\n\rpre 2nd while loop\n\r"); + //Check for fifoThresh + while((readreg(0x28) & 0x20) != 0x00); + printf("\n\r2nd while loop executed\n\r"); + while(byte_counter!=15){ + + //writing again + cs_bar = 0; + spi.write(0x80); + for(int i=7; i>=0 ;i--) + { + if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!=0) + //if((short_beacon[byte_counter] & mask[i]) != 0) + { + spi.write(0xFF); + spi.write(0xFF); + } + else + { + spi.write(0x00); + spi.write(0x00); + } + } + cs_bar = 1; + byte_counter++; + + //Check for fifoThresh + while((readreg(0x28) & 0x20) != 0x00); + } + printf("\n\r3rd big while loop executed\n\r"); + //wait for packet sent bit to fire + while((readreg(0x28) & 0x08) != 0x08); + printf("\n\r4th while loop executed\n\r"); + //chavan.printf("packet sent!!! \n\r"); + + //Switch back to Standby Mode + writereg(0x01,0x04); + + //Lowpowermode + writereg(0x11,0x9F); //RegPalevel (13db) + writereg(0x13,0x1A); //RegOCP + writereg(0x5A,0x55); //RegTestPa1(setting PA_BOOST on RFIO) + writereg(0x5C,0x70); //RegTestPa2(setting PA_BOOST on RFIO) + + //wait for modeready + while((readreg(0x27)&0x80)!=0x80); + + //t.stop(); + //chavan.printf(" time taken to init + transmit = %f \n", t.read()) ; + //} +printf("\n\rBeacon function exiting\n\r"); +}
diff -r 000000000000 -r e91ee0e99213 beacon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beacon.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,5 @@ +#include "mbed.h" + +void writereg(uint8_t reg,uint8_t val); +uint8_t readreg(uint8_t reg); +void FUNC_BEA();
diff -r 000000000000 -r e91ee0e99213 fault.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fault.cpp Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,171 @@ +#include "fault.h" +#include "HK.h" + + +DigitalIn fault0(FAULT0,PullUp); +DigitalIn fault1(FAULT1,PullUp); +DigitalIn fault2(FAULT2,PullUp); +DigitalIn fault3(FAULT3,PullUp); +DigitalIn fault4(FAULT4,PullUp); +//DigitalIn fault5(FAULT5,PullUp); +//DigitalIn fault6(FAULT6,PullUp); +//DigitalIn fault7(FAULT7,PullUp); +//DigitalIn fault8(FAULT8,PullUp); + + +InterruptIn fault_IR1(FAULT5); +InterruptIn fault_IR2(FAULT6); +InterruptIn fault_IR3(FAULT7); +InterruptIn fault_IR4(FAULT8); +InterruptIn fault_IR5(FAULT9); + + + +DigitalOut clear1(FAULT_CLEAR1,0); +DigitalOut clear2(FAULT_CLEAR2,0); +DigitalOut clear3(FAULT_CLEAR3,0); +DigitalOut clear4(FAULT_CLEAR4,0); +DigitalOut clear5(FAULT_CLEAR5); +DigitalOut clear6(FAULT_CLEAR6); +DigitalOut clear7(FAULT_CLEAR7); +DigitalOut clear8(FAULT_CLEAR8); +DigitalOut clear9(FAULT_CLEAR9); + + +DigitalOut acs_active(ACS); + + +BusIn fault_poll(FAULT0,FAULT1,FAULT2,FAULT3,FAULT4); +BusIn fault_ir(FAULT5,FAULT6,FAULT7,FAULT8,FAULT9); + +BusOut clear_poll(FAULT_CLEAR1,FAULT_CLEAR2,FAULT_CLEAR3,FAULT_CLEAR4);//to send fault data along with hk +BusOut clear_ir(FAULT_CLEAR5,FAULT_CLEAR6,FAULT_CLEAR7,FAULT_CLEAR8,FAULT_CLEAR9); + + +extern SensorDataQuantised SensorQuantised; +extern int beacon_sc; //to switch beacon between low and high power mode +extern int acs_pflag; //to activate/deactivate control algo +char out_poll; +char out_ir; + +void FUNC_HK_FAULTS() +{ + + printf("Entered Fault management \n"); + /*if(fault0==0)printf("CHARGER IS CHARGING THE BATTERY "); + if(fault0==1)printf("CHRGER GONE OFFLINE, BATTERY DRAINING"); + + if(fault1==0) + { clear1=1;printf("");} + else + { clear1=0;} + + if(fault2==0) + { clear2=1;printf("");} + else + { clear2=0;} + + if(fault3==0) + { clear3=1;printf("");} + else + { clear3=0;} + + if(fault4==0) + { clear4=1;printf("");} + else + { clear4=0;}*/ + + + + + + + + + //clear1 = !fault1; + //clear2 = !fault2; + //clear3 = !fault3; + //clear4 = !fault4; + //clear5 = !fault5; + //clear6 = !fault6; + //clear7 = !fault7; + //clear8 = !fault8; + + + // out_poll = clear_poll; + //out_ir = clear_ir; + SensorQuantised.faultpoll = fault_poll ; + SensorQuantised.faultir=fault_ir ; + printf(" %d , %d \n ",SensorQuantised.faultpoll, SensorQuantised.faultir ) ; + +} + + + +void Clear_IR1() +{clear5=!clear5; +} + +void Clear_IR2() +{clear6=!clear6; +} + +void Clear_IR3() +{clear7=!clear7; +} + +void Clear_IR4() +{clear8=!clear8; +} + +void Clear_IR5() +{clear9=!clear9; +} + +void interrupt_fault() +{ + fault_IR1.rise(&Clear_IR1); + fault_IR2.rise(&Clear_IR2); + fault_IR3.rise(&Clear_IR3); + fault_IR4.rise(&Clear_IR4); + fault_IR5.rise(&Clear_IR5); + fault_IR1.fall(&Clear_IR1); + fault_IR2.fall(&Clear_IR2); + fault_IR3.fall(&Clear_IR3); + fault_IR4.fall(&Clear_IR4); + fault_IR5.fall(&Clear_IR5); +} + + +void FUNC_HK_POWER(char flag) //flag corresponds to the power mode +{ + printf("Entered Power Management \n"); + printf("Entering mode %c \n", flag); + switch (flag) + { + case '0': beacon_sc = 6; //least power mode + acs_pflag = 0; + acs_active = 0; //switching off a component of acs + break; + case '1': beacon_sc = 3; + acs_pflag = 0; + acs_active = 0; + break; + case '2': beacon_sc = 3; + acs_pflag = 0; + acs_active = 0; + break; + case '3': beacon_sc = 3; //normal mode + acs_pflag = 1; + acs_active = 1; + break; + } + /* if (flag == '0') + beacon_sc = 30; + else + beacon_sc = 3; + if (flag == '3') + acs_pflag = 1; + else + acs_pflag = 0; */ +} \ No newline at end of file
diff -r 000000000000 -r e91ee0e99213 fault.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fault.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" +#include "pin_config.h" + +#define FAULT0 PIN31 +#define FAULT1 PIN42 // FAULTBAR +#define FAULT2 PIN40 // 3V3APGOOD +#define FAULT3 PIN39 // 3V3BPGOOD +#define FAULT4 PIN41 // 3V3CPGOOD +#define FAULT5 PTC23 // 3V3AOCBAR //changed here +#define FAULT6 PIN80 // 3V3COC +#define FAULT7 PIN38 // SW8FAULT /// to pin 97 later +#define FAULT8 PIN83 // SW6FAULT +#define FAULT9 PIN89 // SW7FAULT + +//CONTROL SIGNALS +#define FAULT_CLEAR1 D8 +#define FAULT_CLEAR2 D9 +#define FAULT_CLEAR3 D10 +#define FAULT_CLEAR4 D11 +#define FAULT_CLEAR5 D12 +#define FAULT_CLEAR6 D13 +#define FAULT_CLEAR7 PTC7 +#define FAULT_CLEAR8 PTC10 +#define FAULT_CLEAR9 PTC11 + + + +#define ACS PTE2 +#define TX PTE3 +#define PAYLOAD PTE6 + + +void FUNC_HK_FAULTS(); +void FUNC_HK_POWER(char flag); +void interrupt_fault(); \ No newline at end of file
diff -r 000000000000 -r e91ee0e99213 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,408 @@ +#include "mbed.h" +#include "rtos.h" +#include "HK.h" +#include "slave.h" +#include "beacon.h" +#include "ACS.h" +#include "fault.h" +#include "slave.h" +#include "mnm.h" + +Serial pc(USBTX, USBRX); + +InterruptIn interrupt(D9); //I2c interrupt from CDMS +DigitalOut data_ready(D10); //Sends interrupt to CDMS + +Timer t; //To know the time of execution each thread +Timer t1; //To know the time of entering of each thread +Timer t2; //To check the time sync in i2c communication +Timer t3; //To know the time taken by i2c read/write function + +/*****************************************************************Threads USed***********************************************************************************/ +Thread *ptr_t_hk_acq; +Thread *ptr_t_acs; +Thread *ptr_t_bea; +Thread *ptr_t_i2c; +Thread *ptr_t_wdt; + +/****************************************************************configuring I2c*********************************************************************************/ +I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave + +int i2c_status=0; //read or write mode for i2c 0: write2slave 1: write2master +typedef struct //structure of i2c data +{ + char data[25]; + int length; +}i2c_data; + + +//Mail<i2c_data,16> i2c_data_receive; +Mail<i2c_data,16> i2c_data_send; + +//-------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK 2 : HK +//-------------------------------------------------------------------------------------------------------------------------------------------------- + +char hk_data[25]; +extern SensorDataQuantised SensorQuantised; +void T_HK_ACQ(void const *args) +{ + + while(1) + { + Thread::signal_wait(0x2); + SensorQuantised.power_mode='3'; //default power mode(dummy) + printf("\n\rTHIS IS HK %f\n\r",t1.read()); + t.start(); + FUNC_HK_FAULTS(); // !Actual fault management is not implemented + FUNC_HK_POWER(SensorQuantised.power_mode); // !The power mode algorithm is yet to be obtained + FUNC_HK_MAIN(); //Collecting HK data + FUNC_I2C_IR2CDMS(); //sending HK data to CDMS + t.stop(); + printf("The time to execute hk_acq is %f seconds\n\r",t.read()); + t.reset(); + } +} + +//--------------------------------------------------------------------------------------------------------------------------------------- +//TASK 1 : ACS +//--------------------------------------------------------------------------------------------------------------------------------------- + +int acs_pflag = 1; +void T_ACS(void const *args) +{ + float mag_field[3]; + float omega[3]; + float *mnm_data; + float mag_field1[3]; + float omega1[3]; + float tauc1[3]; + float moment[3]; + while(1) + { + Thread::signal_wait(0x1); + printf("\n\rEntered ACS %f\n",t1.read()); + t.start(); + FUNC_ACS_MAG_EXEC(mag_field); + printf("\n\r check"); + for(int i=0; i<3; i++) + { + printf("%f\t",mag_field[i]); + } + FUNC_ACS_EXEC_GYR(omega); + acs_pflag =1; //to be removed later + omega[0] = 1.0; + omega[1] = 1.0; + omega[2] = 1.0; + + + + /* mnm_data=EXECUTE_PNI(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 + printf("\n\rmnm gyro values\n"); //printing the angular velocity and magnetic field values + for(int i=0; i<3; i++) + { + printf("%f\t",mnm_data[i]); + } + printf("\n\r mnm mag values\n"); + for(int i=3; i<6; i++) + { + printf("%f\t",mnm_data[i]); + } + for(int i = 0 ; i<3;i++) + { + omega1[i] = mnm_data[i]; + } + for( int i = 3;i<6;i++) + { + mag_field1[i-3] = mnm_data[i]; + } + */ + if(acs_pflag == 1) + { + + FUNC_ACS_CNTRLALGO(mag_field,omega,tauc1); + printf("\n\r control algo values "); + for(int i=0; i<3; i++) + { + printf("%f\t",tauc1[i]); + } + moment_calc (tauc1, mag_field,moment); + printf("\n\r moment values "); + for(int i=0; i<3; i++) + { + printf("%f\t",moment[i]); + } + FUNC_ACS_GENPWM(moment); + } + t.reset(); + } +} + +//---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- + +int beac_flag=0; //To receive telecommand from ground. + + +/*void T_BEA_TELECOMMAND(void const *args) +{ + char c = pc.getc(); + if(c=='a') + { + printf("Telecommand detected\n\r"); + beac_flag=1; + } +} +*/ + +void T_BEA(void const *args) +{ + + while(1) + { + Thread::signal_wait(0x3); + printf("\n\rTHIS IS BEACON %f\n\r",t1.read()); + t.start(); + FUNC_BEA(); + if(beac_flag==1) + { + Thread::wait(600000); + beac_flag = 0; + } + printf("The time to execute beacon thread is %f seconds\n\r",t.read()); + t.reset(); + } +} + + + +extern SensorDataQuantised SensorQuantised; + +/*------------------------------------------------------------------------------------------------------------------------------------------- +-------------------------------------------------------WATCHDOG----------------------------------------------------------------------------*/ +DigitalOut trigger(PIN63); // has to be changed +void T_WDT(void const * args) +{ + trigger = 1; + while(true) + { + Thread::signal_wait(0x5); //signal set from scheduler or sthing. r RTOS timer nce the timing is finalized + printf("\n\rEntered WD\n\r"); + trigger = !trigger; + } +} + +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK 5 : i2c data +//--------------------------------------------------------------------------------------------------------------------------------------------------- + +void FUNC_I2C_WRITE2CDMS(char *data, int length=1) +{ + int slave_status = 1; + if(interrupt ==1) + { + if(slave.receive() == 0) + t2.stop(); + if( slave.receive()==1) + { + t2.stop(); + t3.start(); + slave_status=slave.write(data,length); + t3.stop(); + } + else if( slave.receive()==3 || slave.receive()==2) + { + t2.stop(); + t3.start(); + slave_status=slave.read(data,length); + t3.stop(); + } + } + printf("\n\r%d\r",t2.read_us()); + t2.reset(); + printf("\n\r%d\r",t3.read_us()); + t3.reset(); +} + +char data_send[25],data_receive; +void T_I2C_BAE(void const * args) +{ + while(1) + { + Thread::signal_wait(0x4); + if(i2c_status == 0 ) + { + wait_ms(23); + FUNC_I2C_WRITE2CDMS(&data_receive,1); + /*i2c_data * i2c_data_r = i2c_data_receive.alloc(); + i2c_data_r->data = data_receive; + i2c_data_r->length = 1; + i2c_data_receive.put(i2c_data_r);*/ + printf("\n\r Data received from CDMS is %c \n\r",data_receive); + FUNC_I2C_TC_EXECUTE(data_receive); // This has to be done from a differen thread + + } + else if(i2c_status ==1) + { + osEvent evt = i2c_data_send.get(); + if (evt.status == osEventMail) + { + i2c_data *i2c_data_s = (i2c_data*)evt.value.p; + strcpy(data_send,i2c_data_s -> data); + wait_ms(29); + FUNC_I2C_WRITE2CDMS(data_send,25); + printf("\n\rData sent to CDMS is %s\n\r",data_send); + + i2c_data_send.free(i2c_data_s); + i2c_status = 0; + } + } + + } +} + + + +void FUNC_I2C_INT() +{ + + t2.start(); + // t3.start(); + ptr_t_i2c->signal_set(0x4); + + +} + +void FUNC_I2C_IR2CDMS() +{ + data_ready=0; + //char data[25]; + strcpy(hk_data,"hk_Data"); + strcat(hk_data,SensorQuantised.Voltage); + strcat(hk_data,SensorQuantised.Current); + strcat(hk_data,SensorQuantised.Temperature); + strcat(hk_data,SensorQuantised.PanelTemperature); + strcat(hk_data,SensorQuantised.AngularSpeed); + strcat(hk_data,SensorQuantised.Bnewvalue); + char fdata[5] = {SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir,SensorQuantised.power_mode}; + + /*strcat(hk_data,sfaultpoll); + strcat(hk_data,sfaultir); + strcat(hk_data,spower_mode);*/ + strcat(hk_data,fdata); + printf("\n\r hk data being sent %s ",hk_data); + //for(int i=0;i<100000000000;i++) + //; + + /*for(int d=0;d<23;d++) //was written just to check hk data + { + if(hk_data[d]>10) + printf("\n\rhk data : %d\n\r",hk_data[d]); + } */ + + //data = pcslave.getc(); + + i2c_status=1; + i2c_data * i2c_data_s = i2c_data_send.alloc(); + strcpy(i2c_data_s->data,hk_data); + i2c_data_s->length = 25; + i2c_data_send.put(i2c_data_s); + data_ready=1; + //temp = i2c_status; +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------ +//TELECOMMAND +//------------------------------------------------------------------------------------------------------------------------------------------------ +void FUNC_I2C_TC_EXECUTE (char command) +{ switch(command) + { case '0' : printf("command 0 executed"); + break; + case '1' : printf("command 1 executed"); + break; + case '2' : printf("command 2 executed"); + break; + case '3' : printf("command 3 executed"); + } +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------ +//SCHEDULER +//------------------------------------------------------------------------------------------------------------------------------------------------ +int beacon_sc = 3; +uint16_t schedcount=1; +void T_SC(void const *args) +{ + //DRDY=0; + printf("The value of i in scheduler is %d\n\r",schedcount); + if(schedcount == 65532) //to reset the counter + { + schedcount = 0; + } + + if(schedcount%1==0) + { + ptr_t_acs -> signal_set(0x1); + //ptr_t_wdt -> signal_set(0x5); + } + if(schedcount%2==0) + { + // ptr_t_fault -> signal_set(0x2); + //ptr_t_hk_acq -> signal_set(0x2); + + } + if(schedcount%beacon_sc==0) + { + if(beac_flag==0) + { + + //ptr_t_bea -> signal_set(0x3); + } + } + schedcount++; +} + +//--------------------------------------------------------------------------------------------------------------------------------------------- + +int main() +{ + t1.start(); + printf("\n\rIITMSAT BAE Activated \n"); + INIT_PNI(); // Initializing mnm blue + FUNC_ACS_MAG_INIT(); // Initializing magnetometer + //FUNC_ACS_INIT_GYR(); // Initializing Gyroscope + slave.address(0x20); // setting slave address for BAE for I2C communication + + ptr_t_hk_acq = new Thread(T_HK_ACQ); + ptr_t_acs = new Thread(T_ACS); + ptr_t_bea = new Thread(T_BEA); + ptr_t_i2c = new Thread(T_I2C_BAE); + //ptr_t_sc = new Thread(T_SC); + ptr_t_wdt = new Thread(T_WDT); + + interrupt_fault(); // Dummy function called when a fault interrupt is detected + + ptr_t_acs->set_priority(osPriorityAboveNormal); + ptr_t_i2c->set_priority(osPriorityHigh); + ptr_t_hk_acq->set_priority(osPriorityAboveNormal); + ptr_t_bea->set_priority(osPriorityAboveNormal); + //ptr_t_sc->set_priority(osPriorityAboveNormal); + ptr_t_wdt -> set_priority(osPriorityIdle); + + + // ---------------------------------------------------------------------------------------------- + printf("\n\r T_ACS priority is %d",ptr_t_acs->get_priority()); + printf("\n\r T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority()); + printf("\n\r T_BEA priority is %d",ptr_t_bea->get_priority()); + RtosTimer t_sc_timer(T_SC,osTimerPeriodic); + t_sc_timer.start(10000); + printf("\n\r%f\n\r",t1.read()); + + // interrupt.rise(&FUNC_I2C_INT); //interrupt received from CDMS + while(1) //required to prevent main from terminating + { + Thread::wait(5000); + } + +}
diff -r 000000000000 -r e91ee0e99213 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#13a25134ac60
diff -r 000000000000 -r e91ee0e99213 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file
diff -r 000000000000 -r e91ee0e99213 mnm.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mnm.cpp Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,164 @@ +#include<mbed.h> +#include "mnm.h" +#include "pin_config.h" +#include "pni.h" //pni header file +Serial mnm(USBTX,USBRX); //for usb communication +I2C i2c (PIN85,PIN84); //PTC9-sda,PTC8-scl +/*void INIT_PNI(void); //initialization of registers happens +float *EXECUTE_PNI(); //data is obtained +void T_OUT(); //timeout function to stop infinite loop*/ +Timeout to; //Timeout variable to +int toFlag; +void T_OUT() +{ + toFlag=0; //as T_OUT function gets called the while loop gets terminated +} + +//DEFINING VARIABLES +char cmd[2]; +char raw_gyro[6]; +char raw_mag[6]; +char store,status; +int16_t bit_data; +float gyro_data[3], mag_data[3],combined_values[6],*data; +float senstivity_gyro =6.5536; //senstivity is obtained from 2^15/5000dps +float senstivity_mag =32.768; //senstivity is obtained from 2^15/1000microtesla +float gyro_error[3]= {0,0,0}, mag_error[3]= {0,0,0}; + +Timer r0; +Timer r1; +Timer r2; +Timer r3; +Timer r4; + + +/* +int main(void) +{ + + INIT_PNI(); + data=EXECUTE_PNI(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 + mnm.printf("gyro values\n"); //printing the angular velocity and magnetic field values + for(int i=0; i<3; i++) { + mnm.printf("%f\t",data[i]); + } + mnm.printf("mag values\n"); + for(int i=3; i<6; i++) { + mnm.printf("%f\t",data[i]); + } +}*/ + +void INIT_PNI() +{ r0.start(); + cmd[0]=RESETREQ; + cmd[1]=BIT_RESREQ; + i2c.write(SLAVE_ADDR,cmd,2); + r0.stop(); //When 0x01 is written in reset request register Emulates a hard power down/power up + wait_ms(2000); //waiting for loading configuration file stored in EEPROM + cmd[0]=SENTRALSTATUS; + r1.start(); + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&store,1); + r1.stop(); + wait_ms(100); + //to check whether EEPROM is uploaded + + /* switch((int)store) { + case(3): { + printf("\nstore :%d\n",store); + break; + } + case(11): { + printf("\nstore11 :%d\n",store); + break; + } + default: { + cmd[0]=RESETREQ; + cmd[1]=BIT_RESREQ; + i2c.write(SLAVE_ADDR,cmd,2); + wait_ms(2000); + } + }*/ + //mnm.printf("Sentral Status is %x\n",(int)store); + r2.start(); + cmd[0]=HOST_CTRL; //0x01 is written in HOST CONTROL register to enable the sensors + cmd[1]=BIT_RUN_ENB; + i2c.write(SLAVE_ADDR,cmd,2); + r2.stop(); + wait_ms(100); + r3.start(); + cmd[0]=MAGRATE; //Output data rate of 100Hz is used for magnetometer + cmd[1]=BIT_MAGODR; + i2c.write(SLAVE_ADDR,cmd,2); + r3.stop(); + wait_ms(100); + r4.start(); + cmd[0]=GYRORATE; //Output data rate of 150Hz is used for gyroscope + cmd[1]=BIT_GYROODR; + i2c.write(SLAVE_ADDR,cmd,2); + r4.stop(); + wait_ms(100); + cmd[0]=ALGO_CTRL; //When 0x00 is written to ALGO CONTROL register we get scaled sensor values + cmd[1]=0x00; + i2c.write(SLAVE_ADDR,cmd,2); + wait_ms(100); + cmd[0]=ENB_EVT; //enabling the error,gyro values and magnetometer values + cmd[1]=BIT_EVT_ENB; + i2c.write(SLAVE_ADDR,cmd,2); + wait_ms(100); + printf("\n \r %d %d %d %d %d",r0.read_us(),r1.read_us(),r2.read_us(),r3.read_us(),r4.read_us()); +} + +float *EXECUTE_PNI() +{ + //printf("\n\r mnm func \n"); + toFlag=1; //toFlag is set to 1 so that it enters while loop + to.attach(&T_OUT,2); //after 2 seconds the while loop gets terminated + while(toFlag) { + cmd[0]=EVT_STATUS; + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(100); + //mnm.printf("\nEvent Status is %x\n",(int)status); + //if the 6th and 4th bit are 1 then it implies that gyro and magnetometer values are ready to take + if(((int)status&40)==40) { + printf("\nin if of mnm\n"); + cmd[0]=GYRO_XOUT_H; //0x22 gyro LSB of x + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,raw_gyro,6); + cmd[0]=MAG_XOUT_H; //LSB of x + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,raw_mag,6); + //mnm.printf("\nGyro Values:\n"); + for(int i=0; i<3; i++) { + //concatenating gyro LSB and MSB to get 16 bit signed data values + bit_data= ((int16_t)raw_gyro[2*i+1]<<8)|(int16_t)raw_gyro[2*i]; + gyro_data[i]=(float)bit_data; + gyro_data[i]=gyro_data[i]/senstivity_gyro; + gyro_data[i]+=gyro_error[i]; + //mnm.printf("%f\t",gyro_data[i]); + } + //mnm.printf("\nMag Values:\n"); + for(int i=0; i<3; i++) { + //concatenating mag LSB and MSB to get 16 bit signed data values + bit_data= ((int16_t)raw_mag[2*i+1]<<8)|(int16_t)raw_mag[2*i]; + mag_data[i]=(float)bit_data; + mag_data[i]=mag_data[i]/senstivity_mag; + mag_data[i]+=mag_error[i]; + //mnm.printf("%f\t",mag_data[i]); + } + for(int i=0; i<3; i++) { + combined_values[i]=gyro_data[i]; + combined_values[i+3]=mag_data[i]; + } + return(combined_values); //returning poiter combined values + } + //checking for the error + + else if (((int)status&2)==2) { + INIT_PNI(); //when there is any error then Again inilization is done to remove error + } + + + } +} \ No newline at end of file
diff -r 000000000000 -r e91ee0e99213 mnm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mnm.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,3 @@ +void INIT_PNI(void); //initialization of registers happens +float *EXECUTE_PNI(); //data is obtained +void T_OUT(); //timeout function to stop infinite loop
diff -r 000000000000 -r e91ee0e99213 pin_config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pin_config.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,101 @@ +// 100 LQFP format pin assignment +#define PIN1 PTE0 +#define PIN2 PTE1 +#define PIN3 PTE2 +#define PIN4 PTE3 +#define PIN5 PTE4 +#define PIN6 PTE5 +#define PIN7 PTE6 +//#define 8 +//#define 9 +//#define 10 +//#define 11 +//#define 12 +//#define 13 +#define PIN14 PTE16 +#define PIN15 PTE17 +#define PIN16 PTE18 +#define PIN17 PTE19 +#define PIN18 PTE20 +#define PIN19 PTE21 +#define PIN20 PTE22 +#define PIN21 PTE23 +//#define 22 +//#define 23 +//#define 24 +//#define 25 +#define PIN26 PTE29 +#define PIN27 PTE30 +#define PIN28 PTE31 +//#define 29 +//#define 30 +#define PIN31 PTE24 +#define PIN32 PTE25 +#define PIN33 PTE26 +#define PIN34 PTA0 +#define PIN35 PTA1 +#define PIN36 PTA2 +#define PIN37 PTA3 +#define PIN38 PTA4 +#define PIN39 PTA5 +#define PIN40 PTA6 +#define PIN41 PTA7 +#define PIN42 PTA12 +#define PIN43 PTA13 +#define PIN44 PTA14 +#define PIN45 PTA15 +#define PIN46 PTA16 +#define PIN47 PTA17 +//#define 48 +//#define 49 +#define PIN50 PTA18 +#define PIN51 PTA19 +#define PIN52 PTA20 +#define PIN53 PTB0 +#define PIN54 PTB1 +#define PIN55 PTB2 +#define PIN56 PTB3 +#define PIN57 PTB7 +#define PIN58 PTB8 +#define PIN59 PTB9 +#define PIN60 PTB10 +#define PIN61 PTB11 +#define PIN62 PTB16 +#define PIN63 PTB17 +#define PIN64 PTB18 +#define PIN65 PTB19 +#define PIN66 PTB20 +#define PIN67 PTB21 +#define PIN68 PTB22 +#define PIN69 PTB23 +#define PIN70 PTC0 +#define PIN71 PTC1 +#define PIN72 PTC2 +#define PIN73 PTC3 +//#define 74 +//#define 75 +#define PIN76 PTC20 +#define PIN77 PTC21 +#define PIN78 PTC22 +#define PIN79 PTC23 +#define PIN80 PTC4 +#define PIN81 PTC5 +#define PIN82 PTC6 +#define PIN83 PTC7 +#define PIN84 PTC8 +#define PIN85 PTC9 +#define PIN86 PTC10 +#define PIN87 PTC11 +#define PIN88 PTC12 +#define PIN89 PTC13 +#define PIN90 PTC16 +#define PIN91 PTC17 +#define PIN92 PTC18 +#define PIN93 PTD0 +#define PIN94 PTD1 +#define PIN95 PTD2 +#define PIN96 PTD3 +#define PIN97 PTD4 +#define PIN98 PTD5 +#define PIN99 PTD6 +#define PIN100 PTD7 \ No newline at end of file
diff -r 000000000000 -r e91ee0e99213 pni.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pni.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,37 @@ +#define SLAVE_ADDR 0x50 +#define SLAVE_ADDR_READ 0x51 +#define SENTRALSTATUS 0x37 +#define RESETREQ 0x9B +#define MAGRATE 0x55 +#define ACCERATE 0x56 +#define GYRORATE 0x57 +#define QRATE_DIV 0x32 +#define ALGO_CTRL 0x54 +#define ENB_EVT 0x33 +#define HOST_CTRL 0x34 +#define EVT_STATUS 0x35 +#define ALGO_STATUS 0x38 +#define GYRO_XOUT_H 0x22 +#define MAG_XOUT_H 0X12 + +//Configaration bits +#define BIT_RESREQ 0x01 +#define BIT_EEP_DET 0x01 +#define BIT_EEP_UPDN 0x02 +#define BIT_EEP_UPERR 0x04 +#define BIT_EEP_IDLE 0x08 +#define BIT_EEP_NODET 0x10 +#define BIT_STBY 0x01 +#define BIT_RAW_ENB 0x02 +#define BIT_HPR_OUT 0x04 +#define BIT_CPU_RES 0x01 +#define BIT_ERR 0x02 +#define BIT_QRES 0x04 +#define BIT_MAG_RES 0x08 +#define BIT_ACC_RES 0x10 +#define BIT_GYRO_RES 0x20 +#define BIT_GYROODR 0x0F +#define BIT_MAGODR 0x64 +#define BIT_RUN_ENB 0x01 +#define BIT_ALGO_RAW 0x02 +#define BIT_EVT_ENB 0X2A \ No newline at end of file
diff -r 000000000000 -r e91ee0e99213 slave.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slave.h Tue Apr 07 16:11:54 2015 +0000 @@ -0,0 +1,12 @@ +#include "mbed.h" +#define WriteGeneral 3 +#define ReadAddressed 1 +#define slave_address 0x20 + + +void FUNC_I2C_WRITE2CDMS(char* ,int); +void FUNC_I2C_IR2CDMS(); +void FUNC_I2C_INT(); +void FUNC_I2C_RESET(); +void FUNC_I2C_TC_EXECUTE (char command) ; +