| 12345678910111213141516171819202122232425 |
- #include "ntc_sensor.h"
- #include "bsp/bsp.h"
- #include "bsp/adc.h"
- static ntc_t _ntc;
- void ntc_sensor_init(void) {
- _ntc.temp_avg = 0;
- _ntc.low_pass_filter = 0.5f;
- ntc_sensor_sample();
- }
- void ntc_sensor_sample(void){
- u16 w_temp = adc_sample_regular_channel(MOTOR_TEMP_CHAN, 16);
- w_temp -= ( s32 )(V0_V *4096/ ADC_REFERENCE_VOLTAGE );
- w_temp *= (ADC_REFERENCE_VOLTAGE/dV_dT);
- w_temp = w_temp / 4096 + ( s32 )( T0_C );
- _ntc.temp_avg = w_temp * _ntc.low_pass_filter + _ntc.temp_avg * (1.0f - _ntc.low_pass_filter);
- }
- int ntc_sensor_temperature(void){
- return _ntc.temp_avg;
- }
|