69 lines
1.3 KiB
C
69 lines
1.3 KiB
C
|
|
#include "../main/SystemInclude.h"
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
u16 AirflowSensor_Read(void)
|
|||
|
|
{
|
|||
|
|
u8 raw_data[2] = {0};
|
|||
|
|
|
|||
|
|
SI2C_Start();
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>Ͷ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EEA3A8>ַ + <20><>ģʽ<C4A3><CABD>
|
|||
|
|
SI2C_Write((HAF_ADR << 1) | 0x01);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ2<C8A1>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
// <20><><EFBFBD>ݸ<EFBFBD>ʽ<EFBFBD><CABD>[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8λ, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8λ]
|
|||
|
|
raw_data[0] = SI2C_Read();
|
|||
|
|
SI2C_Ack(); // <20><><EFBFBD><EFBFBD>ACK<43><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
|
|||
|
|
raw_data[1] = SI2C_Read();
|
|||
|
|
SI2C_NoAck();// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڷ<D6BD><DAB7><EFBFBD>NACK
|
|||
|
|
SI2C_Stop();
|
|||
|
|
|
|||
|
|
// <20>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>16λ<36><CEBB>
|
|||
|
|
u16 flow_raw =((raw_data[0] << 8) | raw_data[1]) ;
|
|||
|
|
|
|||
|
|
return flow_raw ;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ȡƽ<C8A1><C6BD>ֵ
|
|||
|
|
u16 AirflowSensor_ReadAverage(u8 count)
|
|||
|
|
{
|
|||
|
|
u8 valid_count = 0;
|
|||
|
|
u32 total_flow = 0;
|
|||
|
|
if (count <= 0) return 0;
|
|||
|
|
for (uint8_t i = 0; i < count; i++)
|
|||
|
|
{
|
|||
|
|
total_flow += AirflowSensor_Read();
|
|||
|
|
valid_count++;
|
|||
|
|
delay_ms(10);
|
|||
|
|
}
|
|||
|
|
if (valid_count > 0) {
|
|||
|
|
total_flow= total_flow / valid_count;
|
|||
|
|
}
|
|||
|
|
return total_flow;
|
|||
|
|
}
|
|||
|
|
// ת<><D7AA><EFBFBD><EFBFBD>SCCM
|
|||
|
|
#define MaximumFlow 750 //SCCM
|
|||
|
|
float Get_AirflowSensor_SCCM(void)
|
|||
|
|
{
|
|||
|
|
u16 total_flow = 0;
|
|||
|
|
float slpm_flow;
|
|||
|
|
total_flow = AirflowSensor_ReadAverage(10);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>10<31>ε<EFBFBD>ƽ<EFBFBD><C6BD>ֵ
|
|||
|
|
|
|||
|
|
if(total_flow > 8192)slpm_flow = (total_flow-8192)*MaximumFlow;
|
|||
|
|
else slpm_flow = (total_flow+8192)*MaximumFlow;
|
|||
|
|
|
|||
|
|
slpm_flow = slpm_flow/ 8192;
|
|||
|
|
return slpm_flow;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|