You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
916 B

2 months ago
#include "ntc.h"
#include "comp_adc.h"
#include "drv_analog.h"
#include "comp_gp_mux_pucur.h"
#include <stdbool.h>
#include <stdint.h>
#define NTC_OFFSET 1156
typedef struct debouncer
{
uint16_t cnt;
uint16_t out;
} debouncer_s;
static debouncer_s deb;
static bool _debounce(debouncer_s *obj, bool in, uint16_t up_time, uint16_t down_time)
{
if(in == obj->out)
{
obj->cnt = obj->out ? down_time : up_time;
}
else if(obj->cnt == 0 || --obj->cnt == 0)
{
obj->out = in;
obj->cnt = obj->out ? down_time : up_time;
}
return obj->out;
}
void ntc_init(void)
{
drv_clkctrl_pin_mul_cfg(RT1, 0);
rt1_pucur_cfg(RT_100UA);
}
void ntc_run(void)
{
uint16_t adc_value = 0;
adc_value = COMP_ADC_GET_RT1_VOL();
uint8_t out = 0;
out = _debounce(&deb, adc_value <= NTC_OFFSET, 1000, 100);
if(out)
{
NVIC_SystemReset();
}
}