Subversion Repositories FlightCtrl

Rev

Rev 2025 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1910 - 1
#include "timer0.h"
2
#include "configuration.h"
3
 
4
#include <avr/io.h>
5
 
6
/*
7
 * Configuration for my prototype board with InvenSense gyros.
8
 * The FC 1.3 board is installed upside down, therefore Z acc is reversed but not roll.
9
 */
10
 
2099 - 11
// The special auto-zero feature of this gyro needs a port.
1910 - 12
#define AUTOZERO_PORT PORTD
13
#define AUTOZERO_DDR DDRD
14
#define AUTOZERO_BIT 5
15
 
16
void gyro_calibrate(void) {
17
        // If port not already set to output and high, do it.
2099 - 18
        if (!(AUTOZERO_DDR & (1 << AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1 << AUTOZERO_BIT))) {
1910 - 19
                AUTOZERO_PORT |= (1 << AUTOZERO_BIT);
20
                AUTOZERO_DDR |= (1 << AUTOZERO_BIT);
21
                delay_ms(100);
22
        }
23
 
24
        // Make a pulse on the auto-zero output line.
25
        AUTOZERO_PORT &= ~(1 << AUTOZERO_BIT);
26
        delay_ms(1);
27
        AUTOZERO_PORT |= (1 << AUTOZERO_BIT);
28
        // Delay_ms(10);
2099 - 29
        delay_ms_with_adc_measurement(100, 0);
1910 - 30
}
31
 
2099 - 32
void gyro_init(void) {
33
        gyro_calibrate();
1910 - 34
}
2099 - 35
 
36
void gyro_setDefaultParameters(void) {
37
  IMUConfig.driftCompDivider = 2;
38
  IMUConfig.driftCompLimit = 5;
39
  IMUConfig.zerothOrderCorrection = 1;
40
  IMUConfig.imuReversedFlags = IMU_REVERSE_ACC_Z;
41
}