-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.h
97 lines (70 loc) · 3.33 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef CONFIG_H
#define CONFIG_H
/*
****** PLEASE READ THIS *******
dsPic33 has no EEPROM so we use flash memory to store config data during production
Flash memory can be overwritten 100-1000 times only (estimated) see http://www.microchip.com/forums/m249893.aspx
IMPORTANT: during development config will be ovewritten since it is essentially part of program memory
the solution is to hard-code calibration values in config_default()
Also see:
http://www.microchip.com/forums/tm.aspx?m=532946&high=_write_flash16
*/
//reserve a page of Flash for config storage
//char __attribute__((space(prog),aligned(_FLASH_PAGE*2))) dat[_FLASH_PAGE*3];
//1 flash page = 512 instructions = 1536 bytes (8 rows)
//1 flash row = 64 instructions = 192 bytes
//From libpic30.h:
/* constants for 33F devices */
//#define _FLASH_PAGE 512
//#define _FLASH_ROW 64
#define CONFIG_SIGNATURE 0xAD01
#define CONFIG_VERSION 1
struct {
// !!!!! sizeof(config) should be even (add padding byte if necessary)
// !!!!! sizeof(config) <= _FLASH_ROW * 2 = 64 * 2
unsigned int signature;
unsigned int writeCount; //counts number of config writes, resets to 0 at 0xFFFF
unsigned char accInv[3]; // invert accl input (for example due to physical mounting position)
double accOffs[3]; // accl output at 0g in ADC units
double accSens[3]; // accl input sensitivity in ADC/g
unsigned char gyroInv[3]; // invert gyro input (for example due to physical mounting position)
double gyroOffs[3]; // gyro zero rate output in ADC @ 0 deg/s;
double gyroSens[3]; // gyro input sensitivity ADC/(deg/ms)
} config;
void config_default(){
config.signature = CONFIG_SIGNATURE;
config.writeCount = 0;
//Theoretical values entered in comments, we use actual hard-coded calibrated values for development
//to avoid unnecessary Flash writes
// Settings for Acc_Gyro board http://www.gadgetgangster.com/213 (update based on your sensors)
// Accelerometer offset: 1.65V = 1023 * 1.65/3.3 = 511.5 ADC
// Accelerometer sensisitivity 478 mV/g = 1023 * 0.478 / 3.3 = 148.18 ADC/g
config.accOffs[0] = 511.81;
config.accOffs[1] = 509.10;
config.accOffs[2] = 506.96;
config.accSens[0] = 147.96;
config.accSens[1] = 150.82;
config.accSens[2] = 144.87;
// Gyro X,Y axes (PITCH, ROLL)
// Gyro Zero Level 1.23V @ 0 deg/s = 1023 * 1.23 / 3.3 = 381.3 ADC
// 1 mV / (deg/s) = 1023/3300 ADC / ( (PI/180)rad / 1000ms ) = 17761.69165 ADC /(rad/ms)
// Gyro Sensitivity 2 mV/(deg/s) = 2 * 17761.69165 ADC /(rad/ms) = 35523.3833 ADC /(rad/ms)
//
config.gyroOffs[0] = 383.15;
config.gyroOffs[1] = 385.57;
config.gyroSens[0] = 35523.3833;
config.gyroSens[1] = 35523.3833;
// Settinsg for LISY300AL Single-Axis Gyro http://www.pololu.com/catalog/product/765
// Gyro for Z axis (YAW)
// Gyro Zero Level 1.65V @ 0 deg/s = 1023 * 1.65/3.3 = 511.5 ADC
// Gyro Sensitivity 3.3 mV/(deg/s) = 3.3* 17761.69165 ADC /(rad/ms) = 58613.58245 ADC /(rad/ms)
config.gyroOffs[2] = 516.38;
config.gyroSens[2] = 58613.58245;
config.accInv[0] = 0;
config.accInv[1] = 0;
config.accInv[2] = 0;
config.gyroInv[0] = 1;
config.gyroInv[1] = 0;
config.gyroInv[2] = 0;
}
#endif