Finding my way to adc_config struct

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Writing my first SAM project. For some time I have been trying to find the way to setup the ADC. But I had a hard time to find the right way to do it. Googling results in many hits that I think is outdated. I have a D20 explained board so I tried to create example projects but still it wasn't easy.

Finally I found the definition of the adc_config struct, down in the adc_feature.h. I was browsing around everythere si I can't even say how I ended up there.

 

So, to avoid similar problem next time, what is the normal/best way in the documentation/help files to find those structures and how to use them? I have understand that just as XMEGA such structures are the standard methos for storing settings for peripherals.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hej!

bengtr wrote:
But I had a hard time to find the right way to do it

There is not really a single right way. The only definitely wrong way is if you end up recreating the register definitions yourself. If you create a plain project  ("GCC C executable project") you get these from, e.g.,

...Atmel\Studio\7.0\Packs\Atmel\SAMD20_DFP\1.2.91\samd20\include\instance\adc.h (register definitions)

...Atmel\Studio\7.0\Packs\Atmel\SAMD20_DFP\1.2.91\samd20\include\component\adc.h (register structure mapping)

In a ASF 3 project (which is what you get if you make an example like "Quick Start for the SAM ADC driver...") you have the same files included in the project under src\ASF\sam0\utils\cmsis.

It is certainly possible to write code just based on these cmsis files and the data sheet (basically making your own drivers).

 

But if you have a ASF 3 example or when starting from scratch with a ASF project you will find API documentation linked from both ASF Wizard and ASF Explorer.

The newer framework ASF 4 (atmel start) at http://start.atmel.com/ has docs linked from the Help menu.

 

Finally there is never any real need to blindly browse looking for definitions, select a symbol and do Alt+G (or goto definition from the right click menu) or Ctrl+Shift+F (find in files).
/Lars

 

Last Edited: Thu. Mar 29, 2018 - 12:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm with Lajon.

Use the search facilities of the IDE you use.

Any decent IDE has search facilities to search through all project files. and can also follow the execution path from function calls into function bodies etc.

Every now and then, spend some extra time in learning how to use your IDE effectively.

Some very usefull features are not always immediately obvious. Don't be afraid to read the manual.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's just that in the Atmel Start Example Projects I have created none of them have used this structure. I was looking for the best or normal method for setting up the ADC for my needs and I think that the structure is what I prefer. For example the "ADC and Power Optimization Solution 1 ADC conversion" goes directly to the registers.

 

By the way, my first post in years and someone from Linköping answers!

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks but I do not think this is an IDE issue. I know how to find my way through the definitions using alt-G and so on but I couldn't find how to set up the ADC. If I just add the ADC driver in an empty project there is no example included and I had problems finding and help of usage of the mentioned structure in the help files. If I open an example project I not seen any who uses that structure.

 

Working directly on the registers is an option but I am used to the XMEGA structure principle and I have understood that the same is standard in CMSIS as well.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I think this is worth another comment for other beginners.

 

I have a code that compiles now. That's good!

I used the adc_config struct which can be found in adc_feature.h

How to use it can half-way be figured out by just reading through all settings.

What I didn't know and failed to find anywhere was that I should start with adc_get_config_defaults(&config_adc). I suppose it must be somewhere in Atmels documentation but that and everything else of how to use it was something I found in this forum.

 

There are basically two places in the documentation I tried to use but failed:

1. Modules/SAM Analog-to-Digital Converter (ADC) Driver.

2. Related Pages/Quickstart guide for SAM ADC driver.

 

1st refer to a struct adc_module type which consist of a *const module_inst. That in turn leads to adc_setup which leads to adc_init. There, finally I find the adc_config struct but there it stops. I can't find anything about it in the ASF documentation. There isn't even any match if I search for it.

2nd refers to specific functions for each and every of the ADC settings.

 

Maybe I am looking in the wrong place but for me this was very complicated and I am worried that I will have the same type of problem for each driver I want to use.

 

The resulting code that I used is very simple and easy to understand so no problem there. If it works, I haven't tested it yet. This is how my ADC setup looks like:

 

#include <adc.h>

 

struct adc_config config_adc;

 

adc_get_config_defaults(&config_adc);

config_adc.clock_prescaler = ADC_CLOCK_PRESCALER_DIV8;

config_adc.positive_input  = ADC_POSITIVE_INPUT_PIN13;

config_adc.reference       = ADC_REFERENCE_INTVCC0;

config_adc.resolution      = ADC_RESOLUTION_12BIT;

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.