LibDriver NTC
Loading...
Searching...
No Matches
driver_ntc_basic.c
Go to the documentation of this file.
1
36
37#include "driver_ntc_basic.h"
38
39static ntc_handle_t gs_handle;
40
50uint8_t ntc_basic_init(ntc_circuit_t circuit, float r_fixed_ohm)
51{
52 uint8_t res;
53
54 /* link interface function */
61
62 /* init */
63 res = ntc_init(&gs_handle);
64 if (res != 0)
65 {
66 ntc_interface_debug_print("ntc: init failed.\n");
67
68 return 1;
69 }
70
71 /* set circuit */
72 res = ntc_set_circuit(&gs_handle, circuit);
73 if (res != 0)
74 {
75 ntc_interface_debug_print("ntc: set circuit.\n");
76 (void)ntc_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set circuit fixed resistor */
82 res = ntc_set_circuit_fixed_resistor(&gs_handle, r_fixed_ohm);
83 if (res != 0)
84 {
85 ntc_interface_debug_print("ntc: set circuit fixed resistor.\n");
86 (void)ntc_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 return 0;
92}
93
101uint8_t ntc_basic_deinit(void)
102{
103 if (ntc_deinit(&gs_handle) != 0)
104 {
105 return 1;
106 }
107
108 return 0;
109}
110
120uint8_t ntc_basic_set_algorithm_beta_formula(float beta, float r25_ohm)
121{
122 uint8_t res;
123
124 /* set algorithm beta formula */
126 if (res != 0)
127 {
128 return 1;
129 }
130
131 /* set algorithm beta formula beta value */
132 res = ntc_set_algorithm_beta_formula_beta_value(&gs_handle, beta);
133 if (res != 0)
134 {
135 return 1;
136 }
137
138 /* set algorithm beta formula r25 ohm */
139 res = ntc_set_algorithm_beta_formula_r25_ohm(&gs_handle, r25_ohm);
140 if (res != 0)
141 {
142 return 1;
143 }
144
145 return 0;
146}
147
158uint8_t ntc_basic_set_algorithm_steinhart_hart(double a, double b, double c)
159{
160 uint8_t res;
161
162 /* set algorithm steinhart hart */
164 if (res != 0)
165 {
166 return 1;
167 }
168
169 /* set algorithm steinhart hart */
170 res = ntc_set_algorithm_steinhart_hart(&gs_handle, a, b, c);
171 if (res != 0)
172 {
173 return 1;
174 }
175
176 return 0;
177}
178
188uint8_t ntc_basic_set_algorithm_lookup_table(const ntc_table_t *table, uint16_t table_len)
189{
190 uint8_t res;
191
192 /* set algorithm steinhart hart */
194 if (res != 0)
195 {
196 return 1;
197 }
198
199 /* set algorithm lookup table */
200 res = ntc_load_algorithm_lookup_table(&gs_handle, table, table_len);
201 if (res != 0)
202 {
203 return 1;
204 }
205
206 return 0;
207}
208
217{
218 uint8_t res;
219
220 /* set filter */
221 res = ntc_set_filter(&gs_handle, NTC_FILTER_NONE);
222 if (res != 0)
223 {
224 return 1;
225 }
226
227 return 0;
228}
229
239{
240 uint8_t res;
241
242 /* set filter */
244 if (res != 0)
245 {
246 return 1;
247 }
248
249 /* filter first order lag */
250 res = ntc_set_filter_first_order_lag(&gs_handle, alpha);
251 if (res != 0)
252 {
253 return 1;
254 }
255
256 return 0;
257}
258
267uint8_t ntc_basic_set_filter_median(uint16_t length)
268{
269 uint8_t res;
270
271 /* set filter */
272 res = ntc_set_filter(&gs_handle, NTC_FILTER_MEDIAN);
273 if (res != 0)
274 {
275 return 1;
276 }
277
278 /* set median filter length */
279 res = ntc_set_filter_median_length(&gs_handle, length);
280 if (res != 0)
281 {
282 return 1;
283 }
284
285 return 0;
286}
287
297{
298 uint8_t res;
299
300 /* set filter */
302 if (res != 0)
303 {
304 return 1;
305 }
306
307 /* set anti spike average length */
308 res = ntc_set_filter_anti_spike_average_length(&gs_handle, length);
309 if (res != 0)
310 {
311 return 1;
312 }
313
314 return 0;
315}
316
326{
327 uint8_t res;
328
329 /* set filter */
330 res = ntc_set_filter(&gs_handle, NTC_FILTER_MOVING_AVERAGE);
331 if (res != 0)
332 {
333 return 1;
334 }
335
336 /* set moving average length */
337 res = ntc_set_filter_moving_average_length(&gs_handle, length);
338 if (res != 0)
339 {
340 return 1;
341 }
342
343 return 0;
344}
345
355uint8_t ntc_basic_set_filter_weighted_moving_average(float *weight, uint16_t length)
356{
357 uint8_t res;
358
359 /* set filter */
361 if (res != 0)
362 {
363 return 1;
364 }
365
366 /* set weighted moving average length */
367 res = ntc_set_filter_weighted_moving_average_length(&gs_handle, weight, length);
368 if (res != 0)
369 {
370 return 1;
371 }
372
373 return 0;
374}
375
384uint8_t ntc_basic_set_filter_limiting(float degrees_celsius)
385{
386 uint8_t res;
387
388 /* set filter */
389 res = ntc_set_filter(&gs_handle, NTC_FILTER_LIMITING);
390 if (res != 0)
391 {
392 return 1;
393 }
394
395 /* set limiting */
396 res = ntc_set_filter_limiting(&gs_handle, degrees_celsius);
397 if (res != 0)
398 {
399 return 1;
400 }
401
402 return 0;
403}
404
416uint8_t ntc_basic_set_filter_kalman(float q_process_noise_covariance,
417 float r_measurement_noise_covariance,
418 float p_estimation_error_covariance,
419 float x_estimated_value)
420{
421 uint8_t res;
422
423 /* set filter */
424 res = ntc_set_filter(&gs_handle, NTC_FILTER_KALMAN);
425 if (res != 0)
426 {
427 return 1;
428 }
429
430 /* set kalman */
431 res = ntc_set_filter_kalman(&gs_handle,
432 q_process_noise_covariance,
433 r_measurement_noise_covariance,
434 p_estimation_error_covariance,
435 x_estimated_value);
436 if (res != 0)
437 {
438 return 1;
439 }
440
441 return 0;
442}
443
452{
453 uint8_t res;
454
455 /* reset filter */
456 res = ntc_reset_filter(&gs_handle);
457 if (res != 0)
458 {
459 return 1;
460 }
461
462 return 0;
463}
464
473uint8_t ntc_basic_read(float *degrees_celsius)
474{
475 uint8_t res;
476 float ohm;
477
478 /* read temperature */
479 res = ntc_read_temperature(&gs_handle, &ohm, degrees_celsius);
480 if (res != 0)
481 {
482 return 1;
483 }
484
485 return 0;
486}
487
497uint8_t ntc_basic_calculate_temperature(float ohm, float *degrees_celsius)
498{
499 uint8_t res;
500
501 /* calculate temperature */
502 res = ntc_calculate_temperature(&gs_handle, ohm, degrees_celsius);
503 if (res != 0)
504 {
505 return 1;
506 }
507
508 return 0;
509}
510
521uint8_t ntc_basic_calculate_temperature_with_filter(float *ohm, uint16_t len, float *degrees_celsius)
522{
523 uint8_t res;
524
525 /* calculate temperature with filter */
526 res = ntc_calculate_temperature_with_filter(&gs_handle, ohm, len, degrees_celsius);
527 if (res != 0)
528 {
529 return 1;
530 }
531
532 return 0;
533}
driver ntc basic header file
uint8_t ntc_read_temperature(ntc_handle_t *handle, float *ohm, float *degrees_celsius)
read temperature
uint8_t ntc_set_algorithm_steinhart_hart(ntc_handle_t *handle, double a, double b, double c)
set algorithm steinhart hart
Definition driver_ntc.c:831
uint8_t ntc_set_circuit(ntc_handle_t *handle, ntc_circuit_t circuit)
set circuit
Definition driver_ntc.c:576
uint8_t ntc_load_algorithm_lookup_table(ntc_handle_t *handle, const ntc_table_t *table, uint16_t table_len)
load algorithm lookup table
Definition driver_ntc.c:893
uint8_t ntc_set_algorithm(ntc_handle_t *handle, ntc_algorithm_t algorithm)
set algorithm
Definition driver_ntc.c:673
uint8_t ntc_set_algorithm_beta_formula_r25_ohm(ntc_handle_t *handle, float r25_ohm)
set algorithm beta formula r25 ohm
Definition driver_ntc.c:777
uint8_t ntc_init(ntc_handle_t *handle)
initialize the chip
ntc_circuit_t
ntc circuit enumeration definition
Definition driver_ntc.h:71
uint8_t ntc_calculate_temperature_with_filter(ntc_handle_t *handle, float *ohm, uint16_t len, float *degrees_celsius)
calculate temperature with filter
uint8_t ntc_set_algorithm_beta_formula_beta_value(ntc_handle_t *handle, float beta)
set algorithm beta formula beta value
Definition driver_ntc.c:725
struct ntc_handle_s ntc_handle_t
ntc handle structure definition
uint8_t ntc_deinit(ntc_handle_t *handle)
close the chip
struct ntc_table_s ntc_table_t
ntc table structure definition
uint8_t ntc_calculate_temperature(ntc_handle_t *handle, float ohm, float *degrees_celsius)
calculate temperature
uint8_t ntc_set_circuit_fixed_resistor(ntc_handle_t *handle, float r_fixed_ohm)
set circuit fixed resistor
Definition driver_ntc.c:628
@ NTC_FILTER_MEDIAN
Definition driver_ntc.h:93
@ NTC_FILTER_ANTI_SPIKE_AVERAGE
Definition driver_ntc.h:94
@ NTC_FILTER_FIRST_ORDER_LAG
Definition driver_ntc.h:92
@ NTC_FILTER_NONE
Definition driver_ntc.h:91
@ NTC_FILTER_MOVING_AVERAGE
Definition driver_ntc.h:95
@ NTC_FILTER_KALMAN
Definition driver_ntc.h:98
@ NTC_FILTER_WEIGHTED_MOVING_AVERAGE
Definition driver_ntc.h:96
@ NTC_FILTER_LIMITING
Definition driver_ntc.h:97
@ NTC_ALGORITHM_LOOKUP_TABLE
Definition driver_ntc.h:83
@ NTC_ALGORITHM_BETA_FORMULA
Definition driver_ntc.h:81
@ NTC_ALGORITHM_STEINHART_HART
Definition driver_ntc.h:82
uint8_t ntc_basic_set_filter_none(void)
basic example set filter none
uint8_t ntc_basic_reset_filter(void)
basic example reset filter
uint8_t ntc_basic_set_filter_anti_spike_average(uint16_t length)
basic example set filter anti spike average
uint8_t ntc_basic_set_algorithm_lookup_table(const ntc_table_t *table, uint16_t table_len)
basic example set algorithm lookup table
uint8_t ntc_basic_init(ntc_circuit_t circuit, float r_fixed_ohm)
basic example init
uint8_t ntc_basic_read(float *degrees_celsius)
basic example read
uint8_t ntc_basic_set_filter_limiting(float degrees_celsius)
basic example set filter limiting
uint8_t ntc_basic_deinit(void)
basic example deinit
uint8_t ntc_basic_set_algorithm_steinhart_hart(double a, double b, double c)
basic example set algorithm steinhart hart
uint8_t ntc_basic_calculate_temperature_with_filter(float *ohm, uint16_t len, float *degrees_celsius)
basic calculate temperature with filter
uint8_t ntc_basic_set_filter_kalman(float q_process_noise_covariance, float r_measurement_noise_covariance, float p_estimation_error_covariance, float x_estimated_value)
basic example set filter kalman
uint8_t ntc_basic_set_filter_moving_average(uint16_t length)
basic example set filter moving average
uint8_t ntc_basic_set_filter_first_order_lag(float alpha)
basic example set filter first order lag
uint8_t ntc_basic_set_algorithm_beta_formula(float beta, float r25_ohm)
basic example set algorithm beta formula
uint8_t ntc_basic_set_filter_weighted_moving_average(float *weight, uint16_t length)
basic example set filter weighted moving average
uint8_t ntc_basic_set_filter_median(uint16_t length)
basic example set filter median
uint8_t ntc_basic_calculate_temperature(float ohm, float *degrees_celsius)
basic calculate temperature
uint8_t ntc_set_filter_first_order_lag(ntc_handle_t *handle, float alpha)
set filter first order lag
Definition driver_ntc.c:995
uint8_t ntc_set_filter_moving_average_length(ntc_handle_t *handle, uint16_t length)
set filter moving average length
uint8_t ntc_set_filter_limiting(ntc_handle_t *handle, float degrees_celsius)
set filter limiting
uint8_t ntc_set_filter_median_length(ntc_handle_t *handle, uint16_t length)
set filter median length
uint8_t ntc_reset_filter(ntc_handle_t *handle)
reset the filter
uint8_t ntc_set_filter_anti_spike_average_length(ntc_handle_t *handle, uint16_t length)
set filter anti spike average length
uint8_t ntc_set_filter(ntc_handle_t *handle, ntc_filter_t filter)
set filter
Definition driver_ntc.c:950
uint8_t ntc_set_filter_kalman(ntc_handle_t *handle, float q_process_noise_covariance, float r_measurement_noise_covariance, float p_estimation_error_covariance, float x_estimated_value)
set filter kalman
uint8_t ntc_set_filter_weighted_moving_average_length(ntc_handle_t *handle, float *weight, uint16_t length)
set filter weighted moving average length
uint8_t ntc_interface_adc_init(uint32_t *vcc_counter)
interface adc init
uint8_t ntc_interface_adc_deinit(void)
interface adc deinit
uint8_t ntc_interface_adc_read(uint32_t *counter, uint16_t len)
interface adc read
void ntc_interface_debug_print(const char *const fmt,...)
interface print format data
void ntc_interface_delay_ms(uint32_t ms)
interface delay ms