i2c working with old hk

Dependencies:   mbed-rtos mbed

Fork of BAE_vr2_1_1 by green rosh

Committer:
sakthipriya
Date:
Wed Dec 17 06:06:59 2014 +0000
Revision:
14:ef6be8ac6569
Parent:
13:1b37d98840d3
i2c working with old hk

Who changed what in which revision?

UserRevisionLine numberNew contents of line
greenroshks 0:8b0d43fe6c05 1 #include "HK.h"
greenroshks 0:8b0d43fe6c05 2
sakthipriya 14:ef6be8ac6569 3 DigitalOut SelectLine3 (D4); // MSB of Select Lines
sakthipriya 14:ef6be8ac6569 4 DigitalOut SelectLine2 (D3);
sakthipriya 14:ef6be8ac6569 5 DigitalOut SelectLine1 (D2);
sakthipriya 14:ef6be8ac6569 6 DigitalOut SelectLine0 (D1); // LSB of Select Lines
greenroshks 0:8b0d43fe6c05 7
sakthipriya 14:ef6be8ac6569 8 AnalogIn CurrentInput(A1); // Input from Current Multiplexer
sakthipriya 14:ef6be8ac6569 9 AnalogIn VoltageInput(A2); // Input from Voltage Multiplexer
sakthipriya 14:ef6be8ac6569 10 AnalogIn TemperatureInput(A3); // input from Temperature Multiplexer
greenroshks 13:1b37d98840d3 11
sakthipriya 14:ef6be8ac6569 12 SensorData Sensor;
sakthipriya 14:ef6be8ac6569 13 int quantiz(float start,float step,float x)
greenroshks 0:8b0d43fe6c05 14 {
greenroshks 0:8b0d43fe6c05 15 int y=(x-start)/step;
greenroshks 0:8b0d43fe6c05 16 if(y<=0)y=0;
greenroshks 0:8b0d43fe6c05 17 if(y>=15)y=15;
greenroshks 0:8b0d43fe6c05 18 return y;
greenroshks 0:8b0d43fe6c05 19 }
sakthipriya 14:ef6be8ac6569 20 ShortBeacy Shortbeacon;
sakthipriya 14:ef6be8ac6569 21 void init_beacon(ShortBeacy x){
sakthipriya 14:ef6be8ac6569 22 ;
greenroshks 13:1b37d98840d3 23 }
sakthipriya 14:ef6be8ac6569 24
greenroshks 13:1b37d98840d3 25
sakthipriya 14:ef6be8ac6569 26 void FUNC_HK_MAIN()
greenroshks 13:1b37d98840d3 27 {
sakthipriya 14:ef6be8ac6569 28 printf("\nEntered function HK MAIN\n");
greenroshks 13:1b37d98840d3 29
sakthipriya 14:ef6be8ac6569 30 Shortbeacon.Voltage[0]=1;
sakthipriya 14:ef6be8ac6569 31 Shortbeacon.AngularSpeed[0]=2;
sakthipriya 14:ef6be8ac6569 32 Shortbeacon.AngularSpeed[1]=3;
sakthipriya 14:ef6be8ac6569 33 Shortbeacon.SubsystemStatus[0]=145;
sakthipriya 14:ef6be8ac6569 34 Shortbeacon.Temp[0]=1;
sakthipriya 14:ef6be8ac6569 35 Shortbeacon.Temp[1]=2;
sakthipriya 14:ef6be8ac6569 36 Shortbeacon.Temp[2]=3;
sakthipriya 14:ef6be8ac6569 37 Shortbeacon.ErrorFlag[0]=3;
greenroshks 0:8b0d43fe6c05 38
greenroshks 0:8b0d43fe6c05 39 int LoopIterator;
sakthipriya 14:ef6be8ac6569 40
sakthipriya 14:ef6be8ac6569 41 SelectLine0=0;
sakthipriya 14:ef6be8ac6569 42 SelectLine1=0;
sakthipriya 14:ef6be8ac6569 43 SelectLine2=0;
sakthipriya 14:ef6be8ac6569 44 SelectLine3=0;
greenroshks 0:8b0d43fe6c05 45
sakthipriya 14:ef6be8ac6569 46 for(LoopIterator=0; LoopIterator<16; LoopIterator++) {
sakthipriya 14:ef6be8ac6569 47
sakthipriya 14:ef6be8ac6569 48 if(LoopIterator%2==0) {
sakthipriya 14:ef6be8ac6569 49 Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
sakthipriya 14:ef6be8ac6569 50 Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
sakthipriya 14:ef6be8ac6569 51 Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
sakthipriya 14:ef6be8ac6569 52 } else {
sakthipriya 14:ef6be8ac6569 53 Sensor.Current[(LoopIterator-1)/2]=(Sensor.Current[(LoopIterator-1)/2]<<4)+quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
sakthipriya 14:ef6be8ac6569 54 Sensor.Voltage[(LoopIterator-1)/2]=(Sensor.Voltage[(LoopIterator-1)/2]<<4)+quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
sakthipriya 14:ef6be8ac6569 55 Sensor.Temperature[(LoopIterator-1)/2]=(Sensor.Temperature[(LoopIterator-1)/2]<<4)+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
greenroshks 13:1b37d98840d3 56 }
sakthipriya 14:ef6be8ac6569 57 // The following lines are used to iterate the select lines from 0 to 15
sakthipriya 14:ef6be8ac6569 58 SelectLine0=!(SelectLine0);
greenroshks 0:8b0d43fe6c05 59
sakthipriya 14:ef6be8ac6569 60 if(LoopIterator%2==1)
sakthipriya 14:ef6be8ac6569 61 SelectLine1=!(SelectLine1);
greenroshks 13:1b37d98840d3 62
sakthipriya 14:ef6be8ac6569 63 if(LoopIterator%4==3)
sakthipriya 14:ef6be8ac6569 64 SelectLine2=!(SelectLine2);
sakthipriya 14:ef6be8ac6569 65
sakthipriya 14:ef6be8ac6569 66 if(LoopIterator%8==7)
sakthipriya 14:ef6be8ac6569 67 SelectLine3=!(SelectLine3);
greenroshks 0:8b0d43fe6c05 68
greenroshks 0:8b0d43fe6c05 69 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed.
greenroshks 0:8b0d43fe6c05 70
sakthipriya 14:ef6be8ac6569 71 }
sakthipriya 14:ef6be8ac6569 72
sakthipriya 14:ef6be8ac6569 73 printf("\nVoltage is %u\n",Shortbeacon.Voltage[0]);
sakthipriya 14:ef6be8ac6569 74 printf("\nCurrent is %u\n",Shortbeacon.Temp[0]);
sakthipriya 14:ef6be8ac6569 75
greenroshks 13:1b37d98840d3 76
greenroshks 13:1b37d98840d3 77
sakthipriya 14:ef6be8ac6569 78 printf("\nExited function HK MAIN\n");
greenroshks 13:1b37d98840d3 79 }