Rev 1221 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1221 | Rev 1222 | ||
---|---|---|---|
Line 133... | Line 133... | ||
133 | 133 | ||
134 | 134 | ||
135 | void SearchDacGyroOffset(void) |
135 | void SearchDacGyroOffset(void) |
- | 136 | { |
|
Line 136... | Line 137... | ||
136 | { |
137 | uint8_t i, ready = 0; |
- | 138 | uint16_t timeout ; |
|
- | 139 | ||
137 | uint8_t i, ready = 0; |
140 | GyroDefectNick = 0; GyroDefectRoll = 0; GyroDefectYaw = 0; |
138 | 141 | ||
139 | GyroDefectNick = 0; GyroDefectRoll = 0; GyroDefectYaw = 0; |
142 | timeout = SetDelay(2000); |
140 | if(BoardRelease == 13) // the auto offset calibration is available only at board release 1.3 |
143 | if(BoardRelease == 13) // the auto offset calibration is available only at board release 1.3 |
141 | { |
144 | { |
142 | for(i = 140; i != 0; i--) |
145 | for(i = 140; i != 0; i--) |
143 | { |
146 | { |
144 | if(ready == 3 && i > 10) i = 9; |
147 | if(ready == 3 && i > 10) i = 9; |
145 | ready = 0; |
148 | ready = 0; |
146 | if(AdValueGyroNick < 1020) DacOffsetGyroNick--; else if(AdValueGyroNick > 1030) DacOffsetGyroNick++; else ready++; |
- | |
147 | if(AdValueGyroRoll < 1020) DacOffsetGyroRoll--; else if(AdValueGyroRoll > 1030) DacOffsetGyroRoll++; else ready++; |
149 | if(AdValueGyroNick < 1020) DacOffsetGyroNick--; else if(AdValueGyroNick > 1030) DacOffsetGyroNick++; else ready++; |
148 | if(AdValueGyroYaw < 1020) DacOffsetGyroYaw-- ; else if(AdValueGyroYaw > 1030) DacOffsetGyroYaw++ ; else ready++; |
150 | if(AdValueGyroRoll < 1020) DacOffsetGyroRoll--; else if(AdValueGyroRoll > 1030) DacOffsetGyroRoll++; else ready++; |
149 | twi_state = TWI_STATE_GYRO_OFFSET_TX; // set twi_state in TWI ISR to start of Gyro Offset |
151 | if(AdValueGyroYaw < 1020) DacOffsetGyroYaw-- ; else if(AdValueGyroYaw > 1030) DacOffsetGyroYaw++ ; else ready++; |
150 | I2C_Start(); // initiate data transmission |
152 | I2C_Start(TWI_STATE_GYRO_OFFSET_TX); // initiate data transmission |
- | 153 | if(DacOffsetGyroNick < 10) { GyroDefectNick = 1; DacOffsetGyroNick = 10;}; if(DacOffsetGyroNick > 245) { GyroDefectNick = 1; DacOffsetGyroNick = 245;}; |
|
- | 154 | if(DacOffsetGyroRoll < 10) { GyroDefectRoll = 1; DacOffsetGyroRoll = 10;}; if(DacOffsetGyroRoll > 245) { GyroDefectRoll = 1; DacOffsetGyroRoll = 245;}; |
|
- | 155 | if(DacOffsetGyroYaw < 10) { GyroDefectYaw = 1; DacOffsetGyroYaw = 10;}; if(DacOffsetGyroYaw > 245) { GyroDefectYaw = 1; DacOffsetGyroYaw = 245;}; |
|
- | 156 | while(twi_state) |
|
- | 157 | { |
|
- | 158 | if(CheckDelay(timeout)) |
|
- | 159 | { |
|
151 | if(DacOffsetGyroNick < 10) { GyroDefectNick = 1; DacOffsetGyroNick = 10;}; if(DacOffsetGyroNick > 245) { GyroDefectNick = 1; DacOffsetGyroNick = 245;}; |
160 | printf("\r\n DAC or I2C Error1 check I2C, 3Vref, DAC, and BL-Ctrl"); |
152 | if(DacOffsetGyroRoll < 10) { GyroDefectRoll = 1; DacOffsetGyroRoll = 10;}; if(DacOffsetGyroRoll > 245) { GyroDefectRoll = 1; DacOffsetGyroRoll = 245;}; |
161 | break; |
153 | if(DacOffsetGyroYaw < 10) { GyroDefectYaw = 1; DacOffsetGyroYaw = 10;}; if(DacOffsetGyroYaw > 245) { GyroDefectYaw = 1; DacOffsetGyroYaw = 245;}; |
162 | } |
154 | while(twi_state); // wait for end of data transmission |
163 | } // wait for end of data transmission |
155 | average_pressure = 0; |
164 | average_pressure = 0; |
156 | ADC_Enable(); |
165 | ADC_Enable(); |