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);
Committer:
grussian
Date:
Thu Jul 28 16:12:44 2016 +0000
Revision:
6:32a3eb2a79cd
Parent:
3:52b7f2fcaf74
Child:
7:7a2e3132ce46
changed device name into the main from vps235h2 to vps2535h. Imported new version of the X_NUCLEO_IPS02_A1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grussian 1:59b97633b43d 1 /**
grussian 1:59b97633b43d 2 ******************************************************************************
grussian 1:59b97633b43d 3 * @file main.cpp
grussian 6:32a3eb2a79cd 4 * @author ADG
grussian 1:59b97633b43d 5 * @version V1.0.1
grussian 6:32a3eb2a79cd 6 * @date 01-July-2016
grussian 1:59b97633b43d 7 * @brief Example application for using the X_NUCLEO_IPS02A1
grussian 1:59b97633b43d 8 * Intelligent Power Switch Nucleo expansion board.
grussian 1:59b97633b43d 9 ******************************************************************************
grussian 1:59b97633b43d 10 * @attention
grussian 1:59b97633b43d 11 *
grussian 1:59b97633b43d 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
grussian 1:59b97633b43d 13 *
grussian 1:59b97633b43d 14 * Redistribution and use in source and binary forms, with or without modification,
grussian 1:59b97633b43d 15 * are permitted provided that the following conditions are met:
grussian 1:59b97633b43d 16 * 1. Redistributions of source code must retain the above copyright notice,
grussian 1:59b97633b43d 17 * this list of conditions and the following disclaimer.
grussian 1:59b97633b43d 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
grussian 1:59b97633b43d 19 * this list of conditions and the following disclaimer in the documentation
grussian 1:59b97633b43d 20 * and/or other materials provided with the distribution.
grussian 1:59b97633b43d 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
grussian 1:59b97633b43d 22 * may be used to endorse or promote products derived from this software
grussian 1:59b97633b43d 23 * without specific prior written permission.
grussian 1:59b97633b43d 24 *
grussian 1:59b97633b43d 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
grussian 1:59b97633b43d 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
grussian 1:59b97633b43d 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
grussian 1:59b97633b43d 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
grussian 1:59b97633b43d 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
grussian 1:59b97633b43d 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
grussian 1:59b97633b43d 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
grussian 1:59b97633b43d 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
grussian 1:59b97633b43d 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
grussian 1:59b97633b43d 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
grussian 1:59b97633b43d 35 *
grussian 1:59b97633b43d 36 ******************************************************************************
grussian 1:59b97633b43d 37 */
grussian 3:52b7f2fcaf74 38
grussian 1:59b97633b43d 39 /**
grussian 1:59b97633b43d 40 * @mainpage X_NUCLEO_IPS02A1 Intelligent Power Switch Nucleo Expansion Board Firmware Package
grussian 1:59b97633b43d 41 *
grussian 1:59b97633b43d 42 * <b>Introduction</b>
grussian 1:59b97633b43d 43 *
grussian 1:59b97633b43d 44 * This firmware package includes Components Device Drivers, Board Support Package
grussian 1:59b97633b43d 45 * and example application for STMicroelectronics X_NUCLEO_IPS02A1 Intelligent Power Switch
grussian 1:59b97633b43d 46 * Nucleo Expansion Board
grussian 1:59b97633b43d 47 *
grussian 1:59b97633b43d 48 * <b>Example Application</b>
grussian 1:59b97633b43d 49 *
grussian 1:59b97633b43d 50 */
grussian 1:59b97633b43d 51 /*** Includes ----------------------------------------------------------------- ***/
grussian 1:59b97633b43d 52 #include "mbed.h"
grussian 1:59b97633b43d 53 #include "assert.h"
grussian 1:59b97633b43d 54 #include "x_nucleo_ips02a1.h"
grussian 3:52b7f2fcaf74 55
grussian 1:59b97633b43d 56 /*** Static variables --------------------------------------------------------- ***/
grussian 1:59b97633b43d 57 #ifdef DBG_MCU
grussian 1:59b97633b43d 58 #include "DbgMCU.h"
grussian 1:59b97633b43d 59 static DbgMCU enable_dbg;
grussian 1:59b97633b43d 60 #endif // DBG_MCU
grussian 3:52b7f2fcaf74 61
grussian 1:59b97633b43d 62 /* HW settings */
grussian 1:59b97633b43d 63 /* Pay attention before changing HW settings, they must be coherent with you HW design */
grussian 1:59b97633b43d 64 /* Power Switch Connection to Arduino connectors */
grussian 1:59b97633b43d 65 #define IPS02A1_PIN_IN_1 (D5)
grussian 1:59b97633b43d 66 #define IPS02A1_PIN_IN_2 (D6)
grussian 1:59b97633b43d 67 #define IPS02A1_PIN_FR_STBY (D4)
grussian 1:59b97633b43d 68 #define IPS02A1_PIN_CURRENTSENSE1 (A2)
grussian 1:59b97633b43d 69 #define IPS02A1_PIN_CURRENTSENSE2 (A3)
grussian 3:52b7f2fcaf74 70
grussian 1:59b97633b43d 71 /* V-Ref */
grussian 1:59b97633b43d 72 #define V_REF 3.3
grussian 1:59b97633b43d 73 /* Rsense Value */
grussian 1:59b97633b43d 74 #define R_SENSE 1e3
grussian 1:59b97633b43d 75 /* R_D1 */
grussian 1:59b97633b43d 76 #define R_D1 56e3
grussian 1:59b97633b43d 77 /* R_D2 */
grussian 1:59b97633b43d 78 #define R_D2 36e3
grussian 3:52b7f2fcaf74 79
grussian 1:59b97633b43d 80 /* End of HW settings */
grussian 3:52b7f2fcaf74 81
grussian 3:52b7f2fcaf74 82 /*** Variables ----------------------------------------------------------------- ***/
grussian 1:59b97633b43d 83 static X_NUCLEO_IPS02A1 &ips_expansion_board = X_NUCLEO_IPS02A1::Instance(IPS02A1_PIN_IN_1,
grussian 1:59b97633b43d 84 IPS02A1_PIN_IN_2,
grussian 1:59b97633b43d 85 IPS02A1_PIN_FR_STBY,
grussian 1:59b97633b43d 86 IPS02A1_PIN_CURRENTSENSE1,
grussian 1:59b97633b43d 87 IPS02A1_PIN_CURRENTSENSE2,
grussian 1:59b97633b43d 88 V_REF,
grussian 1:59b97633b43d 89 R_SENSE,
grussian 1:59b97633b43d 90 R_D1,
grussian 1:59b97633b43d 91 R_D2);
grussian 3:52b7f2fcaf74 92
grussian 1:59b97633b43d 93 static Ticker ticker;
grussian 1:59b97633b43d 94 DigitalOut UserLed(LED1);
grussian 1:59b97633b43d 95 float Multisense_Signal = 0; // Multisense pin - signal level
grussian 3:52b7f2fcaf74 96 bool ButtonPressed = 0; // User Button
grussian 3:52b7f2fcaf74 97 int TestSequence = 1; // Test sequence counter
grussian 3:52b7f2fcaf74 98
grussian 1:59b97633b43d 99 //------------------------------------
grussian 1:59b97633b43d 100 // Hyperterminal configuration
grussian 1:59b97633b43d 101 // 9600 bauds, 8-bit data, no parity
grussian 1:59b97633b43d 102 //------------------------------------
grussian 3:52b7f2fcaf74 103
grussian 3:52b7f2fcaf74 104 InterruptIn UserButton(USER_BUTTON); // B1 is the User Button
grussian 1:59b97633b43d 105 void B1_pressed (void);
grussian 1:59b97633b43d 106 void LedBlink (int TestSequence);
grussian 1:59b97633b43d 107 void Write_Serial (void);
grussian 1:59b97633b43d 108 void Reset_Pins (void);
grussian 3:52b7f2fcaf74 109
grussian 3:52b7f2fcaf74 110 /*** Main function ------------------------------------------------------------- ***/
grussian 1:59b97633b43d 111 int main(void){
grussian 3:52b7f2fcaf74 112 UserButton.fall(&B1_pressed); //interrupt User Button
grussian 1:59b97633b43d 113
grussian 1:59b97633b43d 114 printf("############################################################ \n\r");
grussian 1:59b97633b43d 115 printf("################### TEST PROCEDURE ######################## \n\r");
grussian 1:59b97633b43d 116 printf("############################################################ \n\n\r");
grussian 1:59b97633b43d 117 printf("This demo performs current measurements on Ch1 and Ch2 \n\r");
grussian 1:59b97633b43d 118 printf("in the following conditions: \n\r\n\r");
grussian 1:59b97633b43d 119 printf(" 1) Ch1 OFF, Ch2 OFF \n\r");
grussian 1:59b97633b43d 120 printf(" 2) Ch1 ON, Ch2 OFF \n\r");
grussian 1:59b97633b43d 121 printf(" 3) Ch1 OFF, Ch2 ON \n\r");
grussian 1:59b97633b43d 122 printf(" 4) Ch1 ON, Ch2 ON \n\r\n\r");
grussian 1:59b97633b43d 123
grussian 1:59b97633b43d 124 printf("Start test Procedure.... \n\r\n\r");
grussian 1:59b97633b43d 125 printf("PRESS USER BUTTON (Blue One) on NUCLEO to perform single test \n\r\n\r\n\r");
grussian 1:59b97633b43d 126
grussian 1:59b97633b43d 127
grussian 1:59b97633b43d 128 while (true) {
grussian 3:52b7f2fcaf74 129 // Wait for User button pressed.
grussian 1:59b97633b43d 130 while (!ButtonPressed) {
grussian 1:59b97633b43d 131 }
grussian 1:59b97633b43d 132
grussian 1:59b97633b43d 133 ButtonPressed = 0;
grussian 1:59b97633b43d 134
grussian 1:59b97633b43d 135 LedBlink(TestSequence);
grussian 1:59b97633b43d 136
grussian 1:59b97633b43d 137 switch (TestSequence) {
grussian 1:59b97633b43d 138 case (1):
grussian 1:59b97633b43d 139 printf("############################################################ \n\r");
grussian 1:59b97633b43d 140 printf("################### TEST PROCEDURE ######################## \n\r");
grussian 1:59b97633b43d 141 printf("############################################################ \n\n\r");
grussian 1:59b97633b43d 142 printf("This demo performs current measurements on Ch1 and Ch2 \n\r");
grussian 1:59b97633b43d 143 printf("in the following conditions: \n\r\n\r");
grussian 1:59b97633b43d 144 printf(" 1) Ch1 OFF, Ch2 OFF \n\r");
grussian 1:59b97633b43d 145 printf(" 2) Ch1 ON, Ch2 OFF \n\r");
grussian 1:59b97633b43d 146 printf(" 3) Ch1 OFF, Ch2 ON \n\r");
grussian 1:59b97633b43d 147 printf(" 4) Ch1 ON, Ch2 ON \n\r\n\r");
grussian 1:59b97633b43d 148 printf("\n\r\n\r");
grussian 1:59b97633b43d 149 break;
grussian 3:52b7f2fcaf74 150
grussian 1:59b97633b43d 151 case (2): {
grussian 1:59b97633b43d 152 printf("Test 1: StandBy\n\r");
grussian 1:59b97633b43d 153 Reset_Pins();
grussian 1:59b97633b43d 154 wait (0.1);
grussian 1:59b97633b43d 155 Write_Serial();
grussian 1:59b97633b43d 156 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
grussian 1:59b97633b43d 157 printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 158 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
grussian 1:59b97633b43d 159 printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 160 printf("\n\r\n\r");
grussian 1:59b97633b43d 161 }
grussian 1:59b97633b43d 162 break;
grussian 3:52b7f2fcaf74 163
grussian 1:59b97633b43d 164 case(3):{
grussian 1:59b97633b43d 165 printf("Test 2: Ch1=ON, CH2=OFF\n\r");
grussian 6:32a3eb2a79cd 166 ips_expansion_board.vps2535h.In_1 = 1;
grussian 6:32a3eb2a79cd 167 ips_expansion_board.vps2535h.In_2 = 0;
grussian 6:32a3eb2a79cd 168 ips_expansion_board.vps2535h.Fr_Stby = 1;
grussian 1:59b97633b43d 169 wait (0.1);
grussian 1:59b97633b43d 170 Write_Serial();
grussian 1:59b97633b43d 171 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
grussian 1:59b97633b43d 172 printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 173 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
grussian 1:59b97633b43d 174 printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 175 wait (0.5);
grussian 1:59b97633b43d 176 Reset_Pins();
grussian 1:59b97633b43d 177 printf("\n\r\n\r");
grussian 1:59b97633b43d 178 }
grussian 1:59b97633b43d 179 break;
grussian 3:52b7f2fcaf74 180
grussian 1:59b97633b43d 181 case(4):{
grussian 1:59b97633b43d 182 printf("Test 3: Ch1=OFF, CH2=ON\n\r");
grussian 6:32a3eb2a79cd 183 ips_expansion_board.vps2535h.In_1 = 0;
grussian 6:32a3eb2a79cd 184 ips_expansion_board.vps2535h.In_2 = 1;
grussian 6:32a3eb2a79cd 185 ips_expansion_board.vps2535h.Fr_Stby = 1;
grussian 1:59b97633b43d 186 wait (0.1);
grussian 1:59b97633b43d 187 Write_Serial();
grussian 1:59b97633b43d 188 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
grussian 1:59b97633b43d 189 printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 190 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
grussian 1:59b97633b43d 191 printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 192 wait (.5);
grussian 1:59b97633b43d 193 Reset_Pins();
grussian 1:59b97633b43d 194 printf("\n\r\n\r");
grussian 1:59b97633b43d 195 }
grussian 1:59b97633b43d 196 break;
grussian 3:52b7f2fcaf74 197
grussian 1:59b97633b43d 198 case(5):{
grussian 1:59b97633b43d 199 printf("Test 4: Ch1=ON, CH2=ON \n\r");
grussian 6:32a3eb2a79cd 200 ips_expansion_board.vps2535h.In_1= 1;
grussian 6:32a3eb2a79cd 201 ips_expansion_board.vps2535h.In_2 = 1;
grussian 6:32a3eb2a79cd 202 ips_expansion_board.vps2535h.Fr_Stby = 1;
grussian 1:59b97633b43d 203 wait (0.1);
grussian 1:59b97633b43d 204 Write_Serial();
grussian 1:59b97633b43d 205 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
grussian 1:59b97633b43d 206 printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 207 Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
grussian 1:59b97633b43d 208 printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
grussian 1:59b97633b43d 209 wait (.5);
grussian 1:59b97633b43d 210 Reset_Pins();
grussian 1:59b97633b43d 211 printf("\n\r\n\r");
grussian 1:59b97633b43d 212 }
grussian 1:59b97633b43d 213 break;
grussian 3:52b7f2fcaf74 214
grussian 1:59b97633b43d 215 default: {
grussian 3:52b7f2fcaf74 216 printf("End of Test Cycle. Press the user button to continue...\n\n\n\r");
grussian 1:59b97633b43d 217 TestSequence = 0;
grussian 1:59b97633b43d 218 Reset_Pins();
grussian 1:59b97633b43d 219 }
grussian 1:59b97633b43d 220 break;
grussian 1:59b97633b43d 221 }
grussian 1:59b97633b43d 222 }
grussian 3:52b7f2fcaf74 223 }
grussian 3:52b7f2fcaf74 224
grussian 1:59b97633b43d 225 void B1_pressed (){
grussian 3:52b7f2fcaf74 226 // Interrupt procedure - User button is pressed.
grussian 1:59b97633b43d 227 TestSequence ++;
grussian 3:52b7f2fcaf74 228
grussian 1:59b97633b43d 229 UserLed = 1; // LED is ON
grussian 3:52b7f2fcaf74 230 wait(0.05); // 50 ms
grussian 1:59b97633b43d 231 UserLed = 0; // LED is OFF
grussian 3:52b7f2fcaf74 232
grussian 1:59b97633b43d 233 ButtonPressed = 1;
grussian 1:59b97633b43d 234 }
grussian 3:52b7f2fcaf74 235
grussian 1:59b97633b43d 236 void LedBlink (int TestSequence){
grussian 3:52b7f2fcaf74 237 // Feedback by using User LED.
grussian 1:59b97633b43d 238 for (int TestCounter =0; TestCounter<TestSequence; TestCounter++) {
grussian 1:59b97633b43d 239 UserLed = 1; // LED is ON
grussian 3:52b7f2fcaf74 240 wait(0.05); // 50 ms
grussian 1:59b97633b43d 241 UserLed = 0; // LED is OFF
grussian 3:52b7f2fcaf74 242 wait(0.05); // 50 msec
grussian 1:59b97633b43d 243 }
grussian 1:59b97633b43d 244 wait(1-(TestSequence*2*0.05));
grussian 1:59b97633b43d 245 }
grussian 3:52b7f2fcaf74 246
grussian 1:59b97633b43d 247 void Write_Serial (){
grussian 3:52b7f2fcaf74 248 // This code sends messages and data to the serial port.
grussian 6:32a3eb2a79cd 249 printf("Input 1= %d\t", ips_expansion_board.vps2535h.In_1.read());
grussian 6:32a3eb2a79cd 250 printf("Input 2= %d\t", ips_expansion_board.vps2535h.In_2.read());
grussian 6:32a3eb2a79cd 251 printf("Fr_Stby= %d\t\n\r", ips_expansion_board.vps2535h.Fr_Stby.read());
grussian 3:52b7f2fcaf74 252 }
grussian 1:59b97633b43d 253
grussian 3:52b7f2fcaf74 254 void Reset_Pins(){
grussian 3:52b7f2fcaf74 255 // Reset input pins.
grussian 6:32a3eb2a79cd 256 ips_expansion_board.vps2535h.In_1= 0;
grussian 6:32a3eb2a79cd 257 ips_expansion_board.vps2535h.In_2 = 0;
grussian 6:32a3eb2a79cd 258 ips_expansion_board.vps2535h.Fr_Stby = 0;
grussian 3:52b7f2fcaf74 259 }