2024-07-11 06:58:55 +00:00
|
|
|
|
/*
|
|
|
|
|
* collect_Conversion.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2024<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>21<EFBFBD><EFBFBD>
|
|
|
|
|
* Author: psx
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "collect_Conversion.h"
|
2024-07-22 06:20:24 +00:00
|
|
|
|
#include "gpio.h"
|
2024-07-11 06:58:55 +00:00
|
|
|
|
#include "adc.h"
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#define CHG_CURR ADC_Channel_1
|
|
|
|
|
#define PV_VOLT_OUT ADC_Channel_2
|
|
|
|
|
#define DSG_CURR ADC_Channel_3
|
|
|
|
|
#define PV1_VOLT_IN ADC_Channel_4
|
|
|
|
|
#define PV_VOLT_IN1 ADC_Channel_5
|
|
|
|
|
#define MOSFET_Temper ADC_Channel_6
|
|
|
|
|
#define PV2_VOLT_IN ADC_Channel_7
|
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
//#define enable_Printf_VI
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>*<2A><><EFBFBD><EFBFBD> */
|
|
|
|
|
const float P_CHG_CURR = (1.0 / (50 * 0.005));
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹϵ<D1B9><CFB5><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ʱ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><D7BC> */
|
|
|
|
|
const float P_PV_VOLT_OUT = (47 + 4.7) / 4.7;
|
|
|
|
|
/* <20>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
const float P_DSG_CURR = (1.0 / (50 * 0.005));
|
2024-07-22 06:20:24 +00:00
|
|
|
|
///* <20><><EFBFBD><EFBFBD>1<EFBFBD><31>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD> */
|
|
|
|
|
//const float P_PV1_VOLT_IN = (100 + 4.7) / 4.7;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>1<EFBFBD><31>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD> */
|
2024-07-22 06:20:24 +00:00
|
|
|
|
const float P_PV1_VOLT_IN = (100 + 10) / 10;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
/* ϵͳ<CFB5><CDB3>Դ<EFBFBD><D4B4>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD> */
|
|
|
|
|
const float P_PV_VOLT_IN1 = (47 + 4.7) / 4.7;
|
|
|
|
|
/* <20>¶Ȳɼ<C8B2><C9BC><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
const float P_MOSFET_TEMPER = 0;
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>2<EFBFBD><32>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD> */
|
|
|
|
|
const float P_PV2_VOLT_IN = (100 + 4.7) / 4.7;
|
|
|
|
|
|
|
|
|
|
static uint16_t get_adc(uint8_t ADC_Channel);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>adc<EFBFBD><EFBFBD><EFBFBD><EFBFBD>У
|
|
|
|
|
* @param val <EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>adc<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @retval У<EFBFBD><EFBFBD><EFBFBD><EFBFBD>adc<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint16_t Get_ConversionVal(int16_t val)
|
|
|
|
|
{
|
|
|
|
|
if((val + Calibrattion_Val) < 0 || val == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
if((Calibrattion_Val + val) > 4095 || val == 4095)
|
|
|
|
|
return 4095;
|
|
|
|
|
return (val + Calibrattion_Val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD>adc<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param ADC_Channel adcͨ<EFBFBD><EFBFBD>
|
|
|
|
|
* @retval val adc<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint16_t get_adc(uint8_t ADC_Channel)
|
|
|
|
|
{
|
|
|
|
|
uint16_t val;
|
|
|
|
|
ADC_RegularChannelConfig(ADC1, ADC_Channel, 1, ADC_SampleTime_CyclesMode5);
|
|
|
|
|
// ADC_RegularChannelConfig(ADC1, ADC_Channel, 1, ADC_SampleTime_CyclesMode7);
|
|
|
|
|
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
|
|
|
|
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
|
|
|
|
|
val = ADC_GetConversionValue(ADC1);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval I <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
*/
|
|
|
|
|
float get_CHG_CURR(void)
|
|
|
|
|
{
|
|
|
|
|
float I;
|
|
|
|
|
uint16_t I_ADC;
|
|
|
|
|
|
|
|
|
|
I_ADC = Get_ConversionVal(get_adc(CHG_CURR));
|
|
|
|
|
// I_ADC = get_adc(CHG_CURR);
|
|
|
|
|
|
|
|
|
|
I = (float)(I_ADC) / 4095 * 3.3 * P_CHG_CURR;
|
|
|
|
|
|
2024-07-24 08:57:38 +00:00
|
|
|
|
// printf(" CHG_CURR I : %d /10000 \n", (int)(I * 10000));
|
2024-07-11 06:58:55 +00:00
|
|
|
|
#ifdef enable_Printf_VI
|
|
|
|
|
printf("\n CHG_CURR ADC : %d \n", I_ADC);
|
|
|
|
|
printf(" CHG_CURR I : %d /10000 \n", (int)(I * 10000));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return I;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
|
|
|
|
|
* @param
|
|
|
|
|
* @retval V <EFBFBD><EFBFBD>ѹֵ
|
|
|
|
|
*/
|
|
|
|
|
float get_PV_VOLT_OUT(void)
|
|
|
|
|
{
|
|
|
|
|
float V;
|
|
|
|
|
uint16_t V_ADC;
|
|
|
|
|
|
|
|
|
|
V_ADC = Get_ConversionVal(get_adc(PV_VOLT_OUT));
|
|
|
|
|
// V_ADC = get_adc(PV_VOLT_OUT);
|
|
|
|
|
|
|
|
|
|
V = (float)(V_ADC) / 4095 * 3.3 * P_PV_VOLT_OUT;
|
|
|
|
|
|
|
|
|
|
#ifdef enable_Printf_VI
|
|
|
|
|
printf("\n PV_VOLT_OUT ADC : %d \n", V_ADC);
|
|
|
|
|
printf(" PV_VOLT_OUT V : %d /100 \n", (int)(V * 100));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval I <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
*/
|
|
|
|
|
float get_DSG_CURR(void)
|
|
|
|
|
{
|
|
|
|
|
float I;
|
|
|
|
|
uint16_t I_ADC;
|
|
|
|
|
|
|
|
|
|
I_ADC = Get_ConversionVal(get_adc(DSG_CURR));
|
|
|
|
|
// I_ADC = get_adc(DSG_CURR);
|
|
|
|
|
|
|
|
|
|
I = (float)(I_ADC) / 4095 * 3.3 / P_DSG_CURR;
|
|
|
|
|
|
|
|
|
|
#ifdef enable_Printf_VI
|
|
|
|
|
printf("\n DSG_CURR ADC : %d \n", I_ADC);
|
|
|
|
|
printf(" DSG_CURR I : %d /100 \n", (int)(I * 100));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return I;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>ѹ
|
|
|
|
|
* @param
|
|
|
|
|
* @retval V <EFBFBD><EFBFBD>ѹֵ
|
|
|
|
|
*/
|
|
|
|
|
float get_PV1_VOLT_IN(void)
|
|
|
|
|
{
|
|
|
|
|
float V;
|
|
|
|
|
uint16_t V_ADC;
|
|
|
|
|
|
2024-07-22 06:20:24 +00:00
|
|
|
|
GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, SET);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
V_ADC = Get_ConversionVal(get_adc(PV1_VOLT_IN));
|
|
|
|
|
// V_ADC = get_adc(PV1_VOLT_IN);
|
2024-07-22 06:20:24 +00:00
|
|
|
|
GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, RESET);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
|
|
|
|
V = (float)(V_ADC) / 4095 * 3.3 * P_PV1_VOLT_IN;
|
|
|
|
|
|
|
|
|
|
#ifdef enable_Printf_VI
|
|
|
|
|
printf("\n PV1_VOLT_IN ADC : %d \n", V_ADC);
|
|
|
|
|
printf(" PV1_VOLT_IN V1 : %d /100 \n", (int)(V * 100));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD>ϵͳ<EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD>ѹ
|
|
|
|
|
* @param
|
|
|
|
|
* @retval V <EFBFBD><EFBFBD>ѹֵ
|
|
|
|
|
*/
|
|
|
|
|
float get_PV_VOLT_IN1(void)
|
|
|
|
|
{
|
|
|
|
|
float V;
|
|
|
|
|
uint16_t V_ADC;
|
|
|
|
|
|
|
|
|
|
V_ADC = Get_ConversionVal(get_adc(PV_VOLT_IN1));
|
|
|
|
|
// V_ADC = get_adc(PV_VOLT_IN1);
|
|
|
|
|
|
|
|
|
|
V = (float)(V_ADC) / 4095 * 3.3 * P_PV_VOLT_IN1;
|
|
|
|
|
|
|
|
|
|
#ifdef enable_Printf_VI
|
|
|
|
|
printf("\n PV_VOLT_IN1 ADC : %d \n", V_ADC);
|
|
|
|
|
printf(" PV_VOLT_IN1 V : %d /100 \n", (int)(V * 100));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const float Rp=10000.0; //10K
|
|
|
|
|
const float T2 = (273.15+25.0);;//T2
|
|
|
|
|
//const float Bx = 3950.0;//B
|
|
|
|
|
const float Bx = 3435.0;//B
|
|
|
|
|
const float Ka = 273.15;
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD><EFBFBD>¶<EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval V <EFBFBD><EFBFBD>ѹֵ
|
|
|
|
|
*/
|
|
|
|
|
float get_MOSFET_Temper(void)
|
|
|
|
|
{
|
|
|
|
|
float T;
|
|
|
|
|
uint16_t T_ADC;
|
|
|
|
|
|
|
|
|
|
T_ADC = Get_ConversionVal(get_adc(MOSFET_Temper));
|
|
|
|
|
// T_ADC = get_adc(MOSFET_Temper);
|
|
|
|
|
|
|
|
|
|
float V = (float)(T_ADC) / 4095 * 3.3;
|
|
|
|
|
float R = (float)(10 * V) / (3.3 - V);
|
|
|
|
|
|
|
|
|
|
T = R / Rp;
|
|
|
|
|
T = log(T);//ln(Rt/Rp)
|
|
|
|
|
T /= Bx;//ln(Rt/Rp)/B
|
|
|
|
|
T += (1.0 / T2);
|
|
|
|
|
T = 1.0 / (T);
|
|
|
|
|
T -= Ka;
|
|
|
|
|
|
|
|
|
|
// T = (float)(T_ADC) / 4095 * 3.3 * P_MOSFET_TEMPER;
|
|
|
|
|
|
|
|
|
|
#ifdef enable_Printf_VI
|
|
|
|
|
printf("\n MOSFET_Temper ADC : %d \n", T_ADC);
|
|
|
|
|
printf(" MOSFET_Temper T : %d /100 \n", (int)(T * 100));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>ѹ
|
|
|
|
|
* @param
|
|
|
|
|
* @retval V <EFBFBD><EFBFBD>ѹֵ
|
|
|
|
|
*/
|
|
|
|
|
float get_PV2_VOLT_IN(void)
|
|
|
|
|
{
|
|
|
|
|
float V;
|
|
|
|
|
uint16_t V_ADC;
|
|
|
|
|
|
2024-07-22 06:20:24 +00:00
|
|
|
|
GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, SET);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
V_ADC = Get_ConversionVal(get_adc(PV2_VOLT_IN));
|
|
|
|
|
// V_ADC = get_adc(PV2_VOLT_IN);
|
2024-07-22 06:20:24 +00:00
|
|
|
|
GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, RESET);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
|
|
|
|
V = (float)(V_ADC) / 4095 * 3.3 * P_PV2_VOLT_IN;
|
|
|
|
|
|
|
|
|
|
#ifdef enable_Printf_VI
|
|
|
|
|
printf("\n PV2_VOLT_IN ADC : %d \n", V_ADC);
|
|
|
|
|
printf(" PV2_VOLT_IN V : %d /100 \n", (int)(V * 100));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|