Code sequence required or recommended

Is there perhaps a better way to access the power of the Teensy 3.6?

This question is an unusual one. The entire purpose of the TeensyDuino core and libraries is to access the power of the Teensy. Even if you want to write 100% of your own code, you seem to be under the impression that step 1 would be to prevent the default configuration that occurs within the Teensy core. That is not correct. In general, you can override any of the default configuration using your own code, and call that code from setup() and loop(). May I suggest that instead of trying to understand every line of code that occurs before entry to setup(), that you focus on whatever it is you want to do. It's extremely difficult to learn about any microcontroller (or anything, for that matter) without having an objective. For example, if you want to use the ADC, you can (a) use the ADC support that is built in to the Teensy core, or (b) you can use the more full-featured ADC library by pedvide, or (c) you can write your own low level routines to configure and use the ADC peripheral. Even if what you want to do is (c), you would be wise to study (a) and (b), along with the manual. The same would be true for timers, uarts, pwm, digital i/o, dma, etc.
 
PJRC code optimized as possible for general use supporting all the hardware presented, where time allowed, and the need was present. Unless there is something specific going against that as needed, best to use the device as programmed until issues arise.

If there is an issue with use, check the forum and post, or work to a resolution as needed. Pointing such things out as blocking is what gets special case stuff resolved.

Otherwise, it is just C/cpp code that works, meeting the spec of Arduino functions, and beyond as the hardware allows. The hardware bus types have support in some fashion to use existing libraries for many other devices.
 
Neither ADC0_CFG1 nor ADC1_CFG1 are changed in either mk20dx128.c or kinetis.h.

In particular, I would like to know where they are changed from their reset values of 0x0.

If you do a simple text search on the core library files, you'll find the only files with "ADC0_CFG1" are kinetis.h (where it is defined) and analog.c.

Many programs exist to do text search. I personally use "grep" from command line on Linux, sometimes in combination with shell command syntax using other command line tools like "find". I'm sure a number of people here who use Windows or MacOS can recommend graphical programs without the steep Unix learning curve.

You can also use search on GitHub. From any of any core library repository page, just type ADC0_CFG1 in the search box at the top of the page. Then click the "In this repository" button.

screenshot.png

Sometimes simple text search isn't good enough, like when complex data structures, pointers, and abstraction layers are used. Some programmers love that stuff and create enormous code, but I generally prefer to keep things simple & small using the original register names as much as possible. So at least for the Teensy core library and many of the libraries for Teensy, you can quickly answer these sorts of questions if you use text search tools.
 
To explain a bit more about a detail you won't (easily) find so explicit in the code, the ADC has a self calibration process. NXP's reference manual documents this. But exactly how long the calibration takes isn't so clear, though we can assume it requires some time.

You can find the _init_Teensyduino_internal_() function is called near the end of mk20dx128.c. It in turn calls analog_init(). Part of the rationale is to start the ADC calibration early. By the time setup() runs, or C++ constructors run user level code, hopefully the ADC calibration will be completed, or have done as much of its work as possible, so we minimize the wait needed to actually use analogRead().

So the initialization isn't just merely writing certain bits within a config register. The analog hardware does some sort of internal analog self calibration and sets up its internal state to give the full analog performance.
 
joepasquariello - I apologize for creating the impression that I necessarily want to override the default configuration in the Teensy core. Rather, I want to understand the starting configuration, so I know what to expect. I have gotten wrapped around the axle in my quest to understand the machinery under the hood. I will henceforth focus on my project goal using the provided support, consider the wisdom of others to the extent I can grasp it, and continuing referring to the published NXP material.

defragster - I have likely invented problems for myself. I will focus on addressing problems if they arise and not expect that they will arise.

PaulStoffregen - 1. The suggestion of searching in the GitHub repository is one I had not considered and will use. 2. That the ADC system requires calibration time was something I knew but did not know how to handle. That the initialization is very likely to address this is useful information.

Thanks all.
 
Back
Top