See annotated K20P64M72SF1RM manual (MK20DX128 processor used on Teensy 3.1/3.2).
In [142]:
import pandas as pd
# ADC registers memory map on page 651 in `K20P64M72SF1RM.pdf`.
ADC_START_ADDRESS = pd.Series([0x4003B000, 0x400BB000], index=[0, 1])
ADC_REGISTER_MAP = (pd.DataFrame([['SC1A', 0x00000000, 0x0000001F],
['SC1B', 0x00000004, 0x0000001F],
['CFG1', 0x00000008, 0x00000000],
['CFG2', 0x0000000C, 0x00000000],
['RA' , 0x00000010, 0x00000000],
['RB' , 0x00000014, 0x00000000],
['CV1' , 0x00000018, 0x00000000],
['CV2' , 0x0000001C, 0x00000000],
['SC2' , 0x00000020, 0x00000000],
['SC3' , 0x00000024, 0x00000000],
['OFS' , 0x00000028, 0x00000004],
['PG' , 0x0000002C, 0x00008200],
['MG' , 0x00000030, 0x00008200],
['CLPD', 0x00000034, 0x0000000A],
['CLPS', 0x00000038, 0x00000020],
['CLP4', 0x0000003C, 0x00000200],
['CLP3', 0x00000040, 0x00000100],
['CLP2', 0x00000044, 0x00000080],
['CLP1', 0x00000048, 0x00000040],
['CLP0', 0x0000004C, 0x00000020],
['PGA' , 0x00000050, 0x00000000],
['CLMD', 0x00000054, 0x0000000A],
['CLMS', 0x00000058, 0x00000020],
['CLM4', 0x0000005C, 0x00000200],
['CLM3', 0x00000060, 0x00000100],
['CLM2', 0x00000064, 0x00000080],
['CLM1', 0x00000068, 0x00000040],
['CLM0', 0x0000006C, 0x00000020]],
columns=['register_name', 'address_offset',
'reset_value'])
.set_index('register_name'))
def default_adc_reg(adc_num):
ADC_REG = ADC_REGISTER_MAP.copy()
ADC_REG.address_offset += ADC_START_ADDRESS[adc_num]
ADC_REG.rename(columns={'address_offset': 'address', 'reset_value': 'value'}, inplace=True)
return ADC_REG
ADC0_REG = default_adc_reg(0)
ADC1_REG = default_adc_reg(1)
hex(ADC_START_ADDRESS[1] - ADC_START_ADDRESS[0])
Out[142]:
Page 653.
COCO
: Conversion complete flagAIEN
: Interrupt enableDIFF
: Differential mode enableADCH
: 4 bits, Input channel selectThe MK20DX256 processor has two ADC status and control registers. Each register is associated with a pre-trigger in the Programmable Delay Block.
Page 656
ADLPC
: Low-power configurationADIV
: 2 bits, Clock divide selectADLSMP
: Sample time configurationMODE
: 2 bits, Conversion mode selectionADICLK
: 2 bits, Input clock selectPage 658.
MUXSEL
: ADC mux selectADACKEN
: Asynchronous clock output enableADHSC
: High-speed configurationADLSTS
: Long sample time selectPage 661.
ADACT
: Conversion activeADTRG
: Conversion trigger selectACFE
: Compare Function EnableACFGT
: Compare function greater than enableACREN
: Compare function range enableDMAEN
: DMA enableSC1n[COCO]
flags is asserted.REFSEL
: 2 bits, Voltage reference selectionThe startPDB
method sets ADTRG=1
to enable trigger of ADC using Programmable Delay Block.
See "Programmable Delay Block notes" notebook for details.
Voltage reference selection; 0: Default, 1: Alternate, 2-3: Reserved