#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 */ \
-)
+/*
+ * Voltage in uV at ADC reading == 1 is 1100/gain/1024
+ * ADC module returns sum of 1 << PWMLED_ADC_SHIFT measurements
+ * Voltage in uV measured is current in mA * sense resistance in mOhm
+ */
+#define MA_GAIN_TO_ADC(ma, gain) ((uint16_t) \
+ ((uint32_t)(ma) \
+ * (SENSE_MOHM) \
+ * (1 << (PWMLED_ADC_SHIFT)) \
+ * 1024 \
+ / (1100000/(gain))))
+
+#define PWMLED_TESTING 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)
+#ifdef PWMLED_TESTING
+ MA_GAIN_TO_ADC( 400, 20),
+ MA_GAIN_TO_ADC( 30, 20),
+ MA_GAIN_TO_ADC( 800, 1)
#else
- MA_MOHM_GAIN_TO_ADC(2500, SENSE_MOHM, 1)
+ MA_GAIN_TO_ADC( 900, 20),
+ MA_GAIN_TO_ADC( 30, 20),
+ MA_GAIN_TO_ADC(2500, 1)
#endif
};
static uint16_t adc_vals[N_PWMLEDS*N_PWMLED_MODES] = {
+#ifdef PWMLED_TESTING
/* pwmled0 */
- 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),
+ MA_GAIN_TO_ADC( 50, 20),
+ MA_GAIN_TO_ADC( 150, 20),
+ MA_GAIN_TO_ADC( 250, 20),
+ MA_GAIN_TO_ADC( 350, 20),
/* pwmled1 */
- 16, 32, 64, 112,
-#if 0
- 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),
-#endif
+ MA_GAIN_TO_ADC( 5, 20),
+ MA_GAIN_TO_ADC( 10, 20),
+ MA_GAIN_TO_ADC( 15, 20),
+ MA_GAIN_TO_ADC( 20, 20),
/* pwmled2 */
- 24, 32, 40, 48
-#if 0
-#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),
+ MA_GAIN_TO_ADC( 100, 1),
+ MA_GAIN_TO_ADC( 200, 1),
+ MA_GAIN_TO_ADC( 300, 1),
+ MA_GAIN_TO_ADC( 400, 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
+ /* pwmled0 */
+ MA_GAIN_TO_ADC( 100, 20),
+ MA_GAIN_TO_ADC( 300, 20),
+ MA_GAIN_TO_ADC( 700, 20),
+ MA_GAIN_TO_ADC( 800, 20),
+ /* pwmled1 */
+ MA_GAIN_TO_ADC( 5, 20),
+ MA_GAIN_TO_ADC( 10, 20),
+ MA_GAIN_TO_ADC( 18, 20),
+ MA_GAIN_TO_ADC( 23, 20),
+ /* pwmled2 */
+ MA_GAIN_TO_ADC( 200, 1),
+ MA_GAIN_TO_ADC( 400, 1),
+ MA_GAIN_TO_ADC( 800, 1),
+ MA_GAIN_TO_ADC(1500, 1)
#endif
};