element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Faster A to D for Arduino!
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: YT2095
  • Date Created: 1 Mar 2012 11:07 AM Date Created
  • Views 529 views
  • Likes 1 like
  • Comments 1 comment
Related
Recommended

Faster A to D for Arduino!

YT2095
YT2095
1 Mar 2012

Having done a few blogs about A to D, D to A conversions, but focused mainly on the UNO32 board, I realised that I`v perhaps alienated a large chunk of people (very Naughty of me!), and so I`v turned my attention to the Arduino and it`s A to D audio capacities (or lack of without modification).

turns out it`s really quite simple as there`s no delay to mess about with unlike the UNO32 IDE.

for the Arduino it`s simply a case of altering the sample Prescaler, it`s default is set to 128, this is really rubbish! sorry and all that, but it is image

oddly there`s nothing in the Wiring_Analog.C file to alter unlike the Unos.

for the Arduino it`s in (here`s my pathway): Desktop\arduino-0022\hardware\arduino\cores\arduino  and then look for a file called "wiring.C"

again, as before Make a back-up of this file and hide it somewhere!

then open the original wiring.C file in Notepad, use full screen then scroll right the way down to the bottom, and look about a third of the way up and find:

 

#if defined(ADCSRA)

    // set a2d prescale factor to 128

    // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.

    // XXX: this will not work properly for other clock speeds, and

    // this code should use F_CPU to determine the prescale factor.

    sbi(ADCSRA, ADPS2);

    sbi(ADCSRA, ADPS1);

    sbi(ADCSRA, ADPS0);

 

this little bit of code sets your prescaler, change the last 2 lines to:

 

sbi(ADCSRA, ADPS2);

cbi(ADCSRA, ADPS1);

cbi(ADCSRA, ADPS0);

 

yeah, you turn the `s` to a `c`, then save the file. and that`s it, you now have a prescaler of only 32 (4X faster).

this will work perfectly for simple Audio work with an R2R ladder D to A convertor, I use this Huge peice of code on my Arduino Nano as a simple pass-through:

 

void setup()              

{

  DDRD = B11111111;

}

void loop() {

  PORTD = (analogRead(0)>>1);   

}

 

digital pins D0 to D7 are used, LSB to MSB respectively.

 

although it is possible to take it faster, the results are likely to be flaky at best, I have yet to try this prog in ZED, where the 328p chips are running 25MHz (yes a genuine Atmel chip will go this fast, but you can forget serial coms etc...).

I`v also not tried this with PWM D to A either, in fact I`v never even tried PWM for anything yet other than servos.

also don`t panic about the fact that pins D0 and D1 (rx-tx) are used, if you built the R2R D to A with the 74HCT245 buffer chip as I did in mine a few blogs ago, the input impedance is so high, it`s completely ignored! and the fact your hitting PORT D will make no difference either, you can still upload and alter your programs via USB without having to pull 2 wires out every time image

 

so I hope I`m forgiven now for overlooking the Arduino community, I just get a bit carried away sometimes.

(Wife`s thinking; `I wish someone Would carry him away!`)

 

Have Phun image

  • Sign in to reply
Parents
  • fustini
    fustini over 13 years ago

    Interesting tip, I'll have to try when I need higher sampling speed.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • fustini
    fustini over 13 years ago

    Interesting tip, I'll have to try when I need higher sampling speed.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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