Skip to content

Commit

Permalink
firmware: app: tasks: read_sensors: Adding a delay between every sens…
Browse files Browse the repository at this point in the history
…or reading #89
  • Loading branch information
mgm8 committed Nov 27, 2021
1 parent bc8591e commit 90498d7
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 42 deletions.
140 changes: 99 additions & 41 deletions firmware/app/tasks/read_sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* \{
*/

#include <system/sys_log/sys_log.h>

#include <devices/current_sensor/current_sensor.h>
#include <devices/voltage_sensor/voltage_sensor.h>
#include <devices/temp_sensor/temp_sensor.h>
Expand All @@ -56,184 +58,240 @@ void vTaskReadSensors(void)
{
TickType_t last_cycle = xTaskGetTickCount();

sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_SENSORS_NAME, "Reading sensors...");
sys_log_new_line();

uint16_t buf = 0U;

/* -Y Solar Panel current in mA.*/
if (current_sensor_read(PANNEL_MINUS_Y_CURRENT_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_MY_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_MY_CURRENT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* +X Solar Panel current in mA.*/
if (current_sensor_read(PANNEL_PLUS_X_CURRENT_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_PX_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_PX_CURRENT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* -X Solar Panel current in mA.*/
if (current_sensor_read(PANNEL_MINUS_X_CURRENT_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_MX_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_MX_CURRENT, (uint32_t*)&buf);
}


vTaskDelay(pdMS_TO_TICKS(50));

/* +Z Solar Panel current in mA.*/
if (current_sensor_read(PANNEL_PLUS_Z_CURRENT_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_PZ_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_PZ_CURRENT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* -Z Solar Panel current in mA.*/
if (current_sensor_read(PANNEL_MINUS_Z_CURRENT_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_MZ_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_MZ_CURRENT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* +Y Solar Panel current in mA.*/
if (current_sensor_read(PANNEL_PLUS_Y_CURRENT_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_PY_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_PY_CURRENT, (uint32_t*)&buf);
}


vTaskDelay(pdMS_TO_TICKS(50));

/* -Y and +X Solar Panels voltage in mV.*/
if (voltage_sensor_read(PANNELS_MINUS_Y_PLUS_X_VOLTAGE_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_MY_PX_VOLTAGE, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_MY_PX_VOLTAGE, (uint32_t*)&buf);
}


vTaskDelay(pdMS_TO_TICKS(50));

/* -X and +Z Solar Panels voltage in mV.*/
if (voltage_sensor_read(PANNELS_MINUS_X_PLUS_Z_VOLTAGE_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_MX_PZ_VOLTAGE, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_MX_PZ_VOLTAGE, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* -Z and +Y Solar Panels voltage in mV.*/
if (voltage_sensor_read(PANNELS_MINUS_Z_PLUS_Y_VOLTAGE_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_MZ_PY_VOLTAGE, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_MZ_PY_VOLTAGE, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* Total solar panels output voltage after MPPT in mV.*/
if (voltage_sensor_read(TOTAL_SOLAR_PANNELS_VOLTAGE_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_SP_VOLTAGE_MPPT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_SP_VOLTAGE_MPPT, (uint32_t*)&buf);
}


vTaskDelay(pdMS_TO_TICKS(50));

/* Main power bus voltage in mV.*/
if (voltage_sensor_read(MAIN_POWER_BUS_VOLTAGE_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_MAIN_POWER_BUS_VOLTAGE, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_MAIN_POWER_BUS_VOLTAGE, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* EPS and TTC circuitry current in mA.*/
if (current_sensor_read(EPS_BEACON_CURRENT_SENSOR_ADC_PORT, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_EPS_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_EPS_CURRENT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(5));
vTaskDelay(pdMS_TO_TICKS(50));

/* RTD 0 temperature. */
if (temp_rtd_read_k(TEMP_SENSOR_RTD_CH_0, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_RTD_0_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_RTD_0_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* RTD 1 temperature. */
if (temp_rtd_read_k(TEMP_SENSOR_RTD_CH_1, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_RTD_1_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_RTD_1_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* RTD 2 temperature. */
if (temp_rtd_read_k(TEMP_SENSOR_RTD_CH_2, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_RTD_2_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_RTD_2_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* RTD 3 temperature. */
if (temp_rtd_read_k(TEMP_SENSOR_RTD_CH_3, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_RTD_3_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_RTD_3_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* RTD 4 temperature. */
if (temp_rtd_read_k(TEMP_SENSOR_RTD_CH_4, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_RTD_4_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_RTD_4_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* RTD 5 temperature. */
if (temp_rtd_read_k(TEMP_SENSOR_RTD_CH_5, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_RTD_5_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_RTD_5_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* RTD 6 temperature. */
if (temp_rtd_read_k(TEMP_SENSOR_RTD_CH_6, &buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_RTD_6_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_RTD_6_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(5));
vTaskDelay(pdMS_TO_TICKS(50));

/* Battery monitor voltage.*/
if (bm_get_voltage(&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_VOLTAGE, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_VOLTAGE, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* Battery monitor CI temperature.*/
if (bm_get_temperature_kelvin(&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_TEMP, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_TEMP, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* Battery monitor current.*/
if (bm_get_instantaneous_current((int16_t *)&buf) == 0)
if (bm_get_instantaneous_current((int16_t*)&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_CURRENT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* Battery monitor average current.*/
if (bm_get_average_current((int16_t *)&buf) == 0)
if (bm_get_average_current((int16_t*)&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_AVERAGE_CURRENT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_AVERAGE_CURRENT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* Battery monitor status register.*/
if (bm_get_status_register_data((uint8_t *)&buf) == 0)
if (bm_get_status_register_data((uint8_t*)&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_STATUS, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_STATUS, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

/* Battery monitor protection register.*/
if (bm_get_protection_register_data((uint8_t *)&buf) == 0)
if (bm_get_protection_register_data((uint8_t*)&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_PROTECT, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_PROTECT, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

if (bm_get_raac_mah(&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RAAC, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RAAC, (uint32_t*)&buf);
}

vTaskDelay(pdMS_TO_TICKS(50));

if (bm_get_rsac_mah(&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RSAC, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RSAC, (uint32_t*)&buf);
}

if (bm_get_rarc_percent((uint8_t *)&buf) == 0)
vTaskDelay(pdMS_TO_TICKS(50));

if (bm_get_rarc_percent((uint8_t*)&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RARC, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RARC, (uint32_t*)&buf);
}

if (bm_get_rsrc_percent((uint8_t *)&buf) == 0)
vTaskDelay(pdMS_TO_TICKS(50));

if (bm_get_rsrc_percent((uint8_t*)&buf) == 0)
{
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RSRC, (uint32_t *)&buf);
eps_buffer_write(EPS2_PARAM_ID_BAT_MONITOR_RSRC, (uint32_t*)&buf);
}

/* Data timestamp */
uint32_t time_counter = (uint32_t)xTaskGetTickCount();

eps_buffer_write(EPS2_PARAM_ID_TIME_COUNTER, &time_counter);

vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_READ_SENSORS_PERIOD_MS));
Expand Down
2 changes: 1 addition & 1 deletion firmware/app/tasks/read_sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <task.h>

#define TASK_READ_SENSORS_NAME "Read Sensors" /**< Task name. */
#define TASK_READ_SENSORS_STACK_SIZE 128 /**< Stack size in bytes. */
#define TASK_READ_SENSORS_STACK_SIZE 512 /**< Stack size in bytes. */
#define TASK_READ_SENSORS_PRIORITY 2 /**< Task priority. */
#define TASK_READ_SENSORS_PERIOD_MS (60*1000) /**< Task period in milliseconds. */
#define TASK_READ_SENSORS_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */
Expand Down

0 comments on commit 90498d7

Please sign in to comment.