Skip to content

Commit

Permalink
Merge pull request #2 from ramonaoptics/correct_current_calculation
Browse files Browse the repository at this point in the history
Correct the current calculation for the LEDs
  • Loading branch information
hmaarrfk authored Sep 26, 2022
2 parents 0e54e4c + 3e5d2a5 commit 7cda3c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions TLC5957.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,17 @@ void TLC5957::clearLeds()

void TLC5957::getLedCurrents(double* currents, uint16_t* gs)
{

for (int color_channel_index = 0; color_channel_index < COLOR_CHANNEL_COUNT; color_channel_index++)
{
// https://www.ti.com/lit/ds/symlink/tlc5957.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&ts=1648586629571
// Page 8 (Equation 1 & Equation 2)
currents[color_channel_index] = (_maxOutputCurrent * _CC[color_channel_index] / 511 * _BC)
* (gs[color_channel_index] / 0xFFFF);
currents[color_channel_index] = (
_maxOutputCurrent *
(((double)(_CC[color_channel_index])) / 511) *
_gainRatioValues[_BC] *
(((double)(gs[color_channel_index])) / 0xFFFF)
);
}
}

Expand All @@ -238,8 +243,8 @@ double TLC5957::getTotalCurrent()
double totalCurrent = 0;
for (uint8_t color_channel_index = 0; color_channel_index < COLOR_CHANNEL_COUNT; color_channel_index++)
{
double current = (_maxOutputCurrent * (double)_CC[color_channel_index] / 511 * _gainRatioValues[_BC]);
totalCurrent += current * (double)totalCurrent_channel[color_channel_index] / (0xFFFF * total_channels);
double current = (_maxOutputCurrent * ((double)_CC[color_channel_index]) / 511 * _gainRatioValues[_BC]);
totalCurrent += current * ((double)(totalCurrent_channel[color_channel_index]) / 0xFFFF);
}

return totalCurrent;
Expand Down
2 changes: 1 addition & 1 deletion TLC5957.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class TLC5957
const double _gainRatioValues[8] = {0.129, 0.256, 0.379, 0.524, 0.647, 0.733, 0.917, 1.0};
// TODO: I_OLCMAX set by R_IREF resistor
// TODO: think of more descriptive var name there are so many different "maxCurrents" ..
const double _maxOutputCurrent = 25; // placeholder
const double _maxOutputCurrent = 25E-3; // placeholder

// SPI
SPISettings mSettings;
Expand Down

0 comments on commit 7cda3c4

Please sign in to comment.