Serial Wombat Arduino Library

Loading...
Searching...
No Matches
PCB0046_HSD.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2026 Broadwell Consulting Inc.
4
5"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6 the United States. See SerialWombat.com for usage guidance.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 and/or sell copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25*/
29#include "SerialWombat.h"
30
31
48
49 class PCB0046_HSD_PWM
50{
51 public:
52 PCB0046_HSD_PWM() : sw0(),sw1(),vinMeas(sw1),currentSenseSelector1(sw1),currentSenseSelector2(sw1),selH(sw1),selL(sw1),diagEn(sw1),fault0to3(sw1),fault4to7(sw1),
53 output0(sw0),output1(sw0),output2(sw0),output3(sw0),output4(sw0),output5(sw0),output6(sw0),output7(sw0)
54 {}
55
56 SerialWombatChip sw0,sw1;
57 SerialWombatAnalogInput_18AB vinMeas,currentSenseSelector1,currentSenseSelector2;
58 SerialWombatDigitalOutput_18AB selH,selL,diagEn;
59 SerialWombatDigitalInput_18AB fault0to3,fault4to7;
60 SerialWombatPWM_18AB output0,output1,output2,output3,output4,output5,output6,output7;
61
62 SerialWombatPWM_18AB* outputArray[8] = { &output0,&output1,&output2,&output3,&output4,&output5,&output6,&output7};
63
64
73 int16_t begin(uint8_t i2cAddress)
74 {
75 sw0.begin(Wire, i2cAddress, false);
76 sw1.begin(Wire, i2cAddress + 1, false);
77
78 if (!sw0.isSW08())
79 {
80 return SW_ERROR_WRONG_CHIP_TYPE;
81 }
82
83 if (!sw0.isLatestFirmware() || !sw1.isLatestFirmware()) {
84 return SW_ERROR_WRONG_CHIP_FIRMWARE_VERSION;
85 }
86 if (!sw0.isPinModeSupported(PIN_MODE_PWM))
87 {
88 return SW_ERROR_UNKNOWN_PIN_MODE;
89 }
90 if (!sw1.isPinModeSupported(PIN_MODE_ANALOGINPUT))
91 {
92 return SW_ERROR_UNKNOWN_PIN_MODE;
93 }
94 vinMeas.begin(1);
95 currentSenseSelector1.begin(4);
96 currentSenseSelector2.begin(3);
97 diagEn.begin(2,HIGH);
98 selL.begin(0,LOW);
99 selH.begin(6,LOW);
100 fault0to3.begin(7,true);
101 fault4to7.begin(5,true);
102
103
104 for (int i = 0; i < 8; ++i)
105 {
106 outputArray[i]->begin((uint8_t)i);
107 outputArray[i]->writeFrequency_Hz(800); // Make different than 1mS Analog sample time
108 }
109 return (0);
110 }
111 int16_t selectCurrentFeedbackChannel(uint8_t ch)
112 {
113 switch (ch)
114 {
115 case 0:
116 case 4:
117 {
118 selH.high();
119 selL.high();
120 }
121 break;
122 case 1:
123 case 5:
124 {
125 selH.high();
126 selL.low();
127 }
128 break;
129 case 2:
130 case 6:
131 {
132 selH.low();
133 selL.high();
134 }
135 break;
136 case 3:
137 case 7:
138 {
139 selH.low();
140 selL.low();
141 }
142 break;
143 default:
144 return -1;
145
146 }
147
148 selectedFeedbackChannel = ch;
149 return 0;
150 }
151
152 uint16_t readCurrentFeedbackAverage_mA()
153 {
154 uint32_t mV;
155
156 if (selectedFeedbackChannel >= 4)
157 {
158 mV = currentSenseSelector1.readAveraged_mV();
159 }
160 else
161 {
162 mV = currentSenseSelector2.readAveraged_mV();
163 }
164
165 // mv = mA * 100 ohms
166 // mA = mV / 100
167 // Actual mA is 300 times this due to current mirror factor in chip
168 // ma = mV * 300 / 100
169 // ma = mV * 3
170 mV *= 3;
171
172 return (uint16_t)mV;
173
174 }
175
176 uint16_t readCurrentFeedbackInstant_mA()
177 {
178 uint32_t mV;
179
180 if (selectedFeedbackChannel >= 4)
181 {
182 mV = currentSenseSelector1.readVoltage_mV();
183 }
184 else
185 {
186 mV = currentSenseSelector2.readVoltage_mV();
187 }
188
189 // mv = mA * 100 ohms
190 // mA = mV / 100
191 // Actual mA is 300 times this due to current mirror factor in chip
192 // ma = mV * 300 / 100
193 mV *= 3;
194
195 return (uint16_t)mV;
196 }
197 bool readChip4to7IsFaulted()
198 {
199 return (!fault4to7.readPublicData());
200 }
201
202
203 bool readChip0to3IsFaulted()
204 {
205 return (!fault0to3.readPublicData());
206 }
207
208 uint16_t readVin_mV()
209 {
210 return((uint16_t) (vinMeas.readAveraged_mV() * 11));
211
212 }
213
214 private:
215 uint8_t selectedFeedbackChannel = 0;
216
217
218};
219
SerialWombat.h
PIN_MODE_ANALOGINPUT
@ PIN_MODE_ANALOGINPUT
(2)
Definition SerialWombat.h:263
PIN_MODE_PWM
@ PIN_MODE_PWM
(16)
Definition SerialWombat.h:276
SW_ERROR_WRONG_CHIP_FIRMWARE_VERSION
@ SW_ERROR_WRONG_CHIP_FIRMWARE_VERSION
(#52) The Firmware version of the firmware didn't match what was expected by the host.
Definition SerialWombatErrors.h:77
SW_ERROR_UNKNOWN_PIN_MODE
@ SW_ERROR_UNKNOWN_PIN_MODE
(#3) A Pin mode was indicated that is not avaialble on this model or version of Serial Wombat chip
Definition SerialWombatErrors.h:28
SW_ERROR_WRONG_CHIP_TYPE
@ SW_ERROR_WRONG_CHIP_TYPE
(#51) The chip type (04, 08, 18, etc) wasn't what was expected
Definition SerialWombatErrors.h:76
PCB0046_HSD_PWM::output0
SerialWombatPWM_18AB output0
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::readCurrentFeedbackInstant_mA
uint16_t readCurrentFeedbackInstant_mA()
Definition PCB0046_HSD.h:176
PCB0046_HSD_PWM::selL
SerialWombatDigitalOutput_18AB selL
Definition PCB0046_HSD.h:58
PCB0046_HSD_PWM::selH
SerialWombatDigitalOutput_18AB selH
Definition PCB0046_HSD.h:58
PCB0046_HSD_PWM::readChip4to7IsFaulted
bool readChip4to7IsFaulted()
Definition PCB0046_HSD.h:197
PCB0046_HSD_PWM::output4
SerialWombatPWM_18AB output4
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::output3
SerialWombatPWM_18AB output3
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::currentSenseSelector2
SerialWombatAnalogInput_18AB currentSenseSelector2
Definition PCB0046_HSD.h:57
PCB0046_HSD_PWM::sw0
SerialWombatChip sw0
Definition PCB0046_HSD.h:56
PCB0046_HSD_PWM::output2
SerialWombatPWM_18AB output2
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::output5
SerialWombatPWM_18AB output5
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::selectCurrentFeedbackChannel
int16_t selectCurrentFeedbackChannel(uint8_t ch)
Definition PCB0046_HSD.h:111
PCB0046_HSD_PWM::output1
SerialWombatPWM_18AB output1
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::currentSenseSelector1
SerialWombatAnalogInput_18AB currentSenseSelector1
Definition PCB0046_HSD.h:57
PCB0046_HSD_PWM::fault4to7
SerialWombatDigitalInput_18AB fault4to7
Definition PCB0046_HSD.h:59
PCB0046_HSD_PWM::readVin_mV
uint16_t readVin_mV()
Definition PCB0046_HSD.h:208
PCB0046_HSD_PWM::output6
SerialWombatPWM_18AB output6
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::PCB0046_HSD_PWM
PCB0046_HSD_PWM()
Definition PCB0046_HSD.h:52
PCB0046_HSD_PWM::diagEn
SerialWombatDigitalOutput_18AB diagEn
Definition PCB0046_HSD.h:58
PCB0046_HSD_PWM::begin
int16_t begin(uint8_t i2cAddress)
Initialize a PCB0046_HSD pcb on a given I2C address and the I2C address + 1.
Definition PCB0046_HSD.h:73
PCB0046_HSD_PWM::fault0to3
SerialWombatDigitalInput_18AB fault0to3
Definition PCB0046_HSD.h:59
PCB0046_HSD_PWM::output7
SerialWombatPWM_18AB output7
Definition PCB0046_HSD.h:60
PCB0046_HSD_PWM::sw1
SerialWombatChip sw1
Definition PCB0046_HSD.h:56
PCB0046_HSD_PWM::readChip0to3IsFaulted
bool readChip0to3IsFaulted()
Definition PCB0046_HSD.h:203
PCB0046_HSD_PWM::vinMeas
SerialWombatAnalogInput_18AB vinMeas
Definition PCB0046_HSD.h:57
PCB0046_HSD_PWM::outputArray
SerialWombatPWM_18AB * outputArray[8]
Definition PCB0046_HSD.h:62
PCB0046_HSD_PWM::readCurrentFeedbackAverage_mA
uint16_t readCurrentFeedbackAverage_mA()
Definition PCB0046_HSD.h:152
SerialWombatAnalogInput_18AB
This class extends SerialWombatAnalogInput with SW18AB specific capabilities.
Definition SerialWombatAnalogInput.h:317
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:315
SerialWombatDigitalInput_18AB
Definition SerialWombatDigitalInput.h:28
SerialWombatDigitalOutput_18AB
Definition SerialWombatDigitalOutput.h:28
SerialWombatPWM_18AB
Extends the SerialWombatPWM class with SW18AB specific functionality, including SerialWombatAbstractS...
Definition SerialWombatPWM.h:149