Subversion Repositories libIgnTiming

Rev

Rev 4 | Rev 6 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
Line 5... Line 5...
5
namespace
5
namespace
6
{
6
{
7
 
7
 
8
    unsigned constexpr INTERP_SCALE = 256;
8
    unsigned constexpr INTERP_SCALE = 256;
9
 
9
 
10
    unsigned constexpr MAX_TIMING_POINTS = 8;
10
    unsigned constexpr MAX_TIMING_POINTS = 10;
11
    unsigned constexpr MAX_VACUUM_POINTS = 8;
11
    unsigned constexpr MAX_VACUUM_POINTS = 10;
12
    int constexpr TimingScale = TIMING_SCALE;
12
    int constexpr TimingScale = TIMING_SCALE;
-
 
13
    int16_t constexpr NO_DATA = -1;
13
 
14
 
-
 
15
    static int8_t const timingAdjust __attribute((section(".nvram"))) = 0; // in TIMING_SCALE
14
    int16_t rpmMap[MAX_TIMING_POINTS] = {400, 750, 1000, 1500, 2500, 3500, 4500, 6000};
16
    int16_t const rpmMap[MAX_TIMING_POINTS] __attribute__((section(".nvram"))) = {400, 750, 1000, 1500, 2500, 3500, 4500, 6000, NO_DATA, NO_DATA};
15
    int16_t vacuumMap[MAX_VACUUM_POINTS] = {0, 166, 225, 300, 700, (int16_t)-1,(int16_t) -1, (int16_t)-1};
17
    int16_t const vacuumMap[MAX_VACUUM_POINTS] __attribute__((section(".nvram"))) = {0, 166, 225, 300, 700, NO_DATA, NO_DATA, NO_DATA, NO_DATA, NO_DATA};
16
    uint8_t mapping[MAX_VACUUM_POINTS][MAX_TIMING_POINTS] = {
18
    uint8_t const mapping[MAX_VACUUM_POINTS][MAX_TIMING_POINTS] __attribute__((section(".nvram"))) = {
17
        /* Table in degrees. */
19
        /* Table in degrees. */
18
        /* row for 0mb = centrifugal only */
20
        /* row for 0mb = centrifugal only */
19
        {12, 7, 7, 19, 25, 29, 29, 22},
21
        {12, 7, 7, 19, 25, 29, 29, 22, 22, 22},
20
        /* row for 166 mB*/
22
        /* row for 166 mB*/
21
        {12, 7, 7, 21, 27, 31, 31, 24},
23
        {12, 7, 7, 21, 27, 31, 31, 24, 24, 22},
22
        /*   row for 225 mB */
24
        /*   row for 225 mB */
23
        {12, 7, 7, 25, 31, 35, 35, 28},
25
        {12, 7, 7, 25, 31, 35, 35, 28, 24, 22},
24
        /* row for 300 mB*/
26
        /* row for 300 mB*/
25
        {12, 7, 7, 29, 35, 39, 39, 33},
27
        {12, 7, 7, 29, 35, 39, 39, 33, 28, 22},
26
        /* row for 700 mB*/
28
        /* row for 700 mB*/
27
        {12, 7, 7, 29, 35, 39, 39, 33},
29
        {12, 7, 7, 29, 35, 39, 39, 33, 28, 22},
28
        /* unused */
30
        /* unused */
29
        {0, 0, 0, 0, 0, 0, 0, 0},
31
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
30
        /* unused */
32
        /* unused */
31
        {0, 0, 0, 0, 0, 0, 0, 0},
33
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
32
        /* unused */
34
        /* unused */
33
        {0, 0, 0, 0, 0, 0, 0, 0}};
35
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
34
 
-
 
-
 
36
        /* unused */
-
 
37
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
35
 
38
        /* unused */
-
 
39
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
36
};
40
    };
37
 
41
 
-
 
42
}
38
/// @brief Lookup a point using linear interpolation
43
/// @brief Lookup a point using linear interpolation
39
/// @param point value to lookup
44
/// @param point value to lookup
40
/// @param curve data point list
45
/// @param curve data point list
41
/// @param size number of data points in list
46
/// @param size number of data points in list
42
/// @param [out] frac fraction of distance between points
47
/// @param [out] frac fraction of distance between points
Line 105... Line 110...
105
 
110
 
106
        int bottom_advance;
111
        int bottom_advance;
107
        // if no fractional part, then the top and bottom advance point is the same
112
        // if no fractional part, then the top and bottom advance point is the same
108
        if (vacuum_frac == 0)
113
        if (vacuum_frac == 0)
109
        {
114
        {
110
            angle = top_advance * TimingScale / INTERP_SCALE ;
115
            angle = top_advance * TimingScale / INTERP_SCALE;
111
        }
116
        }
112
        else
117
        else
113
        {
118
        {
114
            bottom_advance = mapping[vacuum_index + 1][rpm_index] * (INTERP_SCALE - rpm_frac) + mapping[vacuum_index + 1][rpm_index + 1] * rpm_frac;
119
            bottom_advance = mapping[vacuum_index + 1][rpm_index] * (INTERP_SCALE - rpm_frac) + mapping[vacuum_index + 1][rpm_index + 1] * rpm_frac;
115
            /* interpolate down Y axis this time */
120
            /* interpolate down Y axis this time */
116
            int advance = top_advance * (INTERP_SCALE - vacuum_frac) + bottom_advance * vacuum_frac;
121
            int advance = top_advance * (INTERP_SCALE - vacuum_frac) + bottom_advance * vacuum_frac;
117
            /* point is scaled by two multiplications */
122
            /* point is scaled by two multiplications */
118
            angle = advance * TimingScale / (INTERP_SCALE * INTERP_SCALE);
123
            angle = advance * TimingScale / (INTERP_SCALE * INTERP_SCALE);
119
        }
124
        }
120
 
125
 
121
        assert((angle >= TimingScale * 7) && (angle < TimingScale * 50 ));
126
        assert((angle >= TimingScale * 7) && (angle < TimingScale * 50));
122
        return angle;
127
        return angle + timingAdjust;
123
    }
128
    }
124
}
129
}
125
 
-