#include "lights.h"
static uint16_t pwm_vals[N_PWMLEDS*N_PWMLED_MODES];
-static uint16_t pwm_max[N_PWMLEDS] = { 0x70, 0x70, 0x1F0 };
-static uint16_t adc_max[N_PWMLEDS] = { 0x70, 0x70, 0xF0 };
+static uint16_t pwm_max[N_PWMLEDS] = {
+ PWM_MAX/2,
+ PWM_MAX - (PWM_MAX >> 4), // step-up
+ PWM_MAX/2
+};
+
+#define PWMLED2_TESTING_WITH_350MA_LED
+
+#define SENSE_MOHM 33 /* 0.033 Ohm */
+#define MA_MOHM_GAIN_TO_ADC(ma, mohm, gain) (\
+ ((unsigned long)(ma))*(mohm) /* voltage at sensing resistor in uV */ \
+ /(1100000UL/gain/1024UL) /* voltage of ADC reading == 1 */ \
+)
+static uint16_t adc_max[N_PWMLEDS] = {
+ MA_MOHM_GAIN_TO_ADC( 400, SENSE_MOHM, 20),
+ MA_MOHM_GAIN_TO_ADC( 30, SENSE_MOHM, 20),
+#ifdef PWMLED2_TESTING_WITH_350MA_LED
+ MA_MOHM_GAIN_TO_ADC( 400, SENSE_MOHM, 1)
+#else
+ MA_MOHM_GAIN_TO_ADC(2500, SENSE_MOHM, 1)
+#endif
+};
static uint16_t adc_vals[N_PWMLEDS*N_PWMLED_MODES] = {
/* pwmled0 */
- 0x04, 0x14, 0x24, 0x38,
+ MA_MOHM_GAIN_TO_ADC( 20, SENSE_MOHM, 20),
+ MA_MOHM_GAIN_TO_ADC( 50, SENSE_MOHM, 20),
+ MA_MOHM_GAIN_TO_ADC( 100, SENSE_MOHM, 20),
+ MA_MOHM_GAIN_TO_ADC( 350, SENSE_MOHM, 20),
/* pwmled1 */
- 0x04, 0x14, 0x24, 0x38,
+ MA_MOHM_GAIN_TO_ADC( 5, SENSE_MOHM, 20),
+ MA_MOHM_GAIN_TO_ADC( 12, SENSE_MOHM, 20),
+ MA_MOHM_GAIN_TO_ADC( 16, SENSE_MOHM, 20),
+ MA_MOHM_GAIN_TO_ADC( 20, SENSE_MOHM, 20),
/* pwmled2 */
- 0x0c, 0x24, 0x48, 0x90,
+#ifdef PWMLED2_TESTING_WITH_350MA_LED
+ MA_MOHM_GAIN_TO_ADC( 100, SENSE_MOHM, 1),
+ MA_MOHM_GAIN_TO_ADC( 140, SENSE_MOHM, 1),
+ MA_MOHM_GAIN_TO_ADC( 250, SENSE_MOHM, 1),
+ MA_MOHM_GAIN_TO_ADC( 350, SENSE_MOHM, 1),
+#else
+ MA_MOHM_GAIN_TO_ADC( 150, SENSE_MOHM, 1),
+ MA_MOHM_GAIN_TO_ADC( 350, SENSE_MOHM, 1),
+ MA_MOHM_GAIN_TO_ADC( 700, SENSE_MOHM, 1),
+ MA_MOHM_GAIN_TO_ADC(2400, SENSE_MOHM, 1),
+#endif
};
// TODO: maybe convert this to bitmask to simplify pwmled_needs_adc() ?