Rev 1971 | Rev 2017 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1971 | Rev 2015 | ||
---|---|---|---|
1 | #include "invenSense.h" |
1 | #include "invenSense.h" |
2 | #include "timer0.h" |
2 | #include "timer0.h" |
3 | #include "configuration.h" |
3 | #include "configuration.h" |
4 | 4 | ||
5 | #include <avr/io.h> |
5 | #include <avr/io.h> |
6 | 6 | ||
7 | /* |
7 | /* |
8 | * Configuration for my prototype board with InvenSense gyros. |
8 | * Configuration for my prototype board with InvenSense gyros. |
9 | * The FC 1.3 board is installed upside down, therefore Z acc is reversed but not roll. |
9 | * The FC 1.3 board is installed upside down, therefore Z acc is reversed but not roll. |
10 | */ |
10 | */ |
11 | const uint8_t GYRO_REVERSED[3] = { 0, 0, 0 }; |
- | |
12 | const uint8_t ACC_REVERSED[3] = { 0, 0, 1 }; |
- | |
- | 11 | ||
13 | 12 | // The special auto-zero feature of this gyro needs a port. |
|
14 | #define AUTOZERO_PORT PORTD |
13 | #define AUTOZERO_PORT PORTD |
15 | #define AUTOZERO_DDR DDRD |
14 | #define AUTOZERO_DDR DDRD |
16 | #define AUTOZERO_BIT 5 |
15 | #define AUTOZERO_BIT 5 |
17 | 16 | ||
18 | void gyro_calibrate(void) { |
17 | void gyro_calibrate(void) { |
19 | // If port not already set to output and high, do it. |
18 | // If port not already set to output and high, do it. |
20 | if (!(AUTOZERO_DDR & (1 << AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1 |
19 | if (!(AUTOZERO_DDR & (1 << AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1 |
21 | << AUTOZERO_BIT))) { |
20 | << AUTOZERO_BIT))) { |
22 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
21 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
23 | AUTOZERO_DDR |= (1 << AUTOZERO_BIT); |
22 | AUTOZERO_DDR |= (1 << AUTOZERO_BIT); |
24 | delay_ms(100); |
23 | delay_ms(100); |
25 | } |
24 | } |
26 | 25 | ||
27 | // Make a pulse on the auto-zero output line. |
26 | // Make a pulse on the auto-zero output line. |
28 | AUTOZERO_PORT &= ~(1 << AUTOZERO_BIT); |
27 | AUTOZERO_PORT &= ~(1 << AUTOZERO_BIT); |
29 | delay_ms(1); |
28 | delay_ms(1); |
30 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
29 | AUTOZERO_PORT |= (1 << AUTOZERO_BIT); |
31 | // Delay_ms(10); |
30 | // Delay_ms(10); |
32 | delay_ms_with_adc_measurement(100); |
31 | delay_ms_with_adc_measurement(100); |
33 | } |
32 | } |
34 | 33 | ||
35 | void gyro_loadAmplifierOffsets(uint8_t overwriteWithDefaults) { |
34 | void gyro_loadAmplifierOffsets(uint8_t overwriteWithDefaults) { |
36 | // No amplifiers, no DAC. |
35 | // No amplifiers, no DAC. |
37 | } |
36 | } |
38 | 37 | ||
39 | void gyro_setDefaultParameters(void) { |
38 | void gyro_setDefaultParameters(void) { |
40 | staticParams.gyroD = 3; |
39 | staticParams.gyroD = 3; |
41 | staticParams.driftCompDivider = 2; |
40 | staticParams.driftCompDivider = 2; |
42 | staticParams.driftCompLimit = 3; |
41 | staticParams.driftCompLimit = 3; |
43 | staticParams.zerothOrderCorrection = 2; |
42 | staticParams.zerothOrderCorrection = 2; |
44 | } |
43 | } |
45 | 44 |