Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of workinQM_5thJan_azad by
Diff: ACS.cpp
- Revision:
- 17:fc782f7548c6
- Parent:
- 16:f9e484dc505e
- Child:
- 18:3662058a7c10
diff -r f9e484dc505e -r fc782f7548c6 ACS.cpp --- a/ACS.cpp Thu May 12 10:56:44 2016 +0000 +++ b/ACS.cpp Fri May 13 11:56:49 2016 +0000 @@ -372,26 +372,65 @@ } pc_acs.printf("\n\n\rwait is 1 \n\r"); pc_acs.printf("Sentral Status is %x\n \r",(int)store); + + /*ways to make the sensors work even if one sensor cups first making data rate 0x00 + 1>make data rate 0x00 change the enable events register value to 0x0A or 0x22 as suitable + 2>change the condition for getting the values from the sensors i.e in data_acq function + 3>check the other register values + + other method is pass through working in how it works / decoding SENtral algorithms + */ + 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); - wait_ms(10); + wait_ms(100); cmd[0]=MAGRATE; //Output data rate of 100Hz is used for magnetometer cmd[1]=BIT_MAGODR; i2c.write(SLAVE_ADDR,cmd,2); - wait_ms(1); + wait_ms(100); + //___________________________________________________________________________________________________ + + /*just leave it then see what happens?? the gyro data without inputing anything*/ + + //___________________________________________________________________________________________________ cmd[0]=GYRORATE; //Output data rate of 150Hz is used for gyroscope cmd[1]=BIT_GYROODR; i2c.write(SLAVE_ADDR,cmd,2); wait_ms(1); cmd[0]=ALGO_CTRL; //When 0x00 is written to ALGO CONTROL register we get scaled sensor values - cmd[1]=0x00; + cmd[1]=0x00;//actually 0x00 i2c.write(SLAVE_ADDR,cmd,2); wait_ms(1); cmd[0]=ENB_EVT; //enabling the error,gyro values and magnetometer values - cmd[1]=BIT_EVT_ENB; + cmd[1]=BIT_EVT_ENB;//__________________________________________________________________________________ + i2c.write(SLAVE_ADDR,cmd,2); + wait_ms(1); + //_______________________________________________________________________________// + +/*stop as of now this approach i.e pass through state*/ +/* + cmd[0]=ALGO_CTRL; //When 0x00 is written to ALGO CONTROL register we get scaled sensor values + cmd[1]=0x01;//Places sentral in standby state i2c.write(SLAVE_ADDR,cmd,2); wait_ms(1); + + + cmd[0]=0xA0; //Pass through control register + cmd[1]=0x01;//places SENtral in pass through state + i2c.write(SLAVE_ADDR,cmd,2); + wait_ms(1); + + + cmd[0]=0x9E;//Pass through status reg + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&store,1); + wait_ms(1); + printf("\n\r the value of the pass through status register is = %x",(int)store); + +*/ + //_______________________________________________________________________________// + ACS_INIT_STATUS = 'c'; //set ACS_INIT_STATUS flag } @@ -411,10 +450,17 @@ wait_ms(100); pc_acs.printf("Event Status is %x\n \r",(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) { - cmd[0]=GYRO_XOUT_H; //0x22 gyro LSB of x - i2c.write(SLAVE_ADDR,cmd,1); + if(((int)status&40)==40){ //when both work +/// if((int)status==8){ //for just mag +/// if((int)status == 36){ //for just gyro as status 24(in binary) = 36 in decimal + + /*don't ask for info if the gyro cupped as interrupt makes it go haywire that is enables the pins for gyro*/ + cmd[0]=GYRO_XOUT_H; //0x22 gyro LSB of x + i2c.write(SLAVE_ADDR,cmd,1); i2c.read(SLAVE_ADDR_READ,raw_gyro,6); +printf("\n\n\n\r here reached"); +/*editing the data*/ + cmd[0]=MAG_XOUT_H; //LSB of x i2c.write(SLAVE_ADDR,cmd,1); i2c.read(SLAVE_ADDR_READ,raw_mag,6); @@ -427,6 +473,53 @@ gyro_data[i]+=gyro_error[i]; // pc_acs.printf("%f\t",gyro_data[i]); } + +/*read the status values to determine the actual condition/registers values for the gyro/mag off case */ +//starts here + + cmd[0]=0x35;//event status + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(1); + pc_acs.printf("\n\rEvent Status at the end is %x\n \r",(int)status); + + + cmd[0]=0x33;//enable events + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(1); + pc_acs.printf("\n\rEnable events is %x\n \r",(int)status); + + + cmd[0]=0x57;//gyro rate + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(1); + pc_acs.printf("\n\rgyro rate is %x\n \r",(int)status); + + + cmd[0]=0x55;//mag rate 0x00 indicate value lost + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(1); + pc_acs.printf("\n\rmag rate is %x\n \r",(int)status); + + + cmd[0]=0x36;//sensorstatus + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(1); + pc_acs.printf("\n\rsensor Status is %x\n \r",(int)status); + + + cmd[0]=0x50;//error register + i2c.write(SLAVE_ADDR,cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(1); + pc_acs.printf("\n\rerror register value is %x\n \r",(int)status); + +//end here + // pc_acs.printf("\nMag Values:\n"); for(int i=0; i<3; i++) { //concatenating mag LSB and MSB to get 16 bit signed data values