@@ -170,44 +170,7 @@ The ADCAll Object
170170 The default value is 0xffffffff which means all analog inputs are active. If just the internal
171171 channels (16..18) are required, the mask value should be 0x70000.
172172
173- It is possible to access channle 16..18 values without incurring the side effects of ``ADCAll ``::
174-
175- def adcread(chan): # 16 temp 17 vbat 18 vref
176- assert chan >= 16 and chan <= 18, 'Invalid ADC channel'
177- start = pyb.millis()
178- timeout = 100
179- stm.mem32[stm.RCC + stm.RCC_APB2ENR] |= 0x100 # enable ADC1 clock.0x4100
180- stm.mem32[stm.ADC1 + stm.ADC_CR2] = 1 # Turn on ADC
181- stm.mem32[stm.ADC1 + stm.ADC_CR1] = 0 # 12 bit
182- if chan == 17:
183- stm.mem32[stm.ADC1 + stm.ADC_SMPR1] = 0x200000 # 15 cycles
184- stm.mem32[stm.ADC + 4] = 1 << 23
185- elif chan == 18:
186- stm.mem32[stm.ADC1 + stm.ADC_SMPR1] = 0x1000000
187- stm.mem32[stm.ADC + 4] = 0xc00000
188- else:
189- stm.mem32[stm.ADC1 + stm.ADC_SMPR1] = 0x40000
190- stm.mem32[stm.ADC + 4] = 1 << 23
191- stm.mem32[stm.ADC1 + stm.ADC_SQR3] = chan
192- stm.mem32[stm.ADC1 + stm.ADC_CR2] = 1 | (1 << 30) | (1 << 10) # start conversion
193- while not stm.mem32[stm.ADC1 + stm.ADC_SR] & 2: # wait for EOC
194- if pyb.elapsed_millis(start) > timeout:
195- raise OSError('ADC timout')
196- data = stm.mem32[stm.ADC1 + stm.ADC_DR] # clear down EOC
197- stm.mem32[stm.ADC1 + stm.ADC_CR2] = 0 # Turn off ADC
198- return data
199-
200- def v33():
201- return 4096 * 1.21 / adcread(17)
202-
203- def vbat():
204- return 1.21 * 2 * adcread(18) / adcread(17) # 2:1 divider on Vbat channel
205-
206- def vref():
207- return 3.3 * adcread(17) / 4096
208-
209- def temperature():
210- return 25 + 400 * (3.3 * adcread(16) / 4096 - 0.76)
211-
212- Note that this example is only valid for the F405 MCU and all values are not corrected by Vref and
213- factory calibration data.
173+ Example::
174+
175+ adcall = pyb.ADCAll(12, 0x70000) # 12 bit resolution, internal channels
176+ temp = adcall.read_core_temp()
0 commit comments