Subversion Repositories FlightCtrl

Rev

Rev 726 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 726 Rev 727
Line 117... Line 117...
117
void MM3_Update() // called every 102.4 ms by timer 0 ISR
117
void MM3_Update() // called every 102.4 ms by timer 0 ISR
118
{
118
{
119
        switch (MM3.STATE)
119
        switch (MM3.STATE)
120
        {
120
        {
121
        case MM3_STATE_RESET:
121
        case MM3_STATE_RESET:
-
 
122
                PORTC &= ~(1<<PORTC4); // select slave
122
                PORTC |= (1<<PORTC5);   // PC5 to High, MM3 Reset
123
                PORTC |= (1<<PORTC5);   // PC5 to High, MM3 Reset
123
                MM3.STATE = MM3_STATE_START_TRANSFER;
124
                MM3.STATE = MM3_STATE_START_TRANSFER;
124
                return;
125
                return;
Line 125... Line 126...
125
 
126
 
Line 191... Line 192...
191
                        default:
192
                        default:
192
                                MM3.AXIS = MM3_X_AXIS;
193
                                MM3.AXIS = MM3_X_AXIS;
193
                                break;
194
                                break;
194
                        }
195
                        }
195
                }
196
                }
-
 
197
                PORTC |= (1<<PORTC4); // deselect slave
196
                MM3.STATE = MM3_STATE_RESET;
198
                MM3.STATE = MM3_STATE_RESET;
197
        }
199
        }
198
}
200
}
Line 323... Line 325...
323
        Hy_corr /= 8192;
325
        Hy_corr /= 8192;
Line 324... Line 326...
324
 
326
 
325
        // calculate Heading
327
        // calculate Heading
Line 326... Line 328...
326
        heading = c_atan2(Hy_corr, Hx_corr);
328
        heading = c_atan2(Hy_corr, Hx_corr);
-
 
329
 
327
 
330
    // atan returns angular range from -180 deg to 180 deg in counter clockwise notation
328
        // transform range from +-180° to 0°- 359°
331
    // but the compass course is defined in a range from 0 deg to 360 deg clockwise notation.
Line 329... Line 332...
329
        heading += 360;
332
        if (heading < 0) heading = -heading;
330
        heading %= 360;
333
        else heading = 360 - heading;