element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • 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
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs Arduino: R-2R: Buffer, Attenuate, and Filter
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jc2048
  • Date Created: 22 Apr 2018 9:22 AM Date Created
  • Views 1797 views
  • Likes 11 likes
  • Comments 7 comments
  • r2r
Related
Recommended

Arduino: R-2R: Buffer, Attenuate, and Filter

jc2048
jc2048
22 Apr 2018

I'm still fiddling around with the R-2R ladder as a DAC on an Arduino. This time some hardware.

 

This isn't a project to be built, instead I'm experimenting with analogue stuff; you're looking over

my shoulder as I get some things right and quite a lot of things wrong. What I've ended up with is

messy and not really the way to do it, but if I blog about it at least you'll be forewarned and in a

position to do it better.

 

I decided that I wanted to be able to control both the frequency and the amplitude of the generated

waveform via SCPI messages. Control of the frequency will be done in the software but there's a limit

to how far I can go with doing the amplitude in software (because the waveform is being generated to

only 8 bits of resolution). So I've come up with a circuit to adjust it in hardware under digital

control. I decided continuous adjustment was too complicated, so I've ended up with a circuit that

uses analogue switches to change the gain of an amplifier. The second bit of hardware I needed was a

filter - this will be a low pass filter that will pass audio frequencies but cut higher frequencies

and have a reasonable level of attenuation by the time we get to the output sample rate (which I'm

provisionally thinking will be something like a few hundred ksps, though the Arduino may not be able

to keep up with that).

 

Here's the circuit as I have it at the moment (the voltage generator on the left is the output of the DAC):

 

image

 

The first bad decision I made was to keep it as simple as possible and use the Arduino +5V for the

supply and to use a very cheap op-amp, the LM324 for the circuit. There's nothing essentially wrong

with the LM324, but the inputs and outputs don't operate up to the rail so that immediately stops me

from buffering the output of the R-2R DAC with a follower. So, instead, the buffer became an inverting

amplifier with fractional gain. That compromises the input resistance a bit, but it's still high

enough that it doesn't load the DAC and affect the resolution. Originally, I was going to have the

variable attenuation after the filter, but realised that I could change the gain of this amplifier

instead and came up with the circuit above where gain resistors are selectively shorted by analogue

switches (the switches on the circuit diagram are really CD4066 analogue switches controlled by A0 to

A3 used as digital outputs).

 

The righthand side is a low-pass filter with the cut-off point somewhere around 20kHz. It's a third-

order low-pass Butterworth filter. The response looks like this in the simulator.

 

image

 

Here's how the circuit board looks at the moment - the chips are underneath and the passives on top. A

bit unconventional but it's quite easy to work with, changing and adding bits. (The R-2R DAC is the neat array

at bottom left, the analogue switches are top left, and the op-amps are bottom right).

 

image

 

Unfortunately, when I came to test it, I discovered that the first op-amp was more than happy to

oscillate. I think the reasons for that are twofold - firstly that it was impossible to get the

feedback path compact because of it straggling all around the analogue switch chip and secondly

because the analogue switches add parasitic capacitance (which I'm obviously not modelling in the

simulation). I managed to quieten it down by adding the 22p; that adds to the internal compensation,

but it's still a bit on edge.

 

Here's an accumulated scope trace that shows the sixteen different gain levels. This is with the

scope's 20MHz filter on (there's quite a lot of high-frequency noise that the output filter doesn't

stop). It works, but if you look just after the point where the traces come together, there's evidence

that the op-amp is on edge and only just holding it.

 

image

 

Anyway, that's where I'm at with the hardware. It's far from perfect - it isn't even something that I

could reasonably present as a project to build - but it will do for the moment and I'm going to go back

to the software and see if I can get the frequency adjustment working under SCPI control. Whilst I'm

doing that I'll consider whether to have another go at the hardware or to call it a day and move on to

something else.

 

Part one: Arduino: R-2R Experiment

Part two: Arduino: R-2R: Sine On You Crazy Diamond

Part three: Arduino: R-2R: Buffer, Attenuate, and Filter

Part four: Arduino: R-2R: "We Interrupt This Programme..."

Part five: Arduino: R-2R: "Resistance is..."?

Part six: Arduino: R-2R: Setting the Output Frequency

Part seven: Arduino: R-2R; "A Sweep is as Lucky, as Lucky Can Be..."

Part eight: Arduino: R-2R: Setting the Signal Amplitude

  • Sign in to reply

Top Comments

  • DAB
    DAB over 5 years ago +4
    Yes, Analog circuits can humble the best engineer. Nice overview of the circuit and your results. Breadboards are notorious for noise and floating grounds, so having the oscillations is par for the course…
  • Jan Cumps
    Jan Cumps over 5 years ago +2
    How did you make the scope trace? looping fast trhrough the 16 levels?
  • jw0752
    jw0752 over 5 years ago +2
    Hi Jon, Thank you for taking the time to post experiments like this. I am always fascinated and your posts are always a learning experience for me. John
  • jc2048
    jc2048 over 5 years ago in reply to Jan Cumps

    They are interesting to experiment with.

     

    This is the internal circuit. You can see the input is a standard CMOS inverter. The switch itself is just a pair of MOSFETs back-to-back, one n-type and one p-type. It's having both that allows it to work from rail to rail (wherever the signal is in that range, at least one of the devices is on). I'm not sure what the bit in the middle is doing - maybe it's to keep crosstalk down when the switch is off.

     

    image

     

    Here's what the resistance looks like when it's on. It works much better at 10V or 15V than it does at 5V.

     

    image

     

    If you have a demanding application, there are better analog switches. The pictures I've shown here are from a 1975 databook and a lot of development has gone on since that time.

     

    Because the switch is floating (between the rails - don't take it outside the rails), as well as analogue and pulse circuits they are useful for things like hacking scanned (multiplexed) keyboards.

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

    The switch control inputs went straight to the Arduino pins.

     

    The switch is on when the input is high, so the gain sequence is upside-down - when the output is 0000 the gain is highest and when it's 1111 it's lowest. I invert it in the firmware, but an alternative would be to put external inverters between the processor pins and the switch control inputs.

     

    If you want to try something similar, bear in mind that though it sort of works the op-amp is on edge and close to bursting into oscillation. It's not a good circuit and another reason for me not pushing this as a project.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago

    For the CD4066, did you have to do something special, except giving it power?
    Did you hook up the logic inputs directly to the Arduino outputs (which should be fine I think)?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 5 years ago

    Yes, Analog circuits can humble the best engineer.

     

    Nice overview of the circuit and your results.

     

    Breadboards are notorious for noise and floating grounds, so having the oscillations is par for the course.

     

    Even at relatively low frequencies, you get interesting results. All of those component leads are antennas just waiting to add high frequency noise.

     

    Good job.

     

    DAB

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jc2048
    jc2048 over 5 years ago in reply to Jan Cumps

    No, looping slowly. The processor does 100 cycles and then steps to the next level. The scope has the persistance set to ten seconds, or something like that.

     

    I like it as a display - it makes me think of some fabulous monster from an uncharted ocean.

     

    One other thing it tells me, aside from the question mark over the stability, is that the sine wave is distorting. The traces are taken from the ac coupled output so should average to zero yet you can see that the crossing point is above zero.

    • Cancel
    • Vote Up +2 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 © 2023 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube