Simple demo example of X-NUCLEO-IPS02A1 24V Intelligent Power Switch Library usage.

Dependencies:   X_NUCLEO_IPS02A1 mbed

Fork of HelloWorld_IPS02A1 by ST Expansion SW Team

HelloWorld_IPS02A1, demo example for IPS02A1 expansion board

Introduction

This example application provides a basic code to show how to use the X-NUCLEO-IPS02A1 Intelligent Power Switch Expansion Board. The example performs current measurements on output Channel 1 (Ch1) and Channel 2 (Ch2), continuously, in the following conditions:

  • 1) Ch1 OFF, Ch2 OFF
  • 2) Ch1 ON, Ch2 OFF
  • 3) Ch1 OFF, Ch2 ON
  • 4) Ch1 ON, Ch2 ON

for each configuration the Current for each channel is displayed over an opened console (use Hyperterminal or whatever, set 9600 as bauds, 8-bit data, no parity)

Demo Code

The basic operation done by the demo code, which can be used in the customer application are :

1) In order to use get the singleton instance of the X_NUCLEO_IPS02A1 by calling class method `Instance()`:

// IPS expansion board singleton instance
static X_NUCLEO_IPS02A1 *ips_expansion_board = X_NUCLEO_IPS02A1::Instance();

2) Switch-on or Switch-off loads output (Channel 1 or Channel 2) by setting or clearing associated digital input :

            ips_expansion_board.vps2535h.In_1 = 1; // switch-on Channel 1
            ips_expansion_board.vps2535h.In_2 = 0; // switch-off Channel 2 

3) Read Current circulating on Channel 1 or Channel 2 and print on the Terminal

            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
            printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
            printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
Revision:
9:60a0bf4a5681
Parent:
7:7a2e3132ce46
diff -r 2c636c40108b -r 60a0bf4a5681 main.cpp
--- a/main.cpp	Thu Sep 01 14:20:10 2016 +0000
+++ b/main.cpp	Tue May 09 09:37:26 2017 +0000
@@ -48,12 +48,17 @@
  * <b>Example Application</b>
  *
  */
+
+
 /*** Includes ----------------------------------------------------------------- ***/
+
 #include "mbed.h"
 #include "assert.h"
-#include "x_nucleo_ips02a1.h"
+#include "XNucleoIPS02A1.h"
  
+
 /*** Static variables --------------------------------------------------------- ***/
+
 #ifdef DBG_MCU
 #include "DbgMCU.h"
 static DbgMCU enable_dbg;
@@ -76,40 +81,44 @@
 #define R_D1 56e3
 /* R_D2 */
 #define R_D2 36e3
- 
-/* End of HW settings */
- 
+
+
 /*** Variables ----------------------------------------------------------------- ***/
-static X_NUCLEO_IPS02A1 &ips_expansion_board = X_NUCLEO_IPS02A1::Instance(IPS02A1_PIN_IN_1,
-                                                                          IPS02A1_PIN_IN_2,
-                                                                          IPS02A1_PIN_FR_STBY,
-                                                                          IPS02A1_PIN_CURRENTSENSE1,
-                                                                          IPS02A1_PIN_CURRENTSENSE2,                                                                         
-                                                                          V_REF,
-                                                                          R_SENSE,
-                                                                          R_D1,
-                                                                          R_D2);
- 
+
+static XNucleoIPS02A1 &ips_expansion_board = XNucleoIPS02A1::instance(IPS02A1_PIN_IN_1,
+                                                                      IPS02A1_PIN_IN_2,
+                                                                      IPS02A1_PIN_FR_STBY,
+                                                                      IPS02A1_PIN_CURRENTSENSE1,
+                                                                      IPS02A1_PIN_CURRENTSENSE2,                                                                         
+                                                                      V_REF,
+                                                                      R_SENSE,
+                                                                      R_D1,
+                                                                      R_D2);
+
 static Ticker ticker;
-DigitalOut UserLed(LED1);    
-float Multisense_Signal = 0;    // Multisense pin - signal level
-bool  ButtonPressed = 0;        // User Button
-int   TestSequence = 1;         // Test sequence counter
+DigitalOut user_led(LED1);    
+float multisense_signal = 0;    // Multisense pin - signal level
+bool  button_pressed = 0;       // User Button
+int   test_sequence = 1;        // Test sequence counter
  
 //------------------------------------
 // Hyperterminal configuration
 // 9600 bauds, 8-bit data, no parity
 //------------------------------------
- 
-InterruptIn UserButton(USER_BUTTON); // B1 is the User Button
-void B1_pressed (void);
-void LedBlink (int TestSequence);
-void Write_Serial (void);
-void Reset_Pins (void);
- 
-/*** Main function ------------------------------------------------------------- ***/
-int main(void){
-    UserButton.fall(&B1_pressed);    //interrupt User Button
+InterruptIn user_button(USER_BUTTON); // B1 is the User Button
+void b1_pressed (void);
+void led_blink (int test_sequence);
+void write_serial (void);
+void reset_pins (void);
+
+
+/*** Functions ----------------------------------------------------------------- ***/
+
+/**
+ * Main function.
+ */
+int main(void) {
+    user_button.fall(&b1_pressed); //Interrupt User Button
    
     printf("############################################################ \n\r");
     printf("###################  TEST PROCEDURE ######################## \n\r");
@@ -127,14 +136,13 @@
     
     while (true) {
         // Wait for User button pressed.
-        while (!ButtonPressed) {
-        }
+        while (!button_pressed) {}
            
-        ButtonPressed = 0;
+        button_pressed = 0;
         
-        LedBlink(TestSequence);
+        led_blink(test_sequence);
      
-        switch (TestSequence) {
+        switch (test_sequence) {
           case (1):
             printf("############################################################ \n\r");
             printf("###################  TEST PROCEDURE ######################## \n\r");
@@ -150,13 +158,13 @@
  
           case (2): {
             printf("Test 1: StandBy\n\r");
-            Reset_Pins();
+            reset_pins();
             wait (0.1);
-            Write_Serial();
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
-            printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
-            printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
+            write_serial();
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_1);
+            printf("Current Ch1 = %2.3fA \n\r", multisense_signal);
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_2);
+            printf("Current Ch2 = %2.3fA \n\r", multisense_signal);
             printf("\n\r\n\r");
            }
            break;
@@ -167,13 +175,13 @@
             ips_expansion_board.vps2535h.In_2 = 0;
             ips_expansion_board.vps2535h.Fr_Stby = 1;
             wait (0.1);
-            Write_Serial();
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
-            printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
-            printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
+            write_serial();
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_1);
+            printf("Current Ch1 = %2.3fA \n\r", multisense_signal);
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_2);
+            printf("Current Ch2 = %2.3fA \n\r", multisense_signal);
             wait (0.5);
-            Reset_Pins();
+            reset_pins();
             printf("\n\r\n\r");
            }
            break;
@@ -184,13 +192,13 @@
             ips_expansion_board.vps2535h.In_2 = 1;
             ips_expansion_board.vps2535h.Fr_Stby = 1;
             wait (0.1);
-            Write_Serial();
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
-            printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
-            printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
+            write_serial();
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_1);
+            printf("Current Ch1 = %2.3fA \n\r", multisense_signal);
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_2);
+            printf("Current Ch2 = %2.3fA \n\r", multisense_signal);
             wait (.5);
-            Reset_Pins();
+            reset_pins();
             printf("\n\r\n\r");
            }
            break;
@@ -201,59 +209,68 @@
             ips_expansion_board.vps2535h.In_2 = 1;
             ips_expansion_board.vps2535h.Fr_Stby = 1;
             wait (0.1);
-            Write_Serial();
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
-            printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
-            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
-            printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
+            write_serial();
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_1);
+            printf("Current Ch1 = %2.3fA \n\r", multisense_signal);
+            multisense_signal = ips_expansion_board.get_current(CHANNEL_2);
+            printf("Current Ch2 = %2.3fA \n\r", multisense_signal);
             wait (.5);
-            Reset_Pins();
+            reset_pins();
             printf("\n\r\n\r");
            }
           break;
  
           default: {
             printf("End of Test Cycle. Press the user button to continue...\n\n\n\r");  
-            TestSequence = 0;
-            Reset_Pins();
+            test_sequence = 0;
+            reset_pins();
            }
           break;
         } 
     }
 }
+
+/**
+ * Interrupt procedure, user button is pressed.
+ */
+void b1_pressed() {
+    test_sequence ++;
  
-void B1_pressed (){
-    // Interrupt procedure - User button is pressed.
-    TestSequence ++;
- 
-    UserLed = 1; // LED is ON
-    wait(0.05);  // 50 ms
-    UserLed = 0; // LED is OFF
+    user_led = 1; // LED is ON
+    wait(0.05);   // 50 ms
+    user_led = 0; // LED is OFF
  
-    ButtonPressed = 1;
+    button_pressed = 1;
 }
- 
-void LedBlink (int TestSequence){
-    // Feedback by using User LED.
-    for (int TestCounter =0; TestCounter<TestSequence; TestCounter++) {
-        UserLed = 1; // LED is ON
+
+/**
+ * Feedback by using User LED.
+ */ 
+void led_blink(int test_sequence) {
+
+    for (int test = 0; test < test_sequence; test++) {
+        user_led = 1; // LED is ON
         wait(0.05);  // 50 ms
-        UserLed = 0; // LED is OFF
+        user_led = 0; // LED is OFF
         wait(0.05);  // 50 msec
     }
-    wait(1-(TestSequence*2*0.05));
+    wait(1- (test_sequence * 2 * 0.05));
 }
- 
-void Write_Serial (){
-    // This code sends messages and data to the serial port.
+
+/**
+ * Send messages and data to the serial port.
+ */
+void write_serial() {
     printf("Input 1= %d\t", ips_expansion_board.vps2535h.In_1.read());
     printf("Input 2= %d\t", ips_expansion_board.vps2535h.In_2.read());
     printf("Fr_Stby= %d\t\n\r", ips_expansion_board.vps2535h.Fr_Stby.read());
 }
- 
-void Reset_Pins(){
-    // Reset input pins.
+
+/**
+ * Reset input pins.
+ */
+void reset_pins() {
     ips_expansion_board.vps2535h.In_1= 0;
     ips_expansion_board.vps2535h.In_2 = 0;
     ips_expansion_board.vps2535h.Fr_Stby = 0;
-}
\ No newline at end of file
+}