element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Enchanted Objects
  • Challenges & Projects
  • Design Challenges
  • Enchanted Objects
  • More
  • Cancel
Enchanted Objects
Blog Review 7: Atmel SMART SAMA5D4 Xplained Ultra - C++ ADC Example on Linux
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 16 May 2015 2:53 PM Date Created
  • Views 1642 views
  • Likes 3 likes
  • Comments 11 comments
  • enchanted_player
  • enchanted_objects
  • c++
  • xplained_ultra
  • atmel
Related
Recommended

Review 7: Atmel SMART SAMA5D4 Xplained Ultra - C++ ADC Example on Linux

Jan Cumps
Jan Cumps
16 May 2015

I'm making steady progress on this drizzly day.

I have my first C++ linux program running that samples the an ADC pin on the SAMA4D4 Xplained Ultra Board.

 

In the mid 90's, I was a C++ software developer. Around that same time, the standard template library (STL) came into fashion.

It's great to use it once again.

 

image

 

Getting the ADC values

 

Once again, this is inspired by Robert Peter Oakes's work on this board, SAMA5D4 Xplained Ultra - Tips and Tricks #2 - Using the built in IO and external devices.

I'm using a very similar setup as Peter, but instead of using the Linux command line to read the sample results, I've written a C++ program.

But we're both triggering a sample and reading results by accessing /sys/bus/iio/devices/iio:device0/in_voltage0_raw.

 

The schematic is very simple: a potentiometer with both ends connected to ground and 3.3V of the Xplained board. The wiper goes to A1.

To make things funny, A1 is analog port 0 in the linux mapping. (I don't know yet what A0 is, but it has a digital signal on it when I sample it with my scope.)

 

The program is cross-compiled using the GNU toolchain on a windows machine, loaded to the linux root user's home folder, and executed.

It shows a sample result in the terminal window every second.

I haven't used any of the Atmel libraries. All is done via standard file access.

 

#include <iostream>
#include <fstream>

using namespace std;

const char fileName[] = "/sys/bus/iio/devices/iio:device0/in_voltage0_raw";

int main() {
  string line;
  while(1) {
    ifstream myfile(fileName, ios::in);

    if (myfile.is_open()) {
      while (getline (myfile,line)) {
        cout << line << '\n';
      }
      myfile.close();
    } else {
      cout << "Unable to open file " << fileName << "\n";
    }
  }

  return 0;
}

 

That's the whole program. After compilation, linking, uploading and setting the executable flag, here's what it looks like in the terminal:

 

image

 

The value changes when moving the potentiometer wiper.

  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 10 years ago +1
    ... and with this post I'm claiming dibs on being the first among all roadtest and designchallenge contenders who cross-compiled and ran a c program that accesses I/O on this very board . If we find prior…
  • Jan Cumps
    Jan Cumps over 10 years ago in reply to clem57

    clem57, the tests I have done are ok.

    My main goal up till now is to get the board running and being able to do something with it.

    And I finally believe that I'm at the point to start with the board. I now have taken the very first basic basic basic steps.

     

    Now that I know how to create and run programs on Linux and bare metal, I'll be able to appreciate the capabilities of the on-board hardware.

    I've never doubted that this was a great board with more than decent components, but only now it has unlocked it's capabilities to me

    (I think that the learning curve is needlessly [and for Atmel  recklessly] hard. I claim that one person in two weeks can write a manual that would put me where I am now on day 1).

     

    Now that I feel that I'm on the doorstep of what really can be done with the processor and board, it's time to start evaluating the strengths.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 10 years ago

    I like the use of the ADC, How does it perform? Is it worth exploring more?

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 10 years ago

    I have my first bare metal example running !

     

    image

     

    It's not yet one that I compiled myself. That's the next step.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 10 years ago in reply to michaelkellett

    You can talk to the controller and peripherals directly, both in linux and on bare metal. It's just that I lack the skills at this moment to do that.

    I'm close to running my first bare metal example - I got help on this AT91.com forum thread from gopi_atmel: http://www.at91.com/discussions/viewtopic.php/f,33/t,23932/p,45983.html#p45983

     

    The speed using the character devices is acceptable for what I'm doing at this moment: sample mono audio, Hamming window, FFT and drive 3 LEDS.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett over 10 years ago in reply to Jan Cumps

    Thanks for the reference.

    It's a bit sad really - this processor should be much much faster than a CortexM4 with a 180MHz clock but all this software bloat will probably make it chronically slow - it certainly makes setting up the hardware chronically obscure. On an STM32F4xxx once you've set up the DMA it takes no processor instructions at all to get data from an ADC into a circular buffer. This might be the case with the SAMA5 but of course it isn't possible to tell unless you start looking at the driver source code.

    What do you plan ultimately to do with the ADC ?

     

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube