From 6f12a41cc6fc61d62bfd862f454e63b0652823fc Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 12 Jun 2017 13:03:18 +0200 Subject: Add resistor calculation script --- fw/main.c | 44 +++++++-------- hw/chibi/chibi_2024/rcalc.py | 127 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 22 deletions(-) create mode 100644 hw/chibi/chibi_2024/rcalc.py diff --git a/fw/main.c b/fw/main.c index 6113a10..2e7b56e 100644 --- a/fw/main.c +++ b/fw/main.c @@ -74,32 +74,32 @@ int main(void) { SPI1->CR2 &= ~SPI_CR2_DS_Msk; SPI1->CR2 |= LL_SPI_DATAWIDTH_16BIT; /* FIXME maybe try w/o BIDI */ - SPI1->CR1 = SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_SPE | (1<CR1 = SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_SPE | (0<BSRR = GPIO_BSRR_BR_6; + int j = 0; + int bval = 0x4000; while (42) { - if (i == 8) { - i = 0; - val = ~val; + for (int i=0; i<8; i++) { + spi_send(val); + spi_send(val); + strobe_leds(); + spi_send(0x0200 | bval | (0xff^(1<7.3f}{}{}'.format(name, scaled, prefix, unit), **kwargs) + +r = 1/16 +stages = 3 +mod_r = 1/8 +I_max_led = 0.01 +n_boards = 20 +n_digits_per_board = 8*4 +n_leds = n_boards*n_digits_per_board*8 +V_fw = 1.9 # V + +print('r = 1:{:.0f}'.format(1/r)) + +I_min_led = I_max_led*(r**(stages-1)) # A +I_max_mod = I_max_led/mod_r +I_min_mod = I_min_led/mod_r +print_var('I_max_led', I_max_led, 'A') +print_var('I_max_mod', I_max_mod, 'A') +print_var('I_min_mod', I_min_mod, 'A') +if (I_max_mod > 0.09): + print('\033[91mError: The MBI5026 has a maximum output current of 90mA!\033[0m') + +Vrext = 1.26 # V +# Iout = 15 * Vrext/Rext | acc. to MBI5026 datasheet +R1 = 15*Vrext/I_min_mod +Itot_1 = n_leds * mod_r * I_min_mod +Ptot_1 = Itot_1 * V_fw +print_var('R1', R1, 'Ω', end='\t') +print_var('I1', I_min_mod, 'A', end='\t') +print_var('Itot_1', Itot_1, 'A', end='\t') +print_var('Ptot_1', Ptot_1, 'W') + +for i in range(stages-2, -1, -1): + # Rpar = 15*Vrext/(I_max_mod*r) + # R1||R2 = 1/(1/R1 + 1/R2) =!= Rpar = 15*Vrext/(I_max_mod*r) + # ⇒ 1/R1 + 1/R2 = 1/(15*Vrext/(I_max_mod*r)) + # ⇒ 1/R2 = 1/(15*Vrext/(I_max_mod*r)) - 1/R1 + # ⇒ R2 = 1/((I_max_mod*r)/(15*Vrext) - 1/R1) + In = I_max_mod*(r**i) + Rn = 1/(In/(15*Vrext) - 1/R1) + Itot_n = n_leds * mod_r * In + Ptot_n = Itot_n * V_fw + scaled, prefix = format_unit(Rn) + print_var('R{}'.format(stages-i), Rn, 'Ω', end='\t') + print_var('I{}'.format(stages-i), In, 'A', end='\t') + print_var('Itot_{}'.format(stages-i), Itot_n, 'A', end='\t') + print_var('Ptot_{}'.format(stages-i), Ptot_n, 'W') + -- cgit