This Arduino shield comes with 4 high side switches BTS7002-1EPP (21A nominal current per output). For demonstrating relay and fuse replacement, the shield can be used to control and protect outputs of a 12V supply, turn ON/OFF loads (e.g. bulbs, heating resistors, motor drives), measure the load current and detect no-load condition. The PROFET™ +2 12V family targets high current automotive applications (e.g. ECU power feeds, auxiliary power outlets, heaters).
Dissecting the shieldPush button digital
: Push button digital (optional).
IN4
: Input PROFET™+2 device U4.
LED1
: Indicator LED 1.
LED2
: Indicator LED 2.
DEN 1+3
: Diagnosis enable PROFET™+2 device U1+U3.
OLOFF
: Option for Open Load in OFF detection.
DEN 2+4
: Diagnosis enable PROFET™+2 device U2+U4.
IN1
: Input PROFET™+2 device U1.
IN2
: Input PROFET™+2 device U2.
IN3
: Input PROFET™+2 device U3.
LED3
: Indicator LED 3.
LED4
: Indicator LED 4.
VIN
: Supply voltage.
Push button analog
: Push button analog (optional).
VBAT
: Measuring of VBAT via voltage divider.
IS 1+2
: Current sense of PROFET™+2 device U1+U2.
IS 3+4
: Current sense of PROFET™+2 device U3+U4.
After connecting the Arduino, which the shield is plugged into, to your computer, launch the Arduino IDE and install the high side switch ino library. Do this by clicking on Sketch and then hovering over Include Library and then clicking on Manage Libraries... In the search bar: type high side switch ino and then you'll find the option to install the library.
Now that the library is properly installed you have the option to explore various pre-written code examples. To do so: simply click on File and then hover over examples and high-side-switch-ino and choose whichever example code snippet you wish.
This library essentially saves you the hassle of having to manually address each pin in your code and controlling your shield in terms of analog output signals for the channel control, digital output for enabling diagnostic features, and analog inputs for using Infineon's current sense diagnostic features.
Setup codeWe start by including our library and then using the hss namespace
#include <hss-shield-bts700x-ino.hpp>
using namespace hss;
Consequently, we instantiate a shield object by whichever name we desire (in the case of the code snippet we currently have: it's HSS). Additionally, we also instantiate an error variable, to which the value of a definition called OK is set (you'll know why below).
Bts700xShieldIno HSS = Bts700xShieldIno(&BTS7002);
Error_t err = OK;
Jumping into our setup function: all we have to do is initialize our HSS object, which we just instantiated using the init() function. This function returns an error code, which we will compare with the value we originally assigned to our error variable (OK definition). To ensure that everything is going right you can check the serial monitor on which the controller tells us if initialization was successful. If you follow all that your code should by now look like this:
#include <hss-shield-bts700x-ino.hpp>
using namespace hss;
Bts700xShieldIno HSS = Bts700xShieldIno(&BTS7002);
Error_t err = OK;
void setup()
{
Serial.begin(9600);
Serial.println("Serial initialized");
err = HSS.init();
if(OK!=err)
{
Serial.println("Initialization failed!");
}
else
Serial.println("Initialization successful!");
}
Errorcodes that could possibly be returned are:
OK
:
No error
INTF_ERROR
: Interface error
CONF_ERROR
: Configuration error
READ_ERROR
: Read error
WRITE_ERROR
: Write error
NULLPTR_ERROR
: Null pointer error
INVALID_CH_ERROR
: Invalid channel error
UNSUPPORTED_OP_ERROR
: Invalid channel error
INIT_ERROR
: Not initialized
Now that the setup is fully done, we have the option to actually control the switch channels and check the diagnostics of our channels. For our high side switch channel control, we have two main functions, which are the switchesHxOn(bool out1= false, bool out2= false, bool out3= false, bool out4= false)
and switchesHxOff(bool out1= false, bool out2= false, bool out3= false, bool out4= false)
.
Those two functions take in 4 values (either 0s or 1s / true or false) that indicate their target channels of operation. You could also switch on/off a single channel at a time by using either the switchHxOff()
or the switchHxOn()
functions, where both take in the target output channel number.
The following code snippet turns all the shield channels on for three seconds and then turns them off again for three consecutive seconds.
void loop(){
HSS.switchesHxOn(1,1,1,1);
delay(3000);
HSS.switchesHxOff(1,1,1,1);
delay(3000);
}
Diagnostics:The MVP function of our library for diagnosis is the readDiagx(uint8_t x) function. This function returns a DiagStatus_t type value. It takes in a number from 1 to 4 which represents the output channel number.
The returned diagnosis status could be:
DIAG_READ_ERROR:
Read Error
NOT_ENABLED:
Diagnosis not enabled
NORMAL
Switch works correctly
FAULT
: Switch is in fault condition (Is_fault at IS pin), which can mean “Short to GND”, “Overtemperature” or “Overload”
FAULT_OL_IC:
Switch is either in Open Load (whit enable channel) or inverse current is flowing
SHORT_TO_GND_OR_OT:
Short to the ground or Overtemperature detected
SHORT_TO_VSS:
Short to the supply voltage
OPEN_LOAD:
Open load detected
Another diagnostics feature is Infineon's current sense feature, which allows us to find out the value of the current flowing through our load. The function in charge of reading the current is readIsx()
. The readIsx()
function returns the value of the current in the form of a float in the unit of Amperes.
To add more to the bargain, the readVss()
function reads the voltage over at the vBAT pin (check the diagram above) and returns it in the unit of volts in the form of a float.
The following code snippet is taken from the BTS700x-hss-advanced code example snippet from the library. The custom function getSwitchParams() has three built in custom functions that each serve to provide diagnostic information using the functions mentioned in this section:
void getSwitchParams(int switch_no)
{
Serial.println("Reading the current, battery voltage and diagnosis status of switch ...");
/** Read current value */
readCurrent(switch_no);
/** Get diagnosis result */
readDiagnosis(switch_no);
/** Read battery voltage */
readBatteryVoltage();
}
/**
* @brief Read current flowing through the switch
* @param switch_no Switch number
*/
void readCurrent(int switch_no)
{
float readAmps = 0.0;
readAmps = HSS.readIsx(switch_no);
Serial.print("Current flowing through the switch: ");
Serial.print(readAmps);
Serial.println(" A");
return;
}
/**
* @brief Read diagnosis status of the switch
* @param switch_no Switch number
*/
void readDiagnosis(int switch_no)
{
DiagStatus_t switchStatus;
for(int i = 0; i<10; i++){
switchStatus = HSS.readDiagx(switch_no); // Read the diagnosis function more than once to make sure the IS value is correct (internal exponential filter)
}
if(switchStatus == OPEN_LOAD)
{
Serial.println("Openload detected!");
}
if(switchStatus == FAULT)
{
Serial.println("Short circuit to ground detected, Overtemperature or Overload detected!");
}
if(switchStatus == FAULT_OL_IC)
{
Serial.println("Open load with active switch or inverse current detected!");
}
if(switchStatus == SHORT_TO_VSS)
{
Serial.println("Short circuit to Vss detected!");
}
if(switchStatus == NORMAL)
{
Serial.println("Normal operation!");
}
return;
}
/**
* @brief Reads the current battery voltage
*/
void readBatteryVoltage()
{
float batteryVoltage = 0.0;
for(int i = 0; i<10; i++){
batteryVoltage = HSS.readVss(); // Measure more than once to make use of the internal exponential filter
}
Serial.print("Current battery voltage : ");
Serial.print(batteryVoltage);
Serial.println(" V");
return;
}
Using the shield's button featureThe option to solder an SMD push button at the placeholder S1 is also available. Additionally, a resistor(RS1= 82 kOhm) and a capacitor (CS1 = 100 nF) are required to debounce the switch. Moreover, depending on the jumper J2/J3 setting, the push button is available either on the digital input D2 (P1.4) or on the analog input A0 (P2.6).
Where to use the digital input solder the jumper J3, while to use the analog input solder the jumper J2
You could actually solder Jumper J2 and J3 at the same time, which will allow you to use both the analogReadButton()
and the digitalReadButton()
functions
The following code snippet demonstrates the use of the analogReadButton() and the digitalReadbutton() functions where the Arduino board serially prints "pressed" if the button is being pressed and prints "not pressed" if it is not:
void loop(){
if (HSS.digitalReadButton()){
Serial.println("digital: pressed");
}
else {
Serial.println("digital: not pressed");
}
if (HSS.analogReadButton()){
Serial.println("analog: pressed");
}
else {
Serial.println("analog: not pressed");
}
delay(1000);
}
The LEDs of the shield light up upon the operation of their respective output channel numbers (when you use the HxSwitchesOn/HxSwitchOn functions), however, they do not light up in case of just operating the switch by sending a PWM signal to its pin. To manually control the LEDs: simply send a digital HIGH logic signal to any of the four LED pins.
The following code snippet demonstrates manually this by manually operating the switch of output 3 and at the same time turning the LEDs 1, 2 and 4 ON.
//-------------PIN DEFINITIONS------------------------------
const int IN4 = 3;
const int LED1 = 4;
const int LED2 = 5;
const int DEN1_DEN3 = 6;
const int OLOFF = 7;
const int DEN2_DEN4 = 8;
const int IN1 = 9;
const int IN2 = 10;
const int IN3 = 11;
const int LED3 = 12;
const int LED4 = 13;
const int Button = A0;
const int IS_U1U2 = A2;
const int IS_U3U4 = A3;
//-------------END OF PIN DEFINITIONS------------------------
void setup() {
//------------- PIN MODE SETUP-------------------------------
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
pinMode(Button,INPUT);
pinMode(IS_U1U2,INPUT);
pinMode(IS_U3U4,INPUT);
pinMode(DEN1_DEN3,OUTPUT);
pinMode(DEN2_DEN4,OUTPUT);
pinMode(OLOFF,OUTPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
//-----------------END OF PIN MODE SETUP--------------------
}
void loop(){
analogWrite(IN3,255);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED4,HIGH);
}
For more information check out the BTS7002-1EPP's datasheet and the shield's
Comments
Please log in or sign up to comment.