The BTUmeter Software Design Report

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@kissfirer·
0.000 HBD
The BTUmeter Software Design Report
Btu/hr is a British unit of heat, the full name is: BRITISH THERMAL UNIT/HOUR.

A unit for calculating heat used in Britain, the United States and other countries, abbreviated as Btu. It is equal to the heat required to raise the temperature of a pound of pure water by 1F (1 degree F = 5/9 degree C difference).

In the HVAC industry, it is often necessary to measure BTU. To calculate BTU, we need to measure temperature, relative humidity, wind speed, and then calculate BTU by formula.

Next, we will talk about the software design of a BTU instrument.

# BTUmeter Software Design Report

**Introduction:**

The software is divided 5 parts: signal of sensor process module, key operation, display module, advance function module and information flash module. 

Signal of sensor process module read the value of sensors and convert them to temperature, humidity and velocity; advance function module calculate dew point, wet bulb temperature, volume, BTU/H and so on; Key operation change the state word of system; information flash module is use to stores the parameters, e.g. RH-sensor calibrate information and configure state, they are not lost if the batteries are change.

Signal of sensor process module includes temperature.c, humidity.c, velocity.c, temperature.h, humidity.h, velocity.h; display module includes ht1621.c, ht1621.h; advance function module includes advance_function.c, advance_function.h; information flash module includes info_mem.c, info_mem.h. 

interrupt.c includes key scan, timer counter, read frequency. The main routine is btu.c.

**Module Diagram:**

In the all follow state chart, the word in "  " is the content of display in LCD. Keypads are in red. At any mode press ON is power off
![image](https://ipfs.busy.org/ipfs/QmZtNuttWJfeUAtwtZAtfPjH2Px2JEwEGDrodXbdzvD8vV)

MODE key pressed < 0.5S,jump to next mode; MODE key pressed > 0.5S,the mode jumped one by one, as follow Figure2.
![image](https://ipfs.busy.org/ipfs/QmNpZaj7KuFsJe8hQ7yPxnwVpagRmGrqs8ryz6jVmYhuob)

**Detailed Spec:**

The software is interrupt driven by a recurring 20ms interrupt. The capture/compare register CCR0 data define the timer period: 20ms, operation in time-up mode. All others time interval (e.g. time_20s_count, time_10min_count, and so on) uses this 20ms interrupt as basic timer. If the allow-count bit is set, when the 20ms interrupt occurs, the corresponding counter increase one number. When the value of count reach the TIME_***_COUNT_MAX, corresponding flag bit will be set. 
Example:

![image](https://ipfs.busy.org/ipfs/QmYYyMv1a1o1aKS6Sco27GMxUGVoZEdSeFgPgUAaQ8fBQo)
NOTE: the words of program display by format “time_20s_count” in this report.

- Main routine:

Main routine includes two parts mainly: state word change process module and detail process according to different state word module.
State word change process module includes follow subroutines:

*key_poweroff( );
key_mode_change( );
key_exchange_TempandDewpointmode( );
key_exchange_HumiandWbt( );
key_capacity_process( );
key_volume_process( );
key_CalibrateandConfiguemode_process( );*

Detail process module includes follow subroutines:

*poweroff_extend_mode_process( );
temperature_extend_mode_process( );
humidity_extend_mode_process( );
velocity_mode_process( );
volume_mode_process( );
capacity_mode_process( );*

Main routine calls the subroutines in sequence and cycle. Furthermore, clear watchdog and update display were called in main routine.
The flow chart of key_capacity_process( ) and key_volume_process( ) refer to appendix.

- Signal of sensor process module:

The frequencies of temperature and humidity are capturing by CCR1 and CCR2 of TIME_A. The clock of TIME_A is 2MHz.
Capture/Compare Blocks CCR1 of TIME_B reads the frequency of velocity. The clock of TIME_A is 250kHz.

- Information flash module:

SegmentB was used to store gv_unit_Flag(The length is byte, type is uchar). it is sign of configure mode. SegmentA was used to store RH-sensor calibrate information, Zcal, Scal (length is four byte, type is float), TEMP_COEFFICIENT_OF_RH (length is two byte, type is uint). 
So the module includes follow subroutines: 

*void FlashWriteInt(uint *addr, uint data);
void FlashWriteUchar(uchar *addr, uchar data);
void FlashWriteFloat(uint *addr,float data);*


- Key operation:

Key scans interval use 20ms. The flow chart as follow Figure3:
![image](https://ipfs.busy.org/ipfs/QmXdzm3pqE2dZZJTQ7FaLPJAg1SRJ2Mr4tqfWbLAyVxMQd)
*Figure3. Key scan flow chart*

BTUmeter have three long press key modes, one is two seconds (for ON/OFF key, press time less than 2 seconds to power on, else to configure mode), second is 0.5 second (for MODE key). So need a count for judge press key time: **key_count**. 

Third mode is in *set_outlet_size ( )*. When set size of outlet, the value of size increase/decrease rate is different according to different key-press time. The detail refer to the note of void *set_outlet_size(long outlet_size)*. This needs *long_key and long_key_count*.

- Advance function module:

## a.Calculate dew point temperature:
ⅰ. Calculate saturation pressure of the air stream at ambient temperature from ambient temperature, the unit is kPa.

temp_satur_pressure = COEFFICIENT_A
*exp(COEFFICIENT_B*t/(COEFFICIENT_C+ gv_Temperature)) 

ⅱ. Calculate saturation pressure of the air stream at the dew point temperature from ambient humidity:

vapor_pressure = temp_satur_pressure * gv_Humidity / 100 

ⅲ. Calculate dew point use follow formula:

gv_Dewpoint = COEFFICIENT_C
/(COEFFICIENT_B/log(vapor_pressure/COEFFICIENT_A)-1)
 
From the above equations:
COEFFICIENT_A = 0.61121
COEFFICIENT_B = 17.502
COEFFICIENT_C = 240.97

void dewpoint_calculate(float t,float rh) perform above function, unit is °C 

## b.Calculate wet bulb temperature:
ⅰ. The first step is to calculate the saturation vapor pressure and dew point vapor pressure, the unit is mBar.
ⅱ. A first guess at the wet bulb temperature is calculated, the unit of temperature is KELVIN.

intermediate_coef = ( actual_temp_satur_pressure
 - dewpoint_temp_satur_pressure)/(_gv_Temperature - _dewpoint)

wbt_temp = (_gv_Temperature * fp + _dewpoint * intermediate_coef)/(fp 
+ intermediate_coef)

ⅲ. With a given guess of the wet bulb temperature, an attempt is made to do an energy balance. The difference (de) between the quantities below are examined:

difference_wbt_dbt = fp * (_gv_Temperature - wbt_temp) 
- (wbt_temp_satur_pressure - dewpoint_temp_satur_pressure)
When the difference between these is less than one part in 10,000 of the wet bulb vapor pressure, the looping calculation stops. Otherwise, a new guess at the wet-bulb temperature is calculated based on the difference found, and the loop is repeated. The new guess is found by taking the derivative (der) of the difference (de) with respect to the wet bulb temperature, which is fairly standard numerical technique for finding the zero value of a function.

difference_wbt_dbt_repeat = wbt_temp_satur_pressure * 
(WBT_COEFFICIENT_1-WBT_COEFFICIENT_2/(wbt_temp*wbt_temp))-fp

Next guess of wet bulb temperature:

**wbt_temp -= difference_wbt_dbt/difference_wbt_dbt_repeat**

The new wet bulb temperature is again tested. Up to ten iterations of the loop can be performed before a final value is returned.
From the above equations:
fp = COEFFICIENT_F * ATM_M_UNIT * 10, unit is mBar
( COEFFICIENT_F = 0.0006355
ATM_M_UNIT = 101.325      )
WBT_COEFFICIENT_1 = 0.0091379024
WBT_COEFFICIENT_2 = 6106.396

void wet_bulb_temperature(void) perform calculate wet bulb temperature function, unit is °C

## c.Calculate air volume:
float air_volume_calculate(uint length,uint width,float velocity) perform this function, the unit in consonance with gv_uint_Flag, when gv_uint_Flag  == ENGLISH_UNITS, unit is CFM, when gv_uint_Flag  == METRIC_UNITS, unit is M3/S. 

## d.Calculate heat capacity (BTU/H):
float heat_capacity_calculate(float inlet_temp,float inlet_rh,float outlet_temp,float outlet_rh,float velocity) perform this function, detail refer to BTUH EXAMPLE:

ⅰ. Given at measurement location 1 (conditions inside room):
dry bulb temperature t1 = 76 °F     %RH1 = 49.0% 
barometric pressure = 29.921 in. Hg

ⅱ. Given at measurement location 2 (conditions of supply air entering room):
dry bulb temperature t2 = 53 °F   %RH2 = 88.0% 
flow rate q = 15,000 std ft3/min

ⅲ. Find: sensible heat flow QS, latent heat flow QL, total heat flow QT, and sensible heat factor SHF.
Sensible heat flow QS:
QS = 1.0746qDt = 1.0746 (15000)(|53-76|) = 370,737 Btu/h of heat removal

**Latent heat flow QL:**
QL = 4770qDW , so we need to find W1 and W2.
W = 0.62198pws(td)/(29.921 - pws(td))
pws(td) = %RH1*(pws(t))
Definitions of terms used to calculate W:
pws(td) = saturation pressure of the airstream at the dew point temperature (inches Hg)
pws(t) = saturation pressure of the airstream at ambient temperature (inches Hg)
***
**To find W1:**
pws(t1) = pws(76 °F) = 0.90532 in. Hg 
pws(td1) = %RH1(pws(t1)) = (0.490)(0.90532) = 0.4436068
W1=0.62198pws(td1)/(29.921-pws(td1))=0.62198(0.4436068)/
(29.921 - 0.4436068)=  0.00936021 lb H2O/lb dry air
***
**To find W2:**
pws(t2) = pws(53 °F) = 0.40516 in. Hg 
pws(td2) = %RH2*(pws(t2)) = (0.880)(0.40516) = 0.3565408
W2=0.62198pws(td2)/(29.921-pws(td2))=0.62198(0.3565408)/
(29.921 - 0.3565408)  =  0.00750094 lb H2O/lb dry air
***
**To find QL:**
QL =  4770Qdw =  4770(15,000)(|0.00750094 - 0.00936021|)
= 133,031 Btu/h heat removed
***
**Total heat flow QT**
QT = QS + QL = 370,737 + 133,031 = 503,768 Btu/h heat removed
***
**Sensible Heat Factor SHF**
SHF = QS/QT = 370,737/503,768 = 0.74
The pws(t) and W that are being used in these equations are the same W that is calculated when finding the wet bulb temperature.

Appendix

- Flow chart of measure volume:
![image](https://ipfs.busy.org/ipfs/QmexoXugMwXYNDGrkVC43zkNCpWP9yRQvvMtvk5vdzU5p1)

- Flow chart of measure BTU/H:
![image](https://ipfs.busy.org/ipfs/QmTgemdCkJi14fAroFn3f8aXabRraaL5kZwN5chJaZpf9t)

**This is a real design, designed more than a decade ago, the shipment volume is stable.** <br /><center><hr/><em>Posted from my blog with <a href='https://wordpress.org/plugins/steempress/'>SteemPress</a> : https://kissfirer.000webhostapp.com/the-btumeter-software-design-report </em><hr/></center>         
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,