Skip to content

Commit

Permalink
Config mux to git rid of chatter, add print for Serial terminal
Browse files Browse the repository at this point in the history
Abstract out wire interface, no all 16 cells are functional

Patch to increase NUM_LEDS now that all cells are enabled

Update LDO and Buck DACs to use appropriate wire as well
  • Loading branch information
jimitdoshi210 authored and jimit-mpspace committed Dec 4, 2024
1 parent cd4820c commit 66e4cb8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
41 changes: 22 additions & 19 deletions firmware/src/cell.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "Cell.h"

// Constructor
Cell::Cell(uint8_t mux_channel) : mux_channel(mux_channel) {}
Cell::Cell(uint8_t mux_channel, TwoWire& wire_interface) :
mux_channel(mux_channel), wire(wire_interface) {
// ...
}

// Implementation of public methods
void Cell::init()
Expand All @@ -10,23 +13,23 @@ void Cell::init()
setMuxChannel();

// Initialize DACs
ldo_dac.begin(LDO_ADDRESS);
buck_dac.begin(BUCK_ADDRESS);
ldo_dac.begin(LDO_ADDRESS, &wire);
buck_dac.begin(BUCK_ADDRESS, &wire);

// Initialize ADC
adc.begin(ADC_ADDRESS);
adc.begin(ADC_ADDRESS, &wire);

// Configure GPIO expander
Wire.beginTransmission(0x20);
Wire.write(0x03); // Configuration register
Wire.write(0x00); // Set all pins as output
Wire.endTransmission();
wire.beginTransmission(0x20);
wire.write(0x03); // Configuration register
wire.write(0x00); // Set all pins as output
wire.endTransmission();

// Set the outputs to 0
Wire.beginTransmission(0x20);
Wire.write(0x01); // Configuration register
Wire.write(0x00); // Set all pins as output
Wire.endTransmission();
wire.beginTransmission(0x20);
wire.write(0x01); // Configuration register
wire.write(0x00); // Set all pins as output
wire.endTransmission();
}

void Cell::disable()
Expand Down Expand Up @@ -153,10 +156,10 @@ void Cell::setGPIOState()
{
setMuxChannel();
// Set output relay on P7
Wire.beginTransmission(TCA6408_ADDR);
Wire.write(0x01); // Output register
Wire.write(GPIO_STATE);
Wire.endTransmission();
wire.beginTransmission(TCA6408_ADDR);
wire.write(0x01); // Output register
wire.write(GPIO_STATE);
wire.endTransmission();
}

float Cell::readShuntCurrent()
Expand All @@ -170,7 +173,7 @@ float Cell::readShuntCurrent()

void Cell::setMuxChannel()
{
Wire.beginTransmission(MUX_ADDRESS);
Wire.write(1 << mux_channel);
Wire.endTransmission();
wire.beginTransmission(MUX_ADDRESS);
wire.write(1 << mux_channel);
wire.endTransmission();
}
3 changes: 2 additions & 1 deletion firmware/src/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Cell
{
public:
// Constructor
Cell(uint8_t mux_channel);
Cell(uint8_t mux_channel, TwoWire& wire_interface);

// Public methods
void init();
Expand Down Expand Up @@ -54,6 +54,7 @@ class Cell

// Mux channel
const uint8_t mux_channel;
TwoWire& wire;

// Device instances
Adafruit_MCP4725 ldo_dac;
Expand Down
43 changes: 30 additions & 13 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,29 @@ const int DMM_MUX_PINS[] = {1, 2, 3, 4};
const int DMM_MUX_ENABLE = 5;

// Addressable LEDs
#define NUM_LEDS 16
#define NUM_LEDS 32
CRGB leds[NUM_LEDS];

// Create cells
Cell cell1(0);
Cell cell2(1);
Cell cell3(2);
Cell cell4(3);
Cell cell5(4);
Cell cell6(5);
Cell cell7(6);
Cell cell8(7);
Cell cell1(0, Wire);
Cell cell2(1, Wire);
Cell cell3(2, Wire);
Cell cell4(3, Wire);
Cell cell5(4, Wire);
Cell cell6(5, Wire);
Cell cell7(6, Wire);
Cell cell8(7, Wire);
Cell cell9(0, Wire1);
Cell cell10(1, Wire1);
Cell cell11(2, Wire1);
Cell cell12(3, Wire1);
Cell cell13(4, Wire1);
Cell cell14(5, Wire1);
Cell cell15(6, Wire1);
Cell cell16(7, Wire1);

// Cell array
Cell cells[] = {cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8};
Cell cells[] = {cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10, cell11, cell12, cell13, cell14, cell15, cell16};


void setupLEDs()
Expand Down Expand Up @@ -87,6 +95,13 @@ void setup()
// SPI.setBitOrder(MSBFIRST);
// SPI.setDataMode(SPI_MODE0);

// Setup mux
pinMode(DMM_MUX_ENABLE, OUTPUT);
for (int i = 0; i < 4; i++) {
pinMode(DMM_MUX_PINS[i], OUTPUT);
digitalWrite(DMM_MUX_PINS[i], LOW);
}

delay(1000);

// Initialize cells
Expand All @@ -101,13 +116,15 @@ void setup()
FastLED.setBrightness(255);
}

float voltage = 2;
float sum = 0.01;
float voltage = 3.5;
void loop()
{
for (Cell& cell : cells) {
cell.setVoltage(voltage);
USBSerial.println(cell.getVoltage());
}

updateStatusLEDs(cells, 8);
updateStatusLEDs(cells, sizeof(cells) / sizeof(cells[0]));

delay(1000);
}

0 comments on commit 66e4cb8

Please sign in to comment.