Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
1612 dongfang 1
#include "timer0.h"
2
#include "configuration.h"
3
 
4
#include <avr/io.h>
5
 
1646 - 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
 
2015 - 11
// The special auto-zero feature of this gyro needs a port.
1612 dongfang 12
#define AUTOZERO_PORT PORTD
13
#define AUTOZERO_DDR DDRD
14
#define AUTOZERO_BIT 5
15
 
1887 - 16
void gyro_calibrate(void) {
1821 - 17
        // If port not already set to output and high, do it.
2017 - 18
        if (!(AUTOZERO_DDR & (1 << AUTOZERO_BIT)) || !(AUTOZERO_PORT & (1 << AUTOZERO_BIT))) {
1821 - 19
                AUTOZERO_PORT |= (1 << AUTOZERO_BIT);
20
                AUTOZERO_DDR |= (1 << AUTOZERO_BIT);
1887 - 21
                delay_ms(100);
1821 - 22
        }
23
 
24
        // Make a pulse on the auto-zero output line.
25
        AUTOZERO_PORT &= ~(1 << AUTOZERO_BIT);
1887 - 26
        delay_ms(1);
1821 - 27
        AUTOZERO_PORT |= (1 << AUTOZERO_BIT);
28
        // Delay_ms(10);
2017 - 29
        delay_ms_with_adc_measurement(100, 0);
1612 dongfang 30
}
31
 
2112 - 32
void gyro_init(void) {
2018 - 33
        gyro_calibrate();
1971 - 34
}
35
 
36
void gyro_setDefaultParameters(void) {
1960 - 37
  staticParams.gyroD = 3;
2092 - 38
  IMUConfig.driftCompDivider = 2;
39
  IMUConfig.driftCompLimit = 5;
40
  IMUConfig.zerothOrderCorrection = 1;
41
  IMUConfig.imuReversedFlags = IMU_REVERSE_ACC_Z;
1612 dongfang 42
}