Prox / RFID
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Resume / Consulting
Contact Me

LDmicro Forum - ADC

(you are viewing a thread; or go back to list of threads)

ADC (by oster)
Hello Jonathan. A good program, great for the future, please make an accurate statement in Russian. Help please need a program for my drawing. Thanks
Fri Aug 13 2010, 05:48:53, download attachment ACD.GIF
(no subject) (by Jonathan Westhues)
I don't completely understand your drawing. It looks like you want to A/D convert the input, with a range of 0 to 32767, and then set a digital output high only if the analog value is equal to 12000.

That's not a meaningful thing to do. First, the PIC or AVR hardware has a resolution of only ten bits, and a useful resolution that's lower due to noise. So to try to pick out one code in 32767 isn't meaningful.

It would be more typical to check whether the A/D converted value lies within a range. Also, the A/D value goes from 0 to 1023 (ten bits) by default; you could multiply it to scale it up, but it's simpler to adjust your comparison value accordingly.

See the attached program. The output is high when the input is between an A/D code of 500 and 600, or 2.44 V and 2.93 V with a five-volt reference.
Fri Aug 13 2010, 11:32:00, download attachment adc-range.ld
(no subject) (by oster)
Fri Aug 13 2010, 16:04:42
(no subject) (by oster)
Hello Jonathan. Help please. Show please the program: the input of the ADC is fed growing analog signal when the signal stops growing need to include a digital output.
Can I set up an internal RC oscillator?
Mon Aug 16 2010, 15:34:45
(no subject) (by Jonathan Westhues)
Sorry, I don't understand. Can you post a picture, or some other explanation?
Tue Aug 17 2010, 18:29:42
(no subject) (by oster)
Is it possible to use the internal RC oscillator instead of the quartz crystal?.
Wed Aug 18 2010, 02:57:36, download attachment ADC_2.GIF
(no subject) (by Jonathan Westhues)
If your programming software lets you change the fuse settings to use the internal or external RC oscillator (instead of the crystal, which is the default), then everything will still work. Just enter the RC oscillator frequency instead of the crystal frequency.
Wed Aug 18 2010, 18:08:14
(no subject) (by oster)
Thank you.
About the drawing, shall we say? You need to enable the digital output when stopping the analog signal, it is still at what level.
Thu Aug 19 2010, 06:49:00
(no subject) (by Jonathan Westhues)
I'm still not sure that I understand. Do you want the digital output to be low when the analog input is changing, but high when the analog input is steady?

If that's the case, then try the attached example. We A/D convert our input, and low-pass filter that. We then compare the low-pass filtered version against the original signal.

(The low-pass filter is a first-order low-pass filter, of the form y[k+1] = alpha*x[k] + (1-alpha)*y[k], where x[k] is the input, y[k] is the output, and the constant alpha determines how fast the filter responds. This is almost always a better idea than a moving average, because it requires only a single variable of storage. The implementation is a little more complicated here, since we're doing it with integer math; so we actually write y[k+1] = (alpha*x[k] + (20-alpha)*y[k] + 10)/20.)

If the original and low-pass filtered signals are approximately equal, then the signal is steady. If they're not, then the signal is changing. So based on the difference between the two signals, we either set or clear (reset) an internal relay.

Then, for an additional level of debouncing, we put a turn-on delay from that internal relay to the digital output. If, for example, the signal was changing, but alternating between increasing and decreasing, then the low-pass filtered version would sometimes be equal to the original version, but only for an instant; and the turn-on delay would stop those glitches from appearing on the output.
Thu Aug 19 2010, 13:04:15, download attachment steady.ld
(no subject) (by oster)
In this case, does not fit. The program needs to control battery charging. Tension reached 1,45 Volta includes Yout_0, then monitor the growth of Ain. When the increase stops Ain disable the charging - includes Yout.
Thu Aug 19 2010, 15:27:38, download attachment steady_1.ld
(no subject) (by Jonathan Westhues)
I still don't understand what you're trying to do. Does the charging stop when the voltage reaches some threshold, or does it stop when the voltage becomes constant (at any level)? And when does the charging start again?
Thu Aug 19 2010, 15:37:05
(no subject) (by oster)
voltage becomes constant (at any level),after >1,45 Volt
Thu Aug 19 2010, 16:06:52
(no subject) (by Jonathan Westhues)
So perhaps the attached program is closer to what you want. Here, I calculate the slope of the A/D converted voltage. I first take the difference between the current sample and the previous sample. In theory, that should do what we want; but in practice, this would likely be unusably noisy. So I follow that with a low-pass filter, as before, with the specified time constant parameter alpha.

The stop condition is then just the AND (series connection) of two conditions: one on the slope, and one on the absolute voltage.

You can adjust the time scale of the system by adjusting the timer that sets the period of Rosc. As things stand now, it's relatively fast, so that you can test it in reasonable time in the simulator. For real, you would probably slow that down.

The slope is in units of ADC codes per Rosc period. So if the ADC spans 5 V over 1023 codes, for example, and the Rosc period is 200 ms, then a slope of 10 corresponds to 10*(5 V / 1023)/(200 ms) = 244 mV/s. If you changed the timer to 100 s, then that slope of 10 would correspond to 244*0.2/100 = 0.488 mV/s, or 1.7 V/hour, which is maybe closer to what's desired.

You still didn't indicate when the charging restarts. But in the program, I set that to occur when the voltage drops below some other threshold on just the voltage, irrespective of the slope.
Thu Aug 19 2010, 17:25:26, download attachment slope.ld
(no subject) (by San)
Dear Sir,

I've a doubt regarding the usage of ADC instruction. I copied the basic ladder program given by you in this blog and run that program. There was no response from the output of the ATMEGA 16 micro controller. Is there any need to connect pin no. 32 to +5v before using the ADC ? Please help me to prove out the output of ADC. I've used a variable resistor in the input and while varying the resistance, input to the ADC pin is varying ( Pin No: 40 in the ATMEGA 16), but there was no response from the output of the Yout( Pin no 1:PB0). Please help me in this regard.

Thanks and regards
Thu Sep 12 2013, 05:23:31, download attachment adc-range.ld
(no subject) (by MGP)
In your program no microcontroller/cristal is selected.
You must fill in the menu settings.
Then try again.

Thu Sep 12 2013, 06:31:29
ADC (by San)
Dear Sir,

I got result for ADC. I've attached the simple ladder diagram I used here. The connection between the pin no. 32(AREF) and +5V is must for using the ADC function. I checked it and verified the result. If we don't use this connection, ADC function won't work. In my ATMEGA 16 board, there was no connection between +5V and the AREF. I soldered this connection and checked the working and applied the below ladder diagram and the output was successful.

Thank you very much for your valuable and quick reply.
Thu Sep 12 2013, 06:53:45, download attachment ADC.ld
Variable ON_delay by using ADC (by Dhanushka)
Dear Mr Jonathan

First of all, this is a very nice software.

So i just want to make a variable ON delay timer that the time adjustment could be able to change by an analog input.

so i need to insert a parameter into the time setting of the ON delay block.

So if it is very much appreciated if you can advice on this matter.


Tue Apr 10 2018, 05:07:55
(no subject) (by Mukesh )
Dhanushka there are many ways u may design timer . however a simple way is devised here u may change according to your need.
Mon Dec 24 2018, 00:10:58, download attachment ANALOG TIMER.ld
Post a reply to this comment:
Your Name:
Your Email:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):