2Chx3dof Magnetrometer supported M-Series Random Sequence Generator Servo Control
Sampling Frequency
Sampling Frequency in main.cpp
#define SampleFreq 200 // [Hz]
Auto Stop Setting
Auto-stop Timer 15sec after
// auto-stop when 15sec after if(smpl_cnt>3000){stop_dump();}
The number of 3000 means Sample Count. The number is given by SampleFreq[Hz] * Auto-Stop Time [sec].
M-Series Random Sequence
M-series Random Update Term in main.cpp
// M-series update flag #define M_TERM 200;
Unit is sample count.
cf.) 200 equals to 200 [samples] which equals to 1 [second] where SampleFreq = 200 [Hz}.
See above.
M-Series Random Servo Control
Diff: M-Series.h
- Branch:
- MPU-9250-MagSensServo
- Revision:
- 1:3bcd844dd707
- Child:
- 2:3470f2c07582
diff -r 4656a133ed1a -r 3bcd844dd707 M-Series.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/M-Series.h Tue Feb 02 13:43:21 2021 +0000 @@ -0,0 +1,89 @@ +// +// M-Series Random Sequence Generator +// +// Masahiro Furukawa, m.furukawa@ist.osaka-u.ac.jp +// Feb 2, 2021 + +// m-sequence +// https://okasho-engineer.com/m-sequence/ + + +#ifndef __M_SERIES_H__ +#define __M_SERIES_H__ + +#define MSeries_N 16 + +// m-series definition +class Mseries +{ +private: + uint8_t M[MSeries_N]; + uint8_t H[MSeries_N]; + +public: + Mseries() + { + + // the following initial values are not validated + M[0] = 0; + M[1] = 0; + M[2] = 0; + M[3] = 1; + M[4] = 0; + M[5] = 0; + M[6] = 0; + M[7] = 1; + M[8] = 0; + M[9] = 0; + M[10] = 0; + M[11] = 1; + M[12] = 0; + M[13] = 0; + M[14] = 0; + M[15] = 1; + + // the following initial values are not validated + H[0] = 1; + H[1] = 0; + H[2] = 0; + H[3] = 1; + H[4] = 1; + H[5] = 0; + H[6] = 0; + H[7] = 1; + H[8] = 1; + H[9] = 0; + H[10] = 0; + H[11] = 1; + H[12] = 1; + H[13] = 0; + H[14] = 0; + H[15] = 1; + } + + uint8_t update(void) + { + // update M-series + uint8_t Mtmp = M[0] * H[0]; + + // one left-shifting on ring buffer + M[0] = M[1]; + + // take sequential XOR on the entire sequence + for (int i = 1 ; i < MSeries_N - 1 ; i++) { + // XOR + Mtmp = (Mtmp + M[i] * H[i]) % 2; + + // one left-shifting on ring buffer + M[i] = M[i + 1]; + } + + // store the latest value at the last + M[MSeries_N - 1] = Mtmp; + + return Mtmp; + } +}; + + +#endif // __M_SERIES_H__ \ No newline at end of file