Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: Tashrafkhan on May 13, 2019, 04:50 am

Title: Successive Approximation ADC Code
Post by: Tashrafkhan on May 13, 2019, 04:50 am
Hello All
Can you guys help me with a project I'm working on. I'm trying to built a Analog to Digital converter working on Successive Approximation algorithm. How should I proceed with the code?
Title: Re: Successive Approximation ADC Code
Post by: 6v6gt on May 13, 2019, 05:41 am
Is you intention to build the hardware or are you simply going to convert the flowchart into C++ ?
To convert to C++ you need an 8 element array to represent the register, read some voltages and maintain some counters. You can't really test it, though. All you can do is check it compiles Ok.
Title: Re: Successive Approximation ADC Code
Post by: Tashrafkhan on May 13, 2019, 06:29 am
my intention is to convert the flow chart into C++, I have the hardware to test on.
Title: Re: Successive Approximation ADC Code
Post by: PaulRB on May 13, 2019, 07:59 am
I have the hardware to test on.
Post the schematic please.
Title: Re: Successive Approximation ADC Code
Post by: Tashrafkhan on May 13, 2019, 10:54 am
I've already provided the schematic and the flow chart along my post
Title: Re: Successive Approximation ADC Code
Post by: 6v6gt on May 13, 2019, 11:10 am
OK. So I guess that is an "academic" exercise. The flow chart describes the logic you have to implement in the box labeled "Control Logic and output register".

It looks like you have 3 inputs (GPIO pins): inputs Clock, Start Conversion and Comparator.
You have 1 simple digital output: EOC
You have to understand how you deliver data to the DAC. In the worst case, this requires 8 output pins.
You also have to know how you are to deliver the final output. Maybe writing to the serial monitor is good enough or some other serial method. You'll have a problem with a small microprocessor if it also has to be a parallel output because you'll soon run out of GPIO pins.



I've already provided the schematic and the flow chart along my post
What does the DAC look like in the hardware ?
Title: Re: Successive Approximation ADC Code
Post by: Paul__B on May 13, 2019, 12:30 pm
You'll have a problem with a small microprocessor if it also has to be a parallel output because you'll soon run out of GPIO pins.
Actually, that is fairly easy.  That parallel output is what is fed to the DAC.  When it is finalised, you merely strobe it to whatever successive device you wish.
Title: Re: Successive Approximation ADC Code
Post by: 6v6gt on May 13, 2019, 01:00 pm
Actually, that is fairly easy.  That parallel output is what is fed to the DAC.  When it is finalised, you merely strobe it to whatever successive device you wish.
That is possible, but these appear to be drawn in the block diagram as separate 8 bit bus. Maybe also that the "Arduino" the OP is using to implement the control logic also includes an external 8 bit shift register.

I found the exercise quite interesting because I have never studied a successive approximation ADC before and now, from this thread, I have understood how it works. We didn't do interesting stuff like that when I was at school.
Title: Re: Successive Approximation ADC Code
Post by: david_2018 on May 13, 2019, 01:15 pm
Do you have an actual schematic showing how the hardware is wired, the "schematic" given in the pdf document is more of a block diagram, and doesn't give anywhere near enough information for anyone to give you specific advice. The flowchart gives the basic logic for the code, have you made any attempt to write the code, and if so can you post it?

The only confusing part I see in the logic is that the MSB is being referred to as D1, and the counter k starts at 1, most programmers are going to think of MSB as D7 and LSB as D0, and start loop counters at 0.
Title: Re: Successive Approximation ADC Code
Post by: Paul__B on May 13, 2019, 02:51 pm
most programmers are going to think of MSB as D7 and LSB as D0, and start loop counters at 0.
That would of course, depend on whether they are Lilliputian or Blefuscutian.