8 #ifndef ANTENNALEVEL_H_ 9 #define ANTENNALEVEL_H_ 13 #define ANTENNA_LEVEL_R1 47E3 14 #define ANTENNA_LEVEL_R2 1E3 15 #define ANTENNA_LEVEL_VREF 1.0 16 #define ANTENNA_LEVEL_RES 4096 17 #define ANTENNA_LEVEL_OFFSET 190 19 #define ANTENNA_LEVEL_MILLIVOLT 1E3 20 #define ANTENNA_LEVEL_FACTOR (ANTENNA_LEVEL_VREF * (ANTENNA_LEVEL_R1 + ANTENNA_LEVEL_R2) / (ANTENNA_LEVEL_RES * ANTENNA_LEVEL_R2) ) 21 #define ANTENNA_LEVEL_SCALE ((uint32_t) 1<<16) 22 #define ANTENNA_LEVEL_NUMERATOR ((uint32_t) (ANTENNA_LEVEL_MILLIVOLT * ANTENNA_LEVEL_FACTOR * ANTENNA_LEVEL_SCALE + .5)) 23 #define ANTENNA_LEVEL_DENOMINATOR (ANTENNA_LEVEL_SCALE) 25 #define ANTENNA_LEVEL_LOG_RDRDETECT_INTERVAL (15) 26 extern uint8_t AntennaLevelLogReaderDetectCount;
28 #define FIELD_MIN_RSSI 500 31 void AntennaLevelInit(
void) {
32 ADCA.CAL = (PRODSIGNATURES_ADCACAL1 << 8) | PRODSIGNATURES_ADCACAL0;
33 ADCA.CTRLA = ADC_ENABLE_bm;
34 ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
35 ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
36 ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc;
37 ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
38 ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
43 uint16_t AntennaLevelGet(
void) {
44 ADCA.CH0.CTRL |= ADC_CH_START_bm;
45 while (!(ADCA.CH0.INTFLAGS & ADC_CH_CHIF_bm));
47 ADCA.CH0.INTFLAGS = ADC_CH_CHIF_bm;
49 int16_t Result = ADCA.CH0RES - ANTENNA_LEVEL_OFFSET;
50 if (Result < 0) Result = 0;
52 return (uint16_t)(((uint32_t) Result * ANTENNA_LEVEL_NUMERATOR) / ANTENNA_LEVEL_DENOMINATOR);
55 void AntennaLevelTick(
void);
56 void AntennaLevelResetMaxRssi(
void);