Skip to content

Commit 0b05676

Browse files
committed
Reduced I2C clock when talking to atMega on miniscope
- Only set reduced (80 kHz) I2C clock when talking to the atMega, which has a bit-banged implementation - For the rest of the chips, reset to to 200 kHz, which seems to provide max sampling on BNO while maintaining reliability
1 parent 21d7b21 commit 0b05676

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

OpenEphys.Onix1/ConfigureUclaMiniscopeV4.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ namespace OpenEphys.Onix1
2222
/// </remarks>
2323
public class ConfigureUclaMiniscopeV4 : MultiDeviceFactory
2424
{
25-
26-
const double MaxVoltage = 5.6;
25+
const double MaxVoltage = 5.7;
2726

2827
PortName port;
2928
readonly ConfigureUclaMiniscopeV4PortController PortControl = new();
@@ -158,7 +157,6 @@ override protected bool CheckLinkState(DeviceContext device)
158157
const int FailureToWriteRegister = -6;
159158
try
160159
{
161-
ConfigureUclaMiniscopeV4Camera.ConfigureSerializer(ds90ub9x);
162160
ConfigureUclaMiniscopeV4Camera.ConfigureCameraSystem(ds90ub9x, Camera.FrameRate, Camera.InterleaveLed);
163161
}
164162
catch (ONIException ex) when (ex.Number == FailureToWriteRegister)
@@ -173,7 +171,7 @@ override protected bool CheckLinkState(DeviceContext device)
173171

174172
bool CheckLinkStateWithRetry(DeviceContext device)
175173
{
176-
const int TotalTries = 10;
174+
const int TotalTries = 5;
177175
for (int i = 0; i < TotalTries; i++)
178176
{
179177
if (CheckLinkState(device))

OpenEphys.Onix1/ConfigureUclaMiniscopeV4Camera.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,26 @@ internal static void ConfigureDeserializer(DeviceContext device)
204204
i2cAlias = UclaMiniscopeV4.Max14574Address << 1;
205205
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.SlaveID3, i2cAlias);
206206
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.SlaveAlias3, i2cAlias);
207+
208+
// Nominal I2C rate for miniscope
209+
Set200kHzI2C(device);
210+
}
211+
212+
static void Set80kHzI2C(DeviceContext device)
213+
{
214+
DS90UB9x.Set933I2CRate(device, 80e3); // Empirical data for reliably communication with atMega
207215
}
208216

209-
internal static void ConfigureSerializer(DeviceContext device)
217+
static void Set200kHzI2C(DeviceContext device)
210218
{
211-
DS90UB9x.Set933I2CRate(device, 80e3); //This is an arbitrary value that is proven to work, we need to test speed vs reliability vs bno sampling speed
219+
DS90UB9x.Set933I2CRate(device, 200e3); // This allows maximum rate bno sampling
212220
}
213221

214222
internal static void ConfigureCameraSystem(DeviceContext device, UclaMiniscopeV4FramesPerSecond frameRate, bool interleaveLed)
215223
{
224+
// NB: atMega (bit-banded i2c to SPI) requires that we talk slowly
225+
Set80kHzI2C(device);
226+
216227
// set up Python480
217228
var atMega = new I2CRegisterContext(device, UclaMiniscopeV4.AtMegaAddress);
218229
WriteCameraRegister(atMega, 16, 3); // Turn on PLL
@@ -243,6 +254,10 @@ internal static void ConfigureCameraSystem(DeviceContext device, UclaMiniscopeV4
243254

244255
atMega.WriteByte(0x04, (uint)(interleaveLed ? 0x00 : 0x03));
245256
WriteCameraRegister(atMega, 200, shutterWidth);
257+
258+
// NB: interaction with the atMega (bit-banded i2c to SPI) requires that we talk slowly, reset to
259+
// talk to normal chips
260+
Set200kHzI2C(device);
246261
}
247262

248263
static void WriteCameraRegister(I2CRegisterContext i2c, uint register, uint value)
@@ -260,17 +275,23 @@ static void WriteCameraRegister(I2CRegisterContext i2c, uint register, uint valu
260275

261276
internal static void SetLedBrightness(DeviceContext device, double percent)
262277
{
278+
// NB: atMega (bit-banded i2c to SPI) requires that we talk slowly
279+
Set80kHzI2C(device);
263280
var atMega = new I2CRegisterContext(device, UclaMiniscopeV4.AtMegaAddress);
264281
atMega.WriteByte(0x01, (uint)((percent == 0) ? 0xFF : 0x08));
265282

266283
var tpl0102 = new I2CRegisterContext(device, UclaMiniscopeV4.Tpl0102Address);
267284
tpl0102.WriteByte(0x01, (uint)(255 * ((100 - percent) / 100.0)));
285+
Set200kHzI2C(device);
268286
}
269287

270288
internal static void SetSensorGain(DeviceContext device, UclaMiniscopeV4SensorGain gain)
271289
{
290+
// NB: atMega (bit-banded i2c to SPI) requires that we talk slowly
291+
Set80kHzI2C(device);
272292
var atMega = new I2CRegisterContext(device, UclaMiniscopeV4.AtMegaAddress);
273293
WriteCameraRegister(atMega, 204, (uint)gain);
294+
Set200kHzI2C(device);
274295
}
275296

276297
internal static void SetLiquidLensVoltage(DeviceContext device, double voltage)

0 commit comments

Comments
 (0)