Serial Wombat Arduino Library
Loading...
Searching...
No Matches
PCB0046_HSD.h
Go to the documentation of this file.
1#pragma once
2/*
3Copyright 2026 Broadwell Consulting Inc.
4
5"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6the United States. See SerialWombat.com for usage guidance.
7
8Permission 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
15The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18THE 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
50{
51public:
55
61
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 {
81 }
82
83 if (!sw0.isLatestFirmware() || !sw1.isLatestFirmware()) {
85 }
86 if (!sw0.isPinModeSupported(PIN_MODE_PWM))
87 {
89 }
90 if (!sw1.isPinModeSupported(PIN_MODE_ANALOGINPUT))
91 {
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 }
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
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
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 }
198 {
199 return (!fault4to7.readPublicData());
200 }
201
202
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
@ PIN_MODE_ANALOGINPUT
(2)
@ PIN_MODE_PWM
(16)
@ SW_ERROR_WRONG_CHIP_FIRMWARE_VERSION
(#52) The Firmware version of the firmware didn't match what was expected by the host.
@ SW_ERROR_UNKNOWN_PIN_MODE
(#3) A Pin mode was indicated that is not avaialble on this model or version of Serial Wombat chip
@ SW_ERROR_WRONG_CHIP_TYPE
(#51) The chip type (04, 08, 18, etc) wasn't what was expected
SerialWombatPWM_18AB output0
Definition PCB0046_HSD.h:60
uint16_t readCurrentFeedbackInstant_mA()
SerialWombatDigitalOutput_18AB selL
Definition PCB0046_HSD.h:58
SerialWombatDigitalOutput_18AB selH
Definition PCB0046_HSD.h:58
bool readChip4to7IsFaulted()
SerialWombatPWM_18AB output4
Definition PCB0046_HSD.h:60
SerialWombatPWM_18AB output3
Definition PCB0046_HSD.h:60
SerialWombatAnalogInput_18AB currentSenseSelector2
Definition PCB0046_HSD.h:57
SerialWombatChip sw0
Definition PCB0046_HSD.h:56
SerialWombatPWM_18AB output2
Definition PCB0046_HSD.h:60
SerialWombatPWM_18AB output5
Definition PCB0046_HSD.h:60
int16_t selectCurrentFeedbackChannel(uint8_t ch)
SerialWombatPWM_18AB output1
Definition PCB0046_HSD.h:60
SerialWombatAnalogInput_18AB currentSenseSelector1
Definition PCB0046_HSD.h:57
SerialWombatDigitalInput_18AB fault4to7
Definition PCB0046_HSD.h:59
uint16_t readVin_mV()
SerialWombatPWM_18AB output6
Definition PCB0046_HSD.h:60
SerialWombatDigitalOutput_18AB diagEn
Definition PCB0046_HSD.h:58
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
SerialWombatDigitalInput_18AB fault0to3
Definition PCB0046_HSD.h:59
SerialWombatPWM_18AB output7
Definition PCB0046_HSD.h:60
SerialWombatChip sw1
Definition PCB0046_HSD.h:56
bool readChip0to3IsFaulted()
SerialWombatAnalogInput_18AB vinMeas
Definition PCB0046_HSD.h:57
SerialWombatPWM_18AB * outputArray[8]
Definition PCB0046_HSD.h:62
uint16_t readCurrentFeedbackAverage_mA()
This class extends SerialWombatAnalogInput with SW18AB specific capabilities.
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Extends the SerialWombatPWM class with SW18AB specific functionality, including SerialWombatAbstractS...