@@ -52,8 +52,23 @@ func (a *ADC) Configure(config ADCConfig) {
5252 // TODO: return an error, will that interfere with any interfaced if one will be?
5353 }
5454
55- // Source resistance, according to table 89 on page 364 of the nrf52832 datasheet.
56- // https://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.4.pdf
55+ var resolution uint32
56+ switch config .Resolution {
57+ case 8 :
58+ resolution = nrf .SAADC_RESOLUTION_VAL_8bit
59+ case 10 :
60+ resolution = nrf .SAADC_RESOLUTION_VAL_10bit
61+ case 12 :
62+ resolution = nrf .SAADC_RESOLUTION_VAL_12bit
63+ case 14 :
64+ resolution = nrf .SAADC_RESOLUTION_VAL_14bit
65+ default :
66+ resolution = nrf .SAADC_RESOLUTION_VAL_12bit
67+ }
68+ nrf .SAADC .RESOLUTION .Set (resolution )
69+
70+ // Source resistance, according to table 41 on page 676 of the nrf52832 datasheet.
71+ // https://docs-be.nordicsemi.com/bundle/ps_nrf52840/attach/nRF52840_PS_v1.11.pdf?_LANG=enus
5772 if config .SampleTime <= 3 { // <= 10kΩ
5873 configVal |= nrf .SAADC_CH_CONFIG_TACQ_3us << nrf .SAADC_CH_CONFIG_TACQ_Pos
5974 } else if config .SampleTime <= 5 { // <= 40kΩ
@@ -100,8 +115,8 @@ func (a *ADC) Configure(config ADCConfig) {
100115 nrf .SAADC .CH [0 ].CONFIG .Set (configVal )
101116}
102117
103- func (a ADC ) Get () uint16 {
104118// Get returns the current value of an ADC pin in the range 0..0xffff.
119+ func (a * ADC ) Get () uint16 {
105120 var pwmPin uint32
106121 var rawValue volatile.Register16
107122
0 commit comments