File tree 2 files changed +9
-4
lines changed 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,10 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
74
74
config_adc .reference = ADC_REFERENCE_INTVCC1 ;
75
75
config_adc .gain_factor = ADC_GAIN_FACTOR_DIV2 ;
76
76
config_adc .positive_input = self -> pin -> adc_input ;
77
- config_adc .resolution = ADC_RESOLUTION_16BIT ;
78
- config_adc .clock_prescaler = ADC_CLOCK_PRESCALER_DIV128 ;
77
+ config_adc .resolution = ADC_RESOLUTION_12BIT ;
78
+ // Default input clock is GCLK0 (48 MHz)
79
+ // 48Mhz / 32 = 1.5MHz. Max ADC clock is 2.1MHz
80
+ config_adc .clock_prescaler = ADC_CLOCK_PRESCALER_DIV32 ;
79
81
80
82
struct adc_module adc_instance ;
81
83
// ADC must have been disabled before adc_init() is called.
@@ -108,7 +110,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
108
110
}
109
111
110
112
adc_disable (& adc_instance );
111
- return data ;
113
+ // Scale to 16 bits. In the future we might make this be this be under API control.
114
+ return data * 16 ;
112
115
}
113
116
114
117
float common_hal_analogio_analogin_get_reference_voltage (analogio_analogin_obj_t * self ) {
Original file line number Diff line number Diff line change @@ -111,7 +111,9 @@ STATIC void configure_adc_temp(struct adc_module *adc_instance) {
111
111
// "Discard the first conversion result whenever there is a change
112
112
// in ADC configuration like voltage reference / ADC channel change."
113
113
114
- config_adc .clock_prescaler = ADC_CLOCK_PRESCALER_DIV16 ;
114
+ // Default input clock is GCLK0 (48 MHz)
115
+ // 48Mhz / 32 = 1.5MHz. Max ADC clock is 2.1MHz
116
+ config_adc .clock_prescaler = ADC_CLOCK_PRESCALER_DIV32 ;
115
117
config_adc .reference = ADC_REFERENCE_INT1V ;
116
118
config_adc .positive_input = ADC_POSITIVE_INPUT_TEMP ;
117
119
config_adc .negative_input = ADC_NEGATIVE_INPUT_GND ;
You can’t perform that action at this time.
0 commit comments