gas sensor

gas sensor

Search This Blog

Sunday, January 31, 2010

part 3
Algorithm
The code runs under freeRTOS environment (http://www.freertos.org/ ) and contains three major tasks, see Figure 5.


Figure 5: block diagram



High task
High task is responsible for analog reading, copying parameters changes from parameters shadow to working parameters and handling errors

Analog reading – is done every 100 msec and stored in ADC queue at depth of 11 places, the medium task is responsible for handling those values. In case that it takes the medium task a long time to process , the queue keeps storing those ADC for future handling.

Parameters copy- the low tasks may receive parameters changes through the XBee model, in this case they are stored in shadow parameters and will be copied at once in high task. Parameters are also copied to flash memory so in the next reset they are read and used.

Errors check – two kinds of error checks are done in high priority task.

1.Critical errors; which include task switch error (like tasks taking too long) and queue overrun. When critical error is detected ,the MCU turn on the “alive led” (will stop flashing) and enter infinity loop, after writing critical error message to flash. In next reset this critical message will be read and transmitted to the user. (other methods for handling critical errors can be programed like reset/switch off/buzzer/WD)

2.Non Critical errors; which include buffer over run. This happens when buffer is not asked to transmit and it is needed for new ADC data (the other buffer was last filled), message over run, when message do not have any more space in buffer, and more. When non critical message is detected the MCU continues to work normally but it sends non-critical message to the user and stores it in flash for message after reset.

Medium task
Medium task is responsible for storing the ADC data from the ADC queue to the double buffer, storing message data from message queue to the double buffer and running an algorithm over the ADC data.

Storing ADC and messages data - see figure 6, the task reads the ADC values and messages from the relevant queues and puts them in the next available space in the buffer. The buffer is at length of MAX_LENGTH and has first section of known size storing ADC values and second section with changeable size as function of messages that were collected all over the code and will be transmitted to the user. Only the real needed size is transmitted saving air traffic (not the MAX_LENGTH but ADC length+ messages length). When the fix size ADC area in the buffer is full it is marked as ready to be transmitted, if data request is coming from the user, the ready to send buffer is transmitted.

Figure 6: buffers diagram

Algorithm - this is a specific algorithm for the gas detector board, it works as a stand alone without any need for XBee or the user and can be changed as required. Each channel (different sensor) runs the algorithm separately from any other channel.
It uses user defined thresholds with time window following it, see figure 7.

Description of figure 7:

  • Below up threshold – all OK.
  • Passing up threshold – open time window and light threshold led.
  • Above down threshold after up threshold and time window passed – hazard case, light critical led and start buzzer
  • Below down threshold - close all hazards


Figure 7: algorithm diagram

Low task
Low task is responsible for the flash alive led and telemetry function.
The telemetry function receives and sends data from MCU to XBee.
Each sequence starts with receiving command from GUI-->GUI XBee-->board XBee->MCU.


  • PARAMS_IN command is a user request for parameters values from MCU, this will be followed by the transmission of parameters from MCU to GUI.
  • PARAMS_OUT command is a user request to update parameters, this will be followed by the receiving of parameters from GUI to MCU.
  • PARAMS_RESET command is a user request to reset parameters from hard-coded defined values.
  • DATA_IN command is a user request for the next available full data buffer, this will be followed by the full data buffer transmission (if available) from MCU to GUI.
  • DATA_ECHO command is for debug echoing data. Echo any following input back to XBee.
  • DEBUG command is for task debug, it will send tasks entering and exiting time array, see the next section

No comments:

Post a Comment