integrated code with threads to be removed

Dependencies:   mbed-rtos mbed

Fork of BAE_vr3honeycomb1 by sakthi priya amirtharaj

Files at this revision

API Documentation at this revision

Comitter:
greenroshks
Date:
Fri Dec 26 06:12:09 2014 +0000
Parent:
1:deb3c0fafa3a
Child:
3:89a09736acd3
Commit message:
integrated code with threas 2 b removed

Changed in this revision

ACS.cpp Show annotated file Show diff for this revision Revisions of this file
HK.cpp Show annotated file Show diff for this revision Revisions of this file
fault.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ACS.cpp	Sat Dec 20 05:56:04 2014 +0000
+++ b/ACS.cpp	Fri Dec 26 06:12:09 2014 +0000
@@ -6,13 +6,13 @@
                         //PWM output comes from pins p6
 Serial pc1(USBTX, USBRX);
 SPI spi_acs (PIN16, PIN17, PIN15); // mosi, miso, sclk  PTE18,19,17
-DigitalOut SSN_MAG (PIN61); // ssn for magnetometer PTB11
-DigitalIn 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(A3);        //Functions used to generate PWM signal 
-PwmOut PWM2(A4); 
-PwmOut PWM3(A5);                   //PWM output comes from pins p6
+DigitalOut SSN_MAG (PTC16); // ssn for magnetometer PTB11
+DigitalInOut DRDY (PTE3); // drdy for magnetometer PTA17
+DigitalOut ssn_gyr (PTE2);         //Slave Select pin of gyroscope  PTB16
+InterruptIn dr(PTC6);       //Interrupt pin for gyro PTC5
+PwmOut PWM1(D2);        //Functions used to generate PWM signal 
+PwmOut PWM2(D3); 
+PwmOut PWM3(D4);                   //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;
@@ -31,6 +31,7 @@
      float timep = 0.02 ;  
      float Mx=M[0];            //Time period is set to 0.02s  
                              //Moment in x, y, z directions
+     
       
      
         ix = Mx * 0.3 ;      //Moment and Current always have the linear relationship
@@ -63,7 +64,7 @@
          }
          else if(ix==0)
          {
-             DCx = 0;
+             DCx = 50;
             PWM1.period(timep);
             PWM1 = DCx/100 ;            
          }
@@ -71,6 +72,8 @@
          {
             // printf("!!!!!!!!!!Error!!!!!!!!!");
          } 
+         
+    printf("\n moment :%f\n",DCx);
     float DCy = 0;         //Duty cycle of Moment in x, y, z directions
      float iy = 0;          //Current sent in x, y, z TR's
        
@@ -174,7 +177,11 @@
 
 void FUNC_ACS_MAG_INIT()
  {
-   
+  //DRDY.output();
+  DRDY = 0;
+  int a ;
+  a=DRDY;
+  printf("\n DRDY is %d\n",a);
   SSN_MAG=1;                                    //pin is disabled
   spi_acs.format(8,0);                         //   8bits,Mode 0
   spi_acs.frequency(100000);                   //clock frequency
@@ -198,7 +205,12 @@
 
 float* FUNC_ACS_MAG_EXEC()
 {
-   printf("\nEntered magnetometer function\n");
+   //printf("\nEntered magnetometer function\n");
+   //DRDY.output();
+   DRDY.write(0);
+   int a;
+   a = DRDY;
+   printf("\n DRDY is %d\n",a);
    SSN_MAG=0;                                //enabling slave to measure the values
    wait_ms(10);
    spi_acs.write(0x82);                     //initiates measurement
@@ -209,7 +221,7 @@
 
    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*/
@@ -217,6 +229,7 @@
     wait_ms(5);
     if(DRDY==1)
     {
+        printf("\nwth\n");
         SSN_MAG=0;
         spi_acs.write(0xc9);                  //command  byte for retrieving data
  
@@ -247,7 +260,8 @@
 
         }
         SSN_MAG=1;
-        
+        /* for test only to removed */
+        Bnewvalue[0]=Bnewvalue[1]=Bnewvalue[2]=100;
         return Bnewvalue;          //return here? doubt..
         break;
     }
@@ -431,7 +445,7 @@
 {
     uint8_t response;               
     ssn_gyr=1;                  //Deselecting the chip 
-    spi_acs.format(8,3);                // Spi format is 8 bits, and clock mode 3 
+    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);          
--- a/HK.cpp	Sat Dec 20 05:56:04 2014 +0000
+++ b/HK.cpp	Fri Dec 26 06:12:09 2014 +0000
@@ -4,9 +4,9 @@
  
 //GPIO pins used=> D2-D12, A0-A1
 
-DigitalOut SelectLinesA[]={PIN96,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
+DigitalOut SelectLinesA[]={PIN43,PIN44,PIN45,PIN46};//to mux1=>voltage mux , PTA 13-16 , CHNGE TO PIN43 LATER
+DigitalOut SelectLinesB[]={PTD3,PTC4,PTC8,PIN59};//to mux2=>current mux(differential mux) , PTB 3,7,8,9
+DigitalOut SelectLinesC[]={PIN64,PIN65,PIN66,PTC9};//to mux3=>temp mux   PTB 18-21
 
 //--------------------------------------------MSB is SelectLines[0],LSB is SelectLines[3]-------------------------------- 
 
@@ -130,11 +130,15 @@
 
     for(LoopIterator=0; LoopIterator<5; LoopIterator++) 
 {       
+        
         //following lines 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
-        //PanelTemperature will be updated depending on voltage_thermistor value later in the lines to follow
+        if (LoopIterator==0)
+        {
+            printf(" Temp =%f",-90.7*3.3*TemperatureInput.read()+190.1543);
+        }
         
         if(LoopIterator%2==0)
      {                
--- a/fault.h	Sat Dec 20 05:56:04 2014 +0000
+++ b/fault.h	Fri Dec 26 06:12:09 2014 +0000
@@ -6,7 +6,7 @@
 #define FAULT2 PIN40      //  3V3APGOOD 
 #define FAULT3 PIN39      //  3V3BPGOOD                         
 #define FAULT4  PIN41     //  3V3CPGOOD      
-#define FAULT5  PIN79      //  3V3AOCBAR 
+#define FAULT5  PTC23      //  3V3AOCBAR                //changed here
 #define FAULT6  PIN80      //  3V3COC  
 #define FAULT7  PIN38      //  SW8FAULT   /// to pin 97 later 
 #define FAULT8  PIN83      //  SW6FAULT   
--- a/main.cpp	Sat Dec 20 05:56:04 2014 +0000
+++ b/main.cpp	Fri Dec 26 06:12:09 2014 +0000
@@ -9,6 +9,7 @@
 
 Serial pc(USBTX, USBRX);
 
+//extern DigitalOut DRDY;
 InterruptIn interrupt(D9);
 InterruptIn master_reset(D8);
 
@@ -68,7 +69,7 @@
     while(1)
     {
         Thread::signal_wait(0x2);
-        SensorQuantised.power_mode='0';
+        SensorQuantised.power_mode='3';
         printf("\nTHIS IS HK    %f\n",t1.read());
         t.start();
         FUNC_HK_FAULTS();
@@ -100,7 +101,7 @@
         t.start();
         mag_field= FUNC_ACS_MAG_EXEC();                              //actual execution
         omega = FUNC_ACS_EXEC_GYR();
-        
+        printf("\n gyr 1 value %f",omega[0]);
         
         
         if(acs_pflag == 1)
@@ -381,7 +382,7 @@
 uint16_t schedcount=1;
 void T_SC(void const *args)
 {
-    
+    //DRDY=0;
     printf("The value of i in scheduler is %d\n",schedcount);
     if(schedcount == 65532)                         //to reset the counter
     {
@@ -415,7 +416,7 @@
 int main()
 {
     t1.start();
-    
+    //DRDY=0;
      FUNC_ACS_MAG_INIT();
      FUNC_ACS_INIT_GYR();
 
@@ -461,6 +462,7 @@
     {   
         //Thread::wait(10000);
          //ir2master(); 
+         //DRDY = 0;
          Thread::wait(5000);
     }