nrf: add sample time to ADC
This is important for inputs with a high input resistance. In those cases, the sample time needs to be longer.
Этот коммит содержится в:
родитель
e82f595f37
коммит
868812717f
2 изменённых файлов: 17 добавлений и 1 удалений
|
@ -9,4 +9,5 @@ type ADCConfig struct {
|
|||
Reference uint32 // analog reference voltage (AREF) in millivolts
|
||||
Resolution uint32 // number of bits for a single conversion (e.g., 8, 10, 12)
|
||||
Samples uint32 // number of samples for a single conversion (e.g., 4, 8, 16, 32)
|
||||
SampleTime uint32 // sample time, in microseconds (µs)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ func (a ADC) Configure(config ADCConfig) {
|
|||
var configVal uint32 = nrf.SAADC_CH_CONFIG_RESP_Bypass<<nrf.SAADC_CH_CONFIG_RESP_Pos |
|
||||
nrf.SAADC_CH_CONFIG_RESP_Bypass<<nrf.SAADC_CH_CONFIG_RESN_Pos |
|
||||
nrf.SAADC_CH_CONFIG_REFSEL_Internal<<nrf.SAADC_CH_CONFIG_REFSEL_Pos |
|
||||
nrf.SAADC_CH_CONFIG_TACQ_3us<<nrf.SAADC_CH_CONFIG_TACQ_Pos |
|
||||
nrf.SAADC_CH_CONFIG_MODE_SE<<nrf.SAADC_CH_CONFIG_MODE_Pos
|
||||
|
||||
switch config.Reference {
|
||||
|
@ -54,6 +53,22 @@ func (a ADC) Configure(config ADCConfig) {
|
|||
// TODO: return an error
|
||||
}
|
||||
|
||||
// Source resistance, according to table 89 on page 364 of the nrf52832 datasheet.
|
||||
// https://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.4.pdf
|
||||
if config.SampleTime <= 3 { // <= 10kΩ
|
||||
configVal |= nrf.SAADC_CH_CONFIG_TACQ_3us << nrf.SAADC_CH_CONFIG_TACQ_Pos
|
||||
} else if config.SampleTime <= 5 { // <= 40kΩ
|
||||
configVal |= nrf.SAADC_CH_CONFIG_TACQ_5us << nrf.SAADC_CH_CONFIG_TACQ_Pos
|
||||
} else if config.SampleTime <= 10 { // <= 100kΩ
|
||||
configVal |= nrf.SAADC_CH_CONFIG_TACQ_10us << nrf.SAADC_CH_CONFIG_TACQ_Pos
|
||||
} else if config.SampleTime <= 15 { // <= 200kΩ
|
||||
configVal |= nrf.SAADC_CH_CONFIG_TACQ_15us << nrf.SAADC_CH_CONFIG_TACQ_Pos
|
||||
} else if config.SampleTime <= 20 { // <= 400kΩ
|
||||
configVal |= nrf.SAADC_CH_CONFIG_TACQ_20us << nrf.SAADC_CH_CONFIG_TACQ_Pos
|
||||
} else { // <= 800kΩ
|
||||
configVal |= nrf.SAADC_CH_CONFIG_TACQ_40us << nrf.SAADC_CH_CONFIG_TACQ_Pos
|
||||
}
|
||||
|
||||
// Configure channel 0, which is the only channel we use.
|
||||
nrf.SAADC.CH[0].CONFIG.Set(configVal)
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче