131 constexpr double pga_gain[] = { 0.2, 0.4, 0.8, 1, 2, 4, 8, 16 };
135 for (
auto i = 0; i < 4; i++ )
138 const uint16_t setbit = 0x1 << ch;
143 if ( cc[ 0 ] & 0x0010 )
144 coeff_uV[ ch ] = ((10.0 / (double)(1L << 24)) / pga_gain[ (cc[ 0 ] >> 5) & 0x7 ]) * 1e6;
146 coeff_uV[ ch ] = (4.0 / (double)(1L << 24)) * 1e6;
153 constexpr static double data_rates[] = { 288000, 192000, 144000, 96000, 72000, 48000, 36000, 24000,
154 18000, 12000, 9000, 6000, 4500, 3000, 2250, 1125,
155 562.5, 400, 300, 200, 100, 60, 50, 30,
156 25, 20, 15, 10, 7.5, };
157 constexpr static uint16_t delays[] = { 0, 2, 4, 6, 8, 10, 12, 14,
158 16, 18, 20, 28, 38, 40, 42, 56,
159 64, 76, 90, 128, 154, 178, 204, 224,
161 1024, 1664, 3276, 7680, 19200, 23040, };
168 uint8_t adc_data_rate = (ch_config1 >> 3) & 0x001F;
169 uint8_t adc_sinc = (ch_config1 >> 0) & 0x0007;
170 uint8_t
ch_delay = (ch_config2 >> 10) & 0x003F;
171 bool adc_normal_setting = (ch_config2 >> 9) & 0x0001;
172 bool ch_chop = (ch_config2 >> 7) & 0x0001;
174 double base_freq = data_rates[ adc_data_rate ];
175 double delay_setting = delays[
ch_delay ] / 4608000.00;
177 if ( (28 < adc_data_rate) || (4 < adc_sinc) || ((adc_data_rate < 12) && (adc_sinc)) )
180 if ( !adc_normal_setting )
181 base_freq /= (adc_sinc + 1);
187 printf(
"base_freq = %lf\r\n", base_freq );
188 printf(
"delay_setting = %lf\r\n", delay_setting );
189 printf(
"total delay = %lf\r\n", (1 / base_freq) + delay_setting );
192 return (1 / base_freq) + delay_setting;
272 constexpr double pga1x_voltage = 5.0;
273 constexpr int adc_resolution = 24;
274 constexpr double pga_gain_setting = 0.2;
276 constexpr double fullscale_voltage = pga1x_voltage / pga_gain_setting;
278 double fullscale_data = pow( 2, (adc_resolution - 1) );
282 double dv_slope = ref_data_span / ref_voltage_span;
283 double custom_gain = dv_slope * (fullscale_voltage / fullscale_data);
284 double custom_offset = (dv_slope * ref.
low.
voltage - ref.
low.
data) / custom_gain;
288 int32_t gain_coeff_new = round( gain_coeff_cal * custom_gain );
289 int32_t offset_coeff_new = round( custom_offset - offsset_coeff_cal );
294 printf(
"gain_coeff_new = %8ld\r\n", gain_coeff_new );
295 printf(
"offset_coeff_new = %8ld\r\n", offset_coeff_new );
302void NAFE13388_Base::recalibrate(
int pga_gain_index,
int channel_selection,
int input_select,
double reference_source_voltage,
bool use_positive_side )
304 constexpr auto low_gain_index = 4;
305 auto channel_in_use =
false;
310 channel_in_use =
true;
314 for (
auto i = 0; i < 4; i++ )
320 if ( pga_gain_index <= low_gain_index )
323 reference_source_voltage = 2.30;
328 reference_source_voltage = 0.20;
332 const uint16_t REF_GND = 0x0011 | (pga_gain_index << 5);
333 const uint16_t REF_V = (input_select << (use_positive_side ? 12 : 8)) | REF_GND;
334 const uint16_t ch_config1 = (pga_gain_index << 12) | 0x00E4;
335 constexpr uint16_t ch_config2 = 0x8400;
336 constexpr uint16_t ch_config3 = 0x0000;
338 const ch_setting_t refh = { REF_V, ch_config1, ch_config2, ch_config3 };
339 const ch_setting_t refg = { REF_GND, ch_config1, ch_config2, ch_config3 };
347 constexpr double pga_gain[] = { 0.2, 0.4, 0.8, 1, 2, 4, 8, 16 };
349 const double fullscale_voltage = 5.00 / pga_gain[ pga_gain_index ];
350 const double calibrated_gain = pow( 2, 23 ) * (reference_source_voltage / fullscale_voltage) / (
double)(data_REF - data_GND);
353 printf(
"data_REF = %8ld\r\n", data_REF );
354 printf(
"data_GND = %8ld\r\n", data_GND );
355 printf(
"gain adjustment = %8lf (%lfdB)\r\n", calibrated_gain, 20 * log10( calibrated_gain ) );
364 if ( channel_in_use )
400 uint16_t pattern[] = {
401 0x8000, 0x0040, 0x0100, 0x0080, 0x0200, 0x0400, 0x0800, 0x1000,
402 0x2000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0080,
409 for (
auto j = 0; j < 2; j++ )
411 for (
auto i = 0U; i <
sizeof( pattern ) /
sizeof( uint16_t ); i++ )
420 for (
auto j = 0; j < 4; j++ )
422 for (
auto i = 0; i < 10; i++ )
424 pv = (j % 2) ? pv & ~pattern[ i ] : pv | pattern[ i ];