MicroForce Sensors, Compensated/Amplified

Committer:
mcm
Date:
Wed Jun 30 12:54:49 2021 +0000
Revision:
0:e4146617a5fc
Child:
1:4b8a700b3f5c
The header file is ready to be tested.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 0:e4146617a5fc 1 /**
mcm 0:e4146617a5fc 2 * @brief MicroForce_FMA.h
mcm 0:e4146617a5fc 3 * @details MicroForce Sensors, Compensated/Amplified.
mcm 0:e4146617a5fc 4 * Header file.
mcm 0:e4146617a5fc 5 *
mcm 0:e4146617a5fc 6 *
mcm 0:e4146617a5fc 7 * @return N/A
mcm 0:e4146617a5fc 8 *
mcm 0:e4146617a5fc 9 * @author Manuel Caballero
mcm 0:e4146617a5fc 10 * @date 29/June/2021
mcm 0:e4146617a5fc 11 * @version 29/June/2021 The ORIGIN
mcm 0:e4146617a5fc 12 * @pre N/A.
mcm 0:e4146617a5fc 13 * @warning N/A
mcm 0:e4146617a5fc 14 * @pre This code belongs to Nimbus Centre ( https://www.nimbus.cit.ie ).
mcm 0:e4146617a5fc 15 */
mcm 0:e4146617a5fc 16 #ifndef MicroForce_FMA_H
mcm 0:e4146617a5fc 17 #define MicroForce_FMA_H
mcm 0:e4146617a5fc 18
mcm 0:e4146617a5fc 19 #include "mbed.h"
mcm 0:e4146617a5fc 20 /**
mcm 0:e4146617a5fc 21 Example:
mcm 0:e4146617a5fc 22 @code
mcm 0:e4146617a5fc 23
mcm 0:e4146617a5fc 24 @endcode
mcm 0:e4146617a5fc 25 */
mcm 0:e4146617a5fc 26
mcm 0:e4146617a5fc 27
mcm 0:e4146617a5fc 28 /*!
mcm 0:e4146617a5fc 29 Library for the MicroForce_FMA. MicroForce Sensors, Compensated/Amplified.
mcm 0:e4146617a5fc 30 */
mcm 0:e4146617a5fc 31 class MicroForce_FMA
mcm 0:e4146617a5fc 32 {
mcm 0:e4146617a5fc 33 public:
mcm 0:e4146617a5fc 34 /**
mcm 0:e4146617a5fc 35 * @brief STATUS BITS
mcm 0:e4146617a5fc 36 */
mcm 0:e4146617a5fc 37 typedef enum {
mcm 0:e4146617a5fc 38 MicroForce_FMA_STATUS_BITS_MASK = ( 0b11 << 6 ), /*!< STATUS BITS mask */
mcm 0:e4146617a5fc 39 MicroForce_FMA_STATUS_BITS_NORMAL_OPERATION = ( 0b00 << 6 ), /*!< Normal operation, valid data */
mcm 0:e4146617a5fc 40 MicroForce_FMA_STATUS_BITS_DEVICE_IN_COMMAND_MODE = ( 0b01 << 6 ), /*!< Device in command mode */
mcm 0:e4146617a5fc 41 MicroForce_FMA_STATUS_BITS_STALE_DATA = ( 0b10 << 6 ), /*!< Stale data */
mcm 0:e4146617a5fc 42 MicroForce_FMA_STATUS_BITS_DIAGNOSTIC_CONDITION = ( 0b11 << 6 ) /*!< Diagnostic condition */
mcm 0:e4146617a5fc 43 } MicroForce_FMA_status_bits_t;
mcm 0:e4146617a5fc 44
mcm 0:e4146617a5fc 45
mcm 0:e4146617a5fc 46 /**
mcm 0:e4146617a5fc 47 * @brief TRANSFER FUCNTION
mcm 0:e4146617a5fc 48 */
mcm 0:e4146617a5fc 49 typedef enum {
mcm 0:e4146617a5fc 50 MicroForce_FMA_TRANSFER_FUNCTION_10_TO_90 = 0U, /*!< Tranfer function A: 10% to 90% */
mcm 0:e4146617a5fc 51 MicroForce_FMA_TRANSFER_FUNCTION_20_TO_80 = 1U /*!< Tranfer function C: 20% to 80% */
mcm 0:e4146617a5fc 52 } MicroForce_FMA_transfer_function_t;
mcm 0:e4146617a5fc 53
mcm 0:e4146617a5fc 54
mcm 0:e4146617a5fc 55 /**
mcm 0:e4146617a5fc 56 * @brief FORCE RANGE
mcm 0:e4146617a5fc 57 */
mcm 0:e4146617a5fc 58 const FMA_FORCE_RANGE_5_N = 5U; /*!< Force range: 5N */
mcm 0:e4146617a5fc 59 const FMA_FORCE_RANGE_15_N = 15U; /*!< Force range: 15N */
mcm 0:e4146617a5fc 60 const FMA_FORCE_RANGE_25_N = 25U; /*!< Force range: 25N */
mcm 0:e4146617a5fc 61
mcm 0:e4146617a5fc 62
mcm 0:e4146617a5fc 63
mcm 0:e4146617a5fc 64 #ifndef MicroForce_FMA_STRUCT_H
mcm 0:e4146617a5fc 65 #define MicroForce_FMA_STRUCT_H
mcm 0:e4146617a5fc 66 typedef struct {
mcm 0:e4146617a5fc 67 MicroForce_FMA_status_bits_t status_bits;
mcm 0:e4146617a5fc 68 } MicroForce_FMA_status_bits_data_t;
mcm 0:e4146617a5fc 69
mcm 0:e4146617a5fc 70
mcm 0:e4146617a5fc 71 typedef struct {
mcm 0:e4146617a5fc 72 uint16_t raw_bridge_data;
mcm 0:e4146617a5fc 73 float bridge_data; /*!< Force data in Newton (N) */
mcm 0:e4146617a5fc 74 } MicroForce_FMA_bridge_data_t;
mcm 0:e4146617a5fc 75
mcm 0:e4146617a5fc 76
mcm 0:e4146617a5fc 77 typedef struct {
mcm 0:e4146617a5fc 78 uint8_t raw_8bit_temperature;
mcm 0:e4146617a5fc 79 uint16_t raw_11bit_temperature;
mcm 0:e4146617a5fc 80 float temperature_data; /*!< Temperature data in Celsius degree */
mcm 0:e4146617a5fc 81 } MicroForce_FMA_temperature_data_t;
mcm 0:e4146617a5fc 82
mcm 0:e4146617a5fc 83
mcm 0:e4146617a5fc 84 /* User's data */
mcm 0:e4146617a5fc 85 typedef struct {
mcm 0:e4146617a5fc 86 MicroForce_FMA_transfer_function_t transfer_function; /*!< Transfer function. Calibration */
mcm 0:e4146617a5fc 87 uint8_t force_range; /*!< Force Range */
mcm 0:e4146617a5fc 88
mcm 0:e4146617a5fc 89 MicroForce_FMA_status_bits_data_t status; /*!< Status bits. Device condition */
mcm 0:e4146617a5fc 90
mcm 0:e4146617a5fc 91 MicroForce_FMA_bridge_data_t force; /*!< Force data */
mcm 0:e4146617a5fc 92 MicroForce_FMA_temperature_data_t temperature; /*!< Temperature data */
mcm 0:e4146617a5fc 93 } MicroForce_FMA_data_t;
mcm 0:e4146617a5fc 94 #endif
mcm 0:e4146617a5fc 95
mcm 0:e4146617a5fc 96
mcm 0:e4146617a5fc 97
mcm 0:e4146617a5fc 98 /**
mcm 0:e4146617a5fc 99 * @brief INTERNAL CONSTANTS
mcm 0:e4146617a5fc 100 */
mcm 0:e4146617a5fc 101 typedef enum {
mcm 0:e4146617a5fc 102 MicroForce_FMA_SUCCESS = 0,
mcm 0:e4146617a5fc 103 MicroForce_FMA_FAILURE = 1,
mcm 0:e4146617a5fc 104 SPI_SUCCESS = 1
mcm 0:e4146617a5fc 105 } MicroForce_FMA_status_t;
mcm 0:e4146617a5fc 106
mcm 0:e4146617a5fc 107
mcm 0:e4146617a5fc 108
mcm 0:e4146617a5fc 109
mcm 0:e4146617a5fc 110 /** Create an MicroForce_FMA object connected to the specified SPI pins.
mcm 0:e4146617a5fc 111 *
mcm 0:e4146617a5fc 112 * @param mosi SPI Master Output Slave Input
mcm 0:e4146617a5fc 113 * @param miso SPI Master Input Slave Output
mcm 0:e4146617a5fc 114 * @param sclk SPI clock
mcm 0:e4146617a5fc 115 * @param cs SPI Chip Select
mcm 0:e4146617a5fc 116 * @param freq SPI frequency in Hz.
mcm 0:e4146617a5fc 117 */
mcm 0:e4146617a5fc 118 MicroForce_FMA ( PinName mosi, PinName miso, PinName sclk, PinName cs, uint32_t freq );
mcm 0:e4146617a5fc 119
mcm 0:e4146617a5fc 120 /** Delete MicroForce_FMA object.
mcm 0:e4146617a5fc 121 */
mcm 0:e4146617a5fc 122 ~MicroForce_FMA();
mcm 0:e4146617a5fc 123
mcm 0:e4146617a5fc 124 /** It gets the raw force data.
mcm 0:e4146617a5fc 125 */
mcm 0:e4146617a5fc 126 MicroForce_FMA_status_t MicroForce_FMA_GetRawForce ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRawBridgeData );
mcm 0:e4146617a5fc 127
mcm 0:e4146617a5fc 128 /** It calculates the force data in Newton (N).
mcm 0:e4146617a5fc 129 */
mcm 0:e4146617a5fc 130 float MicroForce_FMA_CalculateForce ( MicroForce_FMA_transfer_function_t myCalibration, uint8_t myForceRange, uint16_t myRawBridgeData );
mcm 0:e4146617a5fc 131
mcm 0:e4146617a5fc 132 /** It gets the raw 8-bit temperature.
mcm 0:e4146617a5fc 133 */
mcm 0:e4146617a5fc 134 MicroForce_FMA_status_t MicroForce_FMA_GetRaw8bitTemperature ( MicroForce_FMA_status_bits_data_t* myStatus, uint8_t* myRaw8bitTemp );
mcm 0:e4146617a5fc 135
mcm 0:e4146617a5fc 136 /** It gets the raw 11-bit temperature.
mcm 0:e4146617a5fc 137 */
mcm 0:e4146617a5fc 138 MicroForce_FMA_status_t MicroForce_FMA_GetRaw11bitTemperature ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRaw11bitTemp );
mcm 0:e4146617a5fc 139
mcm 0:e4146617a5fc 140 /** It calculates the 8-bit temperature in Celsius degree.
mcm 0:e4146617a5fc 141 */
mcm 0:e4146617a5fc 142 float MicroForce_FMA_Calculate8bitTemperature ( uint8_t myRawTemperature );
mcm 0:e4146617a5fc 143
mcm 0:e4146617a5fc 144 /** It calculates the 11-bit temperature in Celsius degree.
mcm 0:e4146617a5fc 145 */
mcm 0:e4146617a5fc 146 float MicroForce_FMA_Calculate11bitTemperature ( uint16_t myRawTemperature );
mcm 0:e4146617a5fc 147
mcm 0:e4146617a5fc 148 /** It gets the all raw data ( bridge data and 11-bit temperature ).
mcm 0:e4146617a5fc 149 */
mcm 0:e4146617a5fc 150 MicroForce_FMA_status_t MicroForce_FMA_GetAllRawData ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRawBridgeData, uint16_t* myRaw11bitTemp );
mcm 0:e4146617a5fc 151
mcm 0:e4146617a5fc 152 private:
mcm 0:e4146617a5fc 153 SPI _spi;
mcm 0:e4146617a5fc 154 DigitalOut _cs;
mcm 0:e4146617a5fc 155 };
mcm 0:e4146617a5fc 156
mcm 0:e4146617a5fc 157 #endif