Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u --- firmware/App/Controllers/LoadCell.c (revision 0) +++ firmware/App/Controllers/LoadCell.c (revision bcd2887a992f73548dc0d9603595b57523b31902) @@ -0,0 +1,78 @@ +/**********************************************************************//** + * + * Copyright (c) 2020 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file LoadCell.c + * + * @date 25-Feb-2020 + * @author S. Nejatali + * + * @brief Processing sensor data. + * + **************************************************************************/ + +#include "LoadCell.h" +#include "Common.h" +#include "SystemCommMessages.h" +#include "FPGA.h" +#include "TaskPriority.h" + + /**@}*/ + +/*********************************************************************//** + * @brief + * The execLoadCell function gets load cell data from FPGA and advertises them over CAN. + * @details + * Inputs : none + * Outputs : Advertising load call data. + * @return none + *************************************************************************/ +void execLoadCell(void) +{ +#ifdef DEBUG_ENABLED + char debugStr[ 256 ]; +#endif + static U32 Counter = 0; + static U32 Load_cell_a1 = 0; + static U32 Load_cell_a2 = 0; + static U32 Load_cell_b1 = 0; + static U32 Load_cell_b2 = 0; + F32 load_cell_a1_f; + F32 load_cell_a2_f; + F32 load_cell_b1_f; + F32 load_cell_b2_f; + BOOL result; + + Load_cell_a1 += getFPGALoadCellA1(); // No overflow since ADC output is 24 bits. + Load_cell_a2 += getFPGALoadCellA2(); + Load_cell_b1 += getFPGALoadCellB1(); + Load_cell_b2 += getFPGALoadCellB2(); + + Counter++; + if (Counter == LOAD_CELL_REPORT_PERIOD) + { + Counter = 0; + + load_cell_a1_f = (F32)(Load_cell_a1)*ADC2GRAM; // division for averaging folded into ADC2GRAM + load_cell_a2_f = (F32)(Load_cell_a2)*ADC2GRAM; + load_cell_b1_f = (F32)(Load_cell_b1)*ADC2GRAM; + load_cell_b2_f = (F32)(Load_cell_b2)*ADC2GRAM; + result = broadcastLoadCellData( load_cell_a1_f, load_cell_a2_f, load_cell_b1_f, load_cell_b2_f ); +#ifdef DEBUG_ENABLED + if (result == FALSE) + sprintf( debugStr, "Adding load cell data to CAN buffer failed" ); +#else + (void)result; +#endif + Load_cell_a1 = 0; + Load_cell_a2 = 0; + Load_cell_b1 = 0; + Load_cell_b2 = 0; + } +} + + + Index: firmware/App/Controllers/LoadCell.h =================================================================== diff -u --- firmware/App/Controllers/LoadCell.h (revision 0) +++ firmware/App/Controllers/LoadCell.h (revision bcd2887a992f73548dc0d9603595b57523b31902) @@ -0,0 +1,27 @@ +/**********************************************************************//** + * + * Copyright (c) 2020 Diality Inc. - All Rights Reserved. + * + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * @file LoadCell.h + * + * @date 25-Feb-2020 + * @author S. Nejatali + * + * @brief Processing sensor data. + * + **************************************************************************/ + +#ifndef APP_CONTROLLERS_LOADCELL_H_ +#define APP_CONTROLLERS_LOADCELL_H_ + +void execLoadCell(void); + +#define LOAD_CELL_REPORT_PERIOD 100/TASK_PRIORITY_INTERVAL // Send a load cell value CAN message to HD every 100 ms +#define LOAD_CELL_SAMPLES_TO_AVERAGE LOAD_CELL_REPORT_PERIOD // Averaging load cell data over the reporting interval +#define ADC2GRAM 0.0894/LOAD_CELL_SAMPLES_TO_AVERAGE // division for averaging is folded into this value + + +#endif /* APP_CONTROLLERS_LOADCELL_H_ */