@@ -52,8 +52,23 @@ func (a *ADC) Configure(config ADCConfig) {
52
52
// TODO: return an error, will that interfere with any interfaced if one will be?
53
53
}
54
54
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
57
72
if config .SampleTime <= 3 { // <= 10kΩ
58
73
configVal |= nrf .SAADC_CH_CONFIG_TACQ_3us << nrf .SAADC_CH_CONFIG_TACQ_Pos
59
74
} else if config .SampleTime <= 5 { // <= 40kΩ
@@ -100,8 +115,8 @@ func (a *ADC) Configure(config ADCConfig) {
100
115
nrf .SAADC .CH [0 ].CONFIG .Set (configVal )
101
116
}
102
117
103
- func (a ADC ) Get () uint16 {
104
118
// Get returns the current value of an ADC pin in the range 0..0xffff.
119
+ func (a * ADC ) Get () uint16 {
105
120
var pwmPin uint32
106
121
var rawValue volatile.Register16
107
122
0 commit comments