Firmware to manage X-Nucleo-IPS02A1 (24V) Intelligent Power Switch.

Dependents:   HelloWorld_IPS02A1

Fork of X_NUCLEO_IPS02A1 by ST Expansion SW Team

X_NUCLEO_IPS02A1 24V Intelligent Power Switch (IPS) Nucleo Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers and Board Support Package for STMicroelectronics X-NUCLEO-IPS02A1 IPS Expansion Board.

Firmware Library

Class X_NUCLEO_IPS02A1 is intended to represent the Intelligent Power Switch expansion board with the same name.

The expansion board is basically featuring by one IP:

  • vps2535h vertical power switch.

It is intentionally implemented as a singleton because only one X-NUCLEO-IPS02A1 at a time might be deployed in a HW component stack. In order to get the singleton instance you have to call class method `Instance()`, e.g.:

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

How to use the firmware package

The basic operations to deal with the firmware pkg and use the IPS are the following :

1) instantiate the X_NUCLEO by calling class method `Instance()`:

// Sensors expansion board singleton instance
static X_NUCLEO_IPS02A1 *sensors_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.Fr_Stby = 1; // set Fr_Stby pin
            ips_expansion_board.vps2535h.In_1 = 1; // switch-on Channel 1
            ips_expansion_board.vps2535h.In_2 = 0; // switch-off Channle 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:42:52 2016 +0000
Revision:
6:c313d3a5c61a
Parent:
5:b683e69b181c
update st copyright to 2016

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grussian 0:c175921ca7c3 1 /**
grussian 4:715dcaf74418 2 *******************************************************************************
grussian 5:b683e69b181c 3 * @file vps2535h_class.h
grussian 5:b683e69b181c 4 * @author ADG
grussian 4:715dcaf74418 5 * @version V1.0.1
grussian 5:b683e69b181c 6 * @date 01-July-2016
grussian 5:b683e69b181c 7 * @brief vps2535h module driver.
grussian 4:715dcaf74418 8 * This file provides firmware functions to manage the following
grussian 5:b683e69b181c 9 * functionalities of the vps2535h power switch:
grussian 4:715dcaf74418 10 * + Initialization and de-initialization functions
grussian 4:715dcaf74418 11 * + Diagnostic Sense Pin Configuration
grussian 4:715dcaf74418 12 * + Get Sense Diagnostic Values
grussian 4:715dcaf74418 13 *******************************************************************************
grussian 4:715dcaf74418 14 * @attention
grussian 4:715dcaf74418 15 *
grussian 6:c313d3a5c61a 16 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
grussian 4:715dcaf74418 17 *
grussian 4:715dcaf74418 18 * Redistribution and use in source and binary forms, with or without modification,
grussian 4:715dcaf74418 19 * are permitted provided that the following conditions are met:
grussian 4:715dcaf74418 20 * 1. Redistributions of source code must retain the above copyright notice,
grussian 4:715dcaf74418 21 * this list of conditions and the following disclaimer.
grussian 4:715dcaf74418 22 * 2. Redistributions in binary form must reproduce the above copyright notice,
grussian 4:715dcaf74418 23 * this list of conditions and the following disclaimer in the documentation
grussian 4:715dcaf74418 24 * and/or other materials provided with the distribution.
grussian 4:715dcaf74418 25 * 3. Neither the name of STMicroelectronics nor the names of its contributors
grussian 4:715dcaf74418 26 * may be used to endorse or promote products derived from this software
grussian 4:715dcaf74418 27 * without specific prior written permission.
grussian 4:715dcaf74418 28 *
grussian 4:715dcaf74418 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
grussian 4:715dcaf74418 30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
grussian 4:715dcaf74418 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
grussian 4:715dcaf74418 32 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
grussian 4:715dcaf74418 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
grussian 4:715dcaf74418 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
grussian 4:715dcaf74418 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
grussian 4:715dcaf74418 36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
grussian 4:715dcaf74418 37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
grussian 4:715dcaf74418 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
grussian 4:715dcaf74418 39 *
grussian 4:715dcaf74418 40 ******************************************************************************
grussian 4:715dcaf74418 41 */
grussian 4:715dcaf74418 42
grussian 0:c175921ca7c3 43 /* Define to prevent recursive inclusion -------------------------------------*/
grussian 5:b683e69b181c 44 #ifndef __VPS2535H_CLASS_H
grussian 5:b683e69b181c 45 #define __VPS2535H_CLASS_H
grussian 3:9edf6b8f3b2f 46
grussian 0:c175921ca7c3 47 /* Includes ------------------------------------------------------------------*/
grussian 0:c175921ca7c3 48 #include "mbed.h"
grussian 0:c175921ca7c3 49 #include "PowerSwitch.h"
grussian 0:c175921ca7c3 50 #include "IPS.h"
grussian 5:b683e69b181c 51 #include "vps2535h.h"
grussian 3:9edf6b8f3b2f 52
grussian 3:9edf6b8f3b2f 53
grussian 0:c175921ca7c3 54 /* Classes -------------------------------------------------------------------*/
grussian 5:b683e69b181c 55 /** Class representing a VPS2535H power switch component
grussian 0:c175921ca7c3 56 */
grussian 3:9edf6b8f3b2f 57
grussian 5:b683e69b181c 58 class VPS2535H : public PowerSwitch {
grussian 0:c175921ca7c3 59
grussian 0:c175921ca7c3 60 public:
grussian 0:c175921ca7c3 61 DigitalOut In_1,In_2,Fr_Stby;
grussian 0:c175921ca7c3 62
grussian 0:c175921ca7c3 63 /** Constructor
grussian 3:9edf6b8f3b2f 64 * @param[in] input Pin for the power switch
grussian 3:9edf6b8f3b2f 65 * @param[out] sense1 and sense2, outputs from Ch1 and Ch2
grussian 3:9edf6b8f3b2f 66 * @param[in] vref, reference voltage
grussian 3:9edf6b8f3b2f 67 * @param[in] rsense, sense resistor ouside of chip
grussian 3:9edf6b8f3b2f 68 * @param[in] rd1, upper partitor resistor (=R6 in schematic) to protect ADC
grussian 3:9edf6b8f3b2f 69 * @param[in] rd1, lower partitor resistor (=R7 in schematic) to protect ADC
grussian 3:9edf6b8f3b2f 70 */
grussian 5:b683e69b181c 71 VPS2535H(PinName in1, PinName in2, PinName frStdby,
grussian 0:c175921ca7c3 72 PinName sense1, PinName sense2, float vref,float rsense,float rd1,float rd2):
grussian 0:c175921ca7c3 73 PowerSwitch(),
grussian 0:c175921ca7c3 74 In_1 (in1),
grussian 0:c175921ca7c3 75 In_2 (in2),
grussian 0:c175921ca7c3 76 Fr_Stby(frStdby),
grussian 0:c175921ca7c3 77 V_REF(vref),
grussian 0:c175921ca7c3 78 R_SENSE(rsense),
grussian 0:c175921ca7c3 79 R_D1(rd1),
grussian 0:c175921ca7c3 80 R_D2(rd2),
grussian 0:c175921ca7c3 81 CurrentSense1(sense1),
grussian 0:c175921ca7c3 82 CurrentSense2(sense2)
grussian 0:c175921ca7c3 83 {
grussian 3:9edf6b8f3b2f 84 In_1 = In_2 = Fr_Stby = 0;
grussian 0:c175921ca7c3 85 }
grussian 3:9edf6b8f3b2f 86
grussian 0:c175921ca7c3 87 /** Destructor
grussian 0:c175921ca7c3 88 */
grussian 5:b683e69b181c 89 virtual ~VPS2535H() {}
grussian 0:c175921ca7c3 90
grussian 0:c175921ca7c3 91 /*** Interface Methods ***/
grussian 2:06d0eb54630a 92 virtual int Init(void *init_struct);
grussian 0:c175921ca7c3 93 virtual int Close(void);
grussian 2:06d0eb54630a 94 /* Getting the ID of the component */
grussian 2:06d0eb54630a 95 virtual int ReadID(uint8_t *id) { return (int) 235; }
grussian 0:c175921ca7c3 96 /* Provide Ch current w/o checking status of convertion */
grussian 3:9edf6b8f3b2f 97 virtual float GetCurrent(int Ch);
grussian 0:c175921ca7c3 98 /* Provide Ch current Value with status of convertion */
grussian 5:b683e69b181c 99 IPS_StatusTypeDef VPS2535H_GetSecureCurrentSense(IPS_HandleTypeDef *hips);
grussian 2:06d0eb54630a 100 /**
grussian 2:06d0eb54630a 101 * @brief Getting the ID of the component.
grussian 2:06d0eb54630a 102 * @param id Pointer to an allocated variable to store the ID into.
grussian 2:06d0eb54630a 103 * @retval "0" in case of success, an error code otherwise.
grussian 2:06d0eb54630a 104 */
grussian 3:9edf6b8f3b2f 105
grussian 3:9edf6b8f3b2f 106 protected:
grussian 0:c175921ca7c3 107 /*** Methods ***/
grussian 5:b683e69b181c 108 IPS_StatusTypeDef VPS2535H_Close(void);
grussian 5:b683e69b181c 109 IPS_StatusTypeDef VPS2535H_Init(void);
grussian 5:b683e69b181c 110 IPS_StatusTypeDef VPS2535H_GetSenseChannelDiagnostic(IPS_HandleTypeDef *);
grussian 3:9edf6b8f3b2f 111
grussian 3:9edf6b8f3b2f 112 private:
grussian 0:c175921ca7c3 113 const float V_REF; // Reference voltage for V-sense measurement
grussian 0:c175921ca7c3 114 const float R_SENSE; // R-sense value depending on resistor connected to V-sense output
grussian 0:c175921ca7c3 115 const float R_D1; // R_D1 upper divisor partitor resistor (=R6 in schematic)
grussian 0:c175921ca7c3 116 const float R_D2; // R_D2 lower divisor partitor resistor (=R7 in schematic)
grussian 0:c175921ca7c3 117 AnalogIn CurrentSense1; // V-Sense Output from Ch1
grussian 0:c175921ca7c3 118 AnalogIn CurrentSense2; // V-Sense Output from Ch2
grussian 0:c175921ca7c3 119 };
grussian 5:b683e69b181c 120 #endif /* __VPS2535H_CLASS_H */
grussian 3:9edf6b8f3b2f 121
grussian 3:9edf6b8f3b2f 122 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
grussian 3:9edf6b8f3b2f 123