110 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
#ifndef PHY_TEMPERATURE_H
 | 
						|
#define PHY_TEMPERATURE_H
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
#ifndef PLC_PHY_SUPPORT_TEMPERATURE
 | 
						|
#define PLC_PHY_SUPPORT_TEMPERATURE (!PLC_SUPPORT_HW_TOPO)
 | 
						|
#endif
 | 
						|
 | 
						|
#if PLC_PHY_SUPPORT_TEMPERATURE
 | 
						|
 | 
						|
typedef struct _phy_temperature_ctxt {
 | 
						|
    float    cur_tempt_val;
 | 
						|
    uint32_t tempt_raw_data;
 | 
						|
    uint32_t cnt:4,
 | 
						|
             resv:28;
 | 
						|
} phy_temperature_ctxt_t;
 | 
						|
 | 
						|
/**
 | 
						|
 * Temperature calculate:
 | 
						|
 * Range from -40 to 125°C, the temperature is linear proportional
 | 
						|
 * to ADC collected voltage. The coefficient is 2.54mV/°C
 | 
						|
 * Kceof = 2.54mV/°C
 | 
						|
 * ADC_Res = 350mV / 2360;
 | 
						|
 * Vcode = code * ADC_Res;
 | 
						|
 * Vbase = 736mV (in Tbase = 20°C)
 | 
						|
 * Temp = Tbase + (Vcode - Vbase) / Kcoef
 | 
						|
 *      = Tbase + (code * ADC_Res  - Vbase) / Kcoef
 | 
						|
 * code = (((Temp - Tbase) * Kcoef) + Vbase) / ADC_Res;
 | 
						|
 */
 | 
						|
 | 
						|
/* temperature new raw data weight */
 | 
						|
#define NEW_RAW_WEIGHT      2
 | 
						|
/* rated temperature minimum */
 | 
						|
#define TEMP_VAL_MIN        (-40)
 | 
						|
/* rated temperature maximum */
 | 
						|
#define TEMP_VAL_MAX        (125)
 | 
						|
/* ADC value fileter value */
 | 
						|
#define TEMP_ADC_FILTER     (1000)
 | 
						|
/* temperature and voltage coefficient is 2.54mV/°C */
 | 
						|
#define K_COEF              (2.54f)
 | 
						|
/* calibrate voltage in 20°C is 736mV */
 | 
						|
#define V_BASE              (736)
 | 
						|
/* calibrate temperature  20°C */
 | 
						|
#define T_BASE              (20)
 | 
						|
/* ADC resolution */
 | 
						|
#define ADC_RES             (350.0f / 2360)
 | 
						|
/* convert ADC value to temperature */
 | 
						|
#define RAW_TO_TEMP(code)   (T_BASE + ((code) * ADC_RES - V_BASE) / K_COEF)
 | 
						|
/* convert temperature value to ADC value */
 | 
						|
#define TEMP_TO_RAW(temp)   (((((temp) - T_BASE) * K_COEF) + V_BASE) / ADC_RES)
 | 
						|
/* calc valid minimum raw data */
 | 
						|
#define RAW_DATA_VALID_MIN  (TEMP_TO_RAW(TEMP_VAL_MIN))
 | 
						|
/* calc valid maximum raw data */
 | 
						|
#define RAW_DATA_VALID_MAX  (TEMP_TO_RAW(TEMP_VAL_MAX))
 | 
						|
/* skip how many data after mcu reset */
 | 
						|
#define TEMPT_DATA_SKIP     10
 | 
						|
 | 
						|
/*
 | 
						|
 * @brief :                  init phy temperature adc channel
 | 
						|
 * @param :                  none
 | 
						|
 * @retval:                  none
 | 
						|
 */
 | 
						|
void phy_temperature_adc_init(void);
 | 
						|
 | 
						|
/*
 | 
						|
 * @brief :                  scan phy temperature adc value
 | 
						|
 * @param :                  none
 | 
						|
 * @retval:                  none
 | 
						|
 */
 | 
						|
void phy_temperature_adc_scan(void);
 | 
						|
 | 
						|
/*
 | 
						|
 * @brief :                  get temperature value
 | 
						|
 * @param :                  none
 | 
						|
 * @retval:                  return temperature value
 | 
						|
 */
 | 
						|
float phy_temperature_val_get(void);
 | 
						|
 | 
						|
#else
 | 
						|
 | 
						|
#define phy_temperature_adc_init()
 | 
						|
#define phy_temperature_adc_scan()
 | 
						|
#define phy_temperature_val_get()   0
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif // !PHY_TEMPERATURE_H
 |