# Transformations

## ADC Transformations

The six ADC channels are passed through a transformation stage before being output as JCS signals

Select a transformation by writing an enum to `transform_type`

:

Control mode | Description |
---|---|

`linear_gain_offset` |
Basic gain and offset transform. |

`linear_gain_offset_tc_adc` |
Gain and offset transform with temperature compensated ADC values. |

`linear_gain_offset_tc_mat` |
Gain and offset transform with temperature compensated gain matrix and offset vector. |

### Gain and offset

Basic linear transform of the form \(\mathbf{y} = \mathbf{Ax} + \mathbf{b}\).

Where

- \(\mathbf{x}\) is vector of 6 ADC values in the range [-1, 1]
- \(\mathbf{A}\) is a 6x6 gain matrix
- \(\mathbf{b}\) is a 1x6 offset vector

Configure the transform with:

Commands | Type | Required | Description |
---|---|---|---|

`transform_gain_offset_A` |
float32 | Required | Float32 vector of gain matrix coefficients. Length: 36 |

`transform_gain_offset_b` |
float32 | Required | Float32 vector of offset vector coefficients. Length: 6 |

### Gain and offset, with temperature compensated ADC

Gain and offset transform with temperature compensated ADC values, of the form \(\mathbf{y} = \mathbf{Ax}(t_c) + \mathbf{b}\)

- \(\mathbf{x}(t_c)\) is vector of 6 temperature compensated ADC values in the range [-1, 1]
- \(t_c\) is the temperature from the source defined in
`temperature_source`

- \(\mathbf{A}\) is a 6x6 gain matrix
- \(\mathbf{b}\) is a 1x6 offset vector

Configure the transform with:

Commands | Type | Required | Description |
---|---|---|---|

`transform_gain_offset_tc_adc_A` |
float32 | Required | Float32 vector of gain matrix coefficients. Length: 36 |

`transform_gain_offset_tc_adc_b` |
float32 | Required | Float32 vector of offset vector coefficients. Length: 6 |

#### Per ADC channel temperature compensation

Each ADC channel may be temperature corrected as:

\(x(t_c) = x - bias(t_c)\) ,

where \(x\) is the ADC value and \(bias(t_c)\) is the polynomial:

\(bias(t_c) = C_{0}dt^3 + C_{1}dt^2 + C_{2}dt + C_{3}\)

and

\(dt = t_c - (t_{c-max} - t_{c-min})\) .

Here \(C_0\) to \(C_3\) are the temperature compensation polynomial coefficients and \(t_{c-max}\) and \(t_{c-min}\) define the temperature region over which the polynomial coefficients were captured.
This also defines the valid compensation range.
If the temperature exceeds the valid compensation range the temperature compensation action will clamp at that limit and the `Temperature compensation clamped flag`

(bit 4) in the JCS `op_state`

signal will be asserted.

Valid signal outputs will still be generated, however the correctness of the signals cannot be assured.

Configure the polynomial coefficients and temperature range with:

Commands | Type | Required | Description |
---|---|---|---|

`transform_gain_offset_tc_adc_x_poly_0` |
float32 array | Required | Float32 vector of ADC compensation polynomial coefficients for channel 0. Length: 4 |

`transform_gain_offset_tc_adc_x_poly_1` |
float32 array | Required | Float32 vector of ADC compensation polynomial coefficients for channel 1. Length: 4 |

`transform_gain_offset_tc_adc_x_poly_2` |
float32 array | Required | Float32 vector of ADC compensation polynomial coefficients for channel 2. Length: 4 |

`transform_gain_offset_tc_adc_x_poly_3` |
float32 array | Required | Float32 vector of ADC compensation polynomial coefficients for channel 3. Length: 4 |

`transform_gain_offset_tc_adc_x_poly_4` |
float32 array | Required | Float32 vector of ADC compensation polynomial coefficients for channel 4. Length: 4 |

`transform_gain_offset_tc_adc_x_poly_5` |
float32 array | Required | Float32 vector of ADC compensation polynomial coefficients for channel 5. Length: 4 |

`transform_gain_offset_tc_adc_tC_max` |
float32 | Required | Maximum temperature at which compensation is valid. |

`transform_gain_offset_tc_adc_tC_min` |
float32 | Required | Minimum temperature at which compensation is valid. |

## Temperature compensation

The temperature compensation source may be configured by writing an enum to `temperature_source`

:

Source | Description |
---|---|

`source_temperature_disabled` |
The temperature compensation is disabled. Default |

`source_temperature_onboard` |
Temperature is sourced from the on board temperature sensor. This effectively measures the temperature of the device PCB. |

`source_temperature_an_0` |
External analog temperature sensor attached to port `an_0` . An example is a sensor fixed to, or in the vicinity of the strain gauge elecment.The analog interface must have the gain and scale configured correctly. |

`source_temperature_network` |
Temperature is sourced from the the JCS network. Input signal `t_net` must be connected to a valid temperature source |