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
Data Conversion
  • Challenges & Projects
  • Project14
  • Data Conversion
  • More
  • Cancel
Data Conversion
Blog Blinken' and Clicken' the DAC for vADC | Part 2
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Data Conversion to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: baldengineer
  • Date Created: 1 Mar 2021 5:46 AM Date Created
  • Views 1812 views
  • Likes 10 likes
  • Comments 2 comments
  • visual adc
  • baldengineer
  • dataconverch
Related
Recommended

Blinken' and Clicken' the DAC for vADC | Part 2

baldengineer
baldengineer
1 Mar 2021

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

One of the key reasons I wanted to build a SAR ADC is its heart is a digital-to-analog converter (DAC). So it is a two-for-one project. As a quick summary, a SAR ADC uses a DAC to generate analog voltages that get compared to the input voltage. Using a binary search, it is possible to find a digital code that represents the input.

 

Quite a bit has changed from the first part. In the last post, I was thinking about a shift register and how to control the LEDs. Ultimately, I with the shift register route and added a buffer chip for individual LED control. I've also gotten the boards back, built, and tested them. Things are moving forward!

 

Bald Bit Boards

The first step in my VADC project was to design an R-2R ladder. My goal was to create individual "bit boards" with a resistor, relay, and LEDs. The resistors are obvious because they build the R-2R ladder. The relay and LEDs are entirely for visualization purposes. I decided the PCB should light up around the relay whenever that particular bit is active. Each bit board contains six LEDs and one relay. The relay determines if the resistor is in the ladder or not. The LEDs are these reverse mount LEDs from Wurthreverse mount LEDs from Wurth. (More on being reverse mount below.)

 

image

 

To drive the relay plus six LEDs, I decided to add a 74HCT595 74HCT595 shift register to each board. Using a shift register means I can daisy-chain multiple boards together. Initially, I built four boards for a 4-bit DAC. But in theory, I should easily be able to extend to 8-bits+. (Well, I would have already built them if the rest of my LEDs were not back-ordered. grr.)

 

Instead of using discrete transistors to drive the LEDs, I decided to add a 74HC245 74HC245 buffer. It can provide up to 70 mA total on its outputs, which should be sufficient for this project. The LEDs have a fairly high forward voltage, so a 330 ohm limiting resistor means I'm drawing 9 mA each. So the LEDs draw 54 mA total (if they are all on). The only real consideration is the relay's coil.

image

For the relay, I decided to include a P-Channel MOSFET configured as a high-side switch. That way, the `595 output can directly drive the transistor. For flyback protection, I added a 1n4001. Although, it is probably overkill for this relay. I'm using these Multicomp Pro Signal RelaysMulticomp Pro Signal Relays. And they are tiny! They are so small; I was initially concerned they would not click loud enough! (Spoiler Alert: No worries, they do.)

 

Why 4-layer?

If you look at the vADC KiCad design files, you'll probably notice the PCB is 4-layers. Why?

image

Well, first, my go-to PCB supplier is OSH Park, especially if the project is below 100 mm2. And second, I am using reverse mount LEDs to create a glowing ring around the relay. (or that was the plan.) OSH Park's FR4 formulation is different from their 2-layer, and it is more fluorescent. While the signal integrity of this design didn't need four layers, the cool visualization integrity did!

 

Soldering

When soldering a board with more than a few components, you can almost always expect at least one mistake. When soldering multiple boards with multiple components, it is a certainty. Shockingly, there were almost no mistakes in assembly the first four boards. At least, no circuit mistakes. I'm not great with hot air, so I had some intermittent behavior with one LED. That was fixed by resoldering the `595 with my normal iron.

 

That said, I did accidentally touch the exposed ground plane with my soldering iron. So, some solder ended up on the gold finish. I left that area exposed on both sides of the board to make clipping on a scope easier. I'm really hoping I can sacrifice that board as extra because I want the gold strip to stay "clean."

 

Code

void send_data_to_bits(uint32_t data_out) {
    // X R X X  X X X 1  X R X X  X X X 1   X R X X  X X X 1   X R X X  X X X 1
    digitalWrite(latch_595, HIGH);
      shiftOut(data_595, clock_595, MSBFIRST, (data_out >> 24));  // bit 4
     shiftOut(data_595, clock_595, MSBFIRST, (data_out >> 16));  // bit 3
     shiftOut(data_595, clock_595, MSBFIRST, (data_out >> 8));    // bit 2
     shiftOut(data_595, clock_595, MSBFIRST, (data_out));        // bit 0
    digitalWrite(latch_595, LOW);
}

 

Interfacing the daisy-chained bit boards is straightforward. The only hiccup I ran into is that Arduino's shfitOut() only accepts 8-bits or a byte. Since each bit board has its own `595, each board has 8-bits of data to handle. So I had to do some barrel shifting to get the expected outputs. Even with 32-bits of data, I found I could update the LEDs once every 25 milliseconds. From a visualization perspective, that is probably too fast, but it is good to know I have plenty of headroom to flash the LEDs.

 

Scope Capture

In the video above, you can see that the multimeter measures a different voltage as the bit values change. Astute viewers might notice that the voltage starts close to 5 volts and ends near 0 volts. From a DAC perspective, this range is irrelevant. However, for the visualization, I think it makes more sense for the voltage to go from 0 volts to 5 volts as the binary codes go from 0x0 to 0xF. So, later, I inverted the relays. This change means while the relay is lit up, it is actually off. In retrospect, I should have swapped Vref and GND on the relay contacts.

image

After making that code change, I captured the codes on my scope. And to my surprise, there is a huge gap between 0x7 and 0x8. Upon further inspection of the Bit Boards, I put the "R" and "2R" values in the wrong places! So, the ladder is just output nonsense. The positive news is that different binary values result in different outputs.

 

Next Steps

Since I have to order some more parts to build another 4-bits, I decided to splurge on some 0.1% resistors to match my R-2R values better. When I get those, I'll fix these four initial bits. In the meantime, I've already built up a functional sample-and-hold amplifier AND a comparator circuit. But, those are a topic for another post.

 

Super Quick Update

The DAC not going to 0V when the binary codes are zero was bothering a friend of mine. Which after he asked the question, it started to bother me too. After thinking about it, I had an idea why. "VIN" on the least significant bit is supposed to be connected to ground. In the video at the top of the post, it is left open. After making that change, now the DAC goes from 0.00 volts to about 4.2 volts. (but the codes are not linear or in order because the resistor values are still wrong.)

 

image

  • Sign in to reply

Top Comments

  • baldengineer
    baldengineer over 4 years ago +1
    A few people (outside of the community) have asked me about the big blue board the bits are sitting on. That is the " Practical IoT Microcontroller Trainer " board. It is sold by the Blue Smoke Monster…
  • DAB
    DAB over 4 years ago +1
    I like the idea of building an ADC from scratch. DAB
  • DAB
    DAB over 4 years ago

    I like the idea of building an ADC from scratch.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • baldengineer
    baldengineer over 4 years ago

    A few people (outside of the community) have asked me about the big blue board the bits are sitting on. That is the "Practical IoT Microcontroller Trainer" board. It is sold by the Blue Smoke Monster Project. The board contains an Arduino Nano (clone), ESP-01, ESP32, and header for Raspberry Pi. All of the I/O pins for the microcontrollers are broken out to make it easy to connect to other devices. On-board there is an I2C OLED, a SPI TFT Touch screen, an HC-05 Bluetooth Module, some ws2812 (NeoPixels), pushbuttons, and rotary encoders.

     

    In this case, I am running my code on the Nano. The Nano's 5 volts, from USB, is powering the trainer and my DAC boards. I'm not using the breadboard for this design. But I am jumping from the Bald Bits to the Nano headers on the PiOT board. (and at one point, I almost connected the push buttons so I could change speeds, but ran out of time.)

     

    You can get the Practical IoT as a full kit (that's what I bought) or just the bare board if you have some of the hardware already. I like it because it is an all-in-one board for common MCU hardware. BSM is working on improvements and a new revision, but I think this board is still worthwhile.
    Apologies if this sounds like an ad. Josh, its creator, is a friend of mine. That said, I did buy my kit and I would think it is worth the price even if I didn't know him.
    • Cancel
    • Vote Up +1 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