MicroForce Sensors, Compensated/Amplified

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Wed Jun 30 14:08:37 2021 +0000
Parent:
1:4b8a700b3f5c
Commit message:
This driver was completed and tested (NUCLEO-L053R8) and it works as expected. This driver only supports SPI communication.

Changed in this revision

MicroForce_FMA.cpp Show annotated file Show diff for this revision Revisions of this file
MicroForce_FMA.h Show annotated file Show diff for this revision Revisions of this file
diff -r 4b8a700b3f5c -r 2f45d928f6e0 MicroForce_FMA.cpp
--- a/MicroForce_FMA.cpp	Wed Jun 30 13:29:31 2021 +0000
+++ b/MicroForce_FMA.cpp	Wed Jun 30 14:08:37 2021 +0000
@@ -7,10 +7,10 @@
  * @return      N/A
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021    The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021    The ORIGIN
  * @pre         N/A.
- * @warning     N/A
+ * @warning     This driver only supports SPI communication.
  * @pre         This code belongs to Nimbus Centre ( https://www.nimbus.cit.ie ).
  */
 
@@ -46,8 +46,8 @@
  *
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021   The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021   The ORIGIN
  * @pre         N/A.
  * @warning     N/A.
  */
@@ -93,8 +93,8 @@
  *
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021   The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021   The ORIGIN
  * @pre         The function: MicroForce_FMA_GetRawForce must be called to update the bridge data values.
  * @warning     N/A.
  */
@@ -135,8 +135,8 @@
  *
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021   The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021   The ORIGIN
  * @pre         N/A.
  * @warning     N/A.
  */
@@ -180,8 +180,8 @@
  *
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021   The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021   The ORIGIN
  * @pre         N/A.
  * @warning     N/A.
  */
@@ -228,8 +228,8 @@
  *
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021   The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021   The ORIGIN
  * @pre         The function:MicroForce_FMA_GetRaw8bitTemperature must be called to update the temperature value.
  * @warning     N/A.
  */
@@ -262,8 +262,8 @@
  *
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021   The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021   The ORIGIN
  * @pre         The function:MicroForce_FMA_GetRaw11bitTemperature must be called to update the temperature value.
  * @warning     N/A.
  */
@@ -291,8 +291,8 @@
  *
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021   The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021   The ORIGIN
  * @pre         N/A.
  * @warning     N/A.
  */
diff -r 4b8a700b3f5c -r 2f45d928f6e0 MicroForce_FMA.h
--- a/MicroForce_FMA.h	Wed Jun 30 13:29:31 2021 +0000
+++ b/MicroForce_FMA.h	Wed Jun 30 14:08:37 2021 +0000
@@ -7,10 +7,10 @@
  * @return      N/A
  *
  * @author      Manuel Caballero
- * @date        29/June/2021
- * @version     29/June/2021    The ORIGIN
+ * @date        30/June/2021
+ * @version     30/June/2021    The ORIGIN
  * @pre         N/A.
- * @warning     N/A
+ * @warning     This driver only supports SPI communication.
  * @pre         This code belongs to Nimbus Centre ( https://www.nimbus.cit.ie ).
  */
 #ifndef MicroForce_FMA_H
@@ -20,7 +20,93 @@
 /**
     Example:
 @code
+#include "mbed.h"
+#include "MicroForce_FMA.h"
 
+MicroForce_FMA myMicroForce_FMA ( PB_5, PB_4, PB_3, PB_8, 500000 );             // MOSI: PB_5 | MISO: PB_4 | SCLK: PB_3 | CS: PB_8 | FREQ: 500kHz;
+Serial pc     ( USBTX, USBRX );                                                 // tx, rx
+
+DigitalOut  myled   ( LED1 );
+Ticker      newAction;
+
+
+//@brief Constants.
+
+
+//@brief Variables.
+volatile uint32_t myState;                                                      // State that indicates when to perform a new sample
+
+
+//@brief   FUNCTION PROTOTYPES
+void    changeDATA     ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+int main()
+{
+    MicroForce_FMA::MicroForce_FMA_status_t aux;
+    MicroForce_FMA::MicroForce_FMA_data_t   myMicroForce_FMA_Data;
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+
+    myState  =   0UL;                                                           // Reset the variable
+    newAction.attach( &changeDATA, 1U );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 5s )
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        if ( myState == 1UL ) {
+            myled = 1U;
+
+            do {
+                // Get all the data  
+                aux  =   myMicroForce_FMA.MicroForce_FMA_GetAllRawData ( &myMicroForce_FMA_Data.status, &myMicroForce_FMA_Data.force.raw_bridge_data, &myMicroForce_FMA_Data.temperature.raw_11bit_temperature );
+                wait_ms(1U);
+            } while( myMicroForce_FMA_Data.status.status_bits != MicroForce_FMA::MicroForce_FMA_STATUS_BITS_NORMAL_OPERATION );
+
+            // It processes all the data  
+            myMicroForce_FMA_Data.transfer_function             =  MicroForce_FMA::MicroForce_FMA_TRANSFER_FUNCTION_20_TO_80;
+            myMicroForce_FMA_Data.force_range                   =  FMA_FORCE_RANGE_15_N;
+            myMicroForce_FMA_Data.force.bridge_data             =  myMicroForce_FMA.MicroForce_FMA_CalculateForce ( myMicroForce_FMA_Data.transfer_function, myMicroForce_FMA_Data.force_range, myMicroForce_FMA_Data.force.raw_bridge_data );
+            myMicroForce_FMA_Data.temperature.temperature_data  =  myMicroForce_FMA.MicroForce_FMA_Calculate11bitTemperature ( myMicroForce_FMA_Data.temperature.raw_11bit_temperature );
+
+
+            // Send data through the UART
+            pc.printf ( "Force: %d N | Temp: %d C\r\n", (uint32_t)myMicroForce_FMA_Data.force.bridge_data, (uint32_t)myMicroForce_FMA_Data.temperature.temperature_data );
+
+            // Reset the variables
+            myState  =   0UL;
+            myled    =   0U;
+        }
+    }
+}
+
+
+// @brief       changeDATA ( void  )
+//
+// @details     It changes myState variable
+//
+// @param[in]    N/A
+//
+// @param[out]   N/A.
+//
+// @return       N/A.
+//
+// @author      Manuel Caballero
+// @date        30/June/2021
+// @version     30/June/2021   The ORIGIN
+// @pre         N/A
+// @warning     N/A.
+void changeDATA ( void )
+{
+    myState  =   1UL;
+}
 @endcode
 */