The Code is implemented in accordens to the requirments given in the  function description. Quickly summerized it describes the following,

  • Survey and report the temperature
  • Sound  an alarm after 30 mintues if the temperature deviates more than +-1C away from the setpoint.
  • In case of an alarm, turn on fans to ensure a well ventilated facility


The Code for the Temperature sensor is based on its technical data (Bosch, 2024), where 0v = -45C  which linearly scales to 10v = 80C. This means that linear interpolation is utilized to scale the input voltage too an output in celsius.


Linear interpolation is performed with the following function (Chapra and Canale, 2015),


This means that the inputs needs to be,

  • sensor_reading:REAL;
  • set_point_in_c:REAL;
  • alarm_delay:TIME;
  • max_temp:REAL;
  • max_temp_in_volts:REAL;
  • min_temp:REAL;
  • min_temp_in_volts:REAL;


And the outputs needs to be,

  • temp_read_in_c:REAL;
  • alarm_high:BOOL;
  • alarm_low:BOOL;


With the following internal variables,

  • alarm_since_trig:TIME;
  • alarm_high_trig:BOOL;
  • alarm_low_trig:BOOL;
  • alarm_high_trig_0:BOOL;
  • alarm_low_trig_0:BOOL;


The coded implementation looks like this,


Which gives the following function block,


References:


Chapra, S.C. and Canale, R.P. (2015). Numerical Methods for Engineers. 7th ed. New York: McGraw-Hill Education. [pdf] Available at: https://gdcboysang.ac.in/About/Droid/uploads/Numerical%20Methods.pdf (Accessed: 28 May 2024).

Bosch. (2024). BME688: Digital low power gas, pressure, temperature & humidity sensor with AI. [pdf] February 2024, Document revision 1.3. Available at: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme688-ds000.pdf (Accessed: 28 May 2024).


  • No labels