I have 4 digits and need to supply a maximum of 15mA per segment, where each segment (RED) needs 2.1V. For example, the refresh rate is 220Hz, hence 55Hz/digit. How can I calculate the value of each of the 8 resistors that will allow me to pass 15mA to each segment during the time the segment is lit?
I am asking this because I have a lot of 82R resistors and I wanted to use them, what is the safe refresh rate that will yield 15mA/segment consumption. Vcc is 5V, of course.
Necessary part of the code is shown for reference
//common anode or common cathode //this will save 2 bytes, no need to use //bitwise NOT operation later on //1 --> common anode //0 --> common cathode #define CA 1 volatile unsigned int val = 0; #if CA unsigned char digits[] = { ~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f), // 0 ~(SEG_b|SEG_c), // 1 ~(SEG_a|SEG_b|SEG_d|SEG_e|SEG_g), // 2 ~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_g), // 3 ~(SEG_b|SEG_c|SEG_c|SEG_f|SEG_g), // 4 ~(SEG_a|SEG_c|SEG_d|SEG_f|SEG_g), // 5 ~(SEG_a|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g), // 6 ~(SEG_a|SEG_b|SEG_c), // 7 ~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g), // 8 ~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_f|SEG_g), // 9 }; #else unsigned char digits[] = { (SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f), // 0 (SEG_b|SEG_c), // 1 (SEG_a|SEG_b|SEG_d|SEG_e|SEG_g), // 2 (SEG_a|SEG_b|SEG_c|SEG_d|SEG_g), // 3 (SEG_b|SEG_c|SEG_c|SEG_f|SEG_g), // 4 (SEG_a|SEG_c|SEG_d|SEG_f|SEG_g), // 5 (SEG_a|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g), // 6 (SEG_a|SEG_b|SEG_c), // 7 (SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g), // 8 (SEG_a|SEG_b|SEG_c|SEG_d|SEG_f|SEG_g), // 9 }; #endif ISR(TIMER0_COMP_vect) { //turn off all digits CA_PORT &= 0xF0; unsigned char cnt = 0; if ( val == 0) cnt = 1; static unsigned char active_digit = 0; unsigned char digit_val[4] = {0, 0, 0, 0}; // NUMBER OF DIGITS unsigned int tmp; //extract each digit's value tmp = val; // necessary to prevent modifying val variable while (tmp > 0) { digit_val[cnt++] = tmp % 10; tmp /= 10; } /* Leading zeros suppresion cnt from above calculation can tell us how many digits should be lit without using if statement */ active_digit = ++active_digit % cnt; SEGMENT_PORT = digits[digit_val[ active_digit]]; //turn corresponding digit on CA_PORT |= (0x01 << active_digit); };