mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-21 12:59:04 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
e82f595f37
commit
868812717f
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user