Help determining required ADC/DAC resolution - Page 1
Forum section: electronics / projects

author: birdman
author_rank: Newbie
timestamp: April 14, 2022, 06:00:17 pm
content: Hi all,I'm trying to wrap my head around the adc and dac resolution I require for my project, but I keep getting tripped up.Essentially, I'm trying to use a PIC microcontroller to convert a DC voltage reading from a potentiometer (could be 0-3.3V or 0-5V depending on PIC model, does it make a difference in resolution??) to a value via the ADC, and then output a value (via SPI or I2C) to a DAC that will then control a VCA. I'm using the VCA to control the resonant frequency of a filter.Let's say I want to be able to vary the resonant frequency of the filter between 200Hz and 2000Hz and I want to be able to move in 1Hz step sizes, so I essentially need my DAC to provide 1800 values, is that correct?Now the VCA output covers that frequency range with only roughly 0mV-700mV control voltage swing. So does this imply I need 1800 values just between 0mV and 700mV? If my DAC output is for example 0 - 5V, and lets say 12 bits, that's 4096 values between 0 - 5V. So I'd need a much higher resolution DAC than 12 bits then for what I'm trying to do??I'm definitely missing some big picture things here. There's probably some scaling somewhere that could be done but I just don't understand well enough. Sorry if this question is not clear enough, I'm not sure if there's any information I'm leaving out that could be helpful... Thanks for any help!

author: RoGeorge
author_rank: Super Contributor
timestamp: April 14, 2022, 06:12:13 pm
content: 11 bits (2048 steps) is more than the 1800 steps you requested, so you'll need at least 11.Use the 12 bits DAC you have, then use a voltage divider (two resistors) to lower the 0-5V range from the DAC output down to the 0-700mV you need.

author: birdman
author_rank: Newbie
timestamp: April 14, 2022, 06:57:23 pm
content: Quote from: RoGeorge on April 14, 2022, 06:12:13 pmThanks for your reply! So I'm on the right track then in my thinking that if I need my control to be 1Hz increments between 200Hz and 2000Hz, I'd need 1800 points of resolution from my DAC? I know it seems kind of obvious but I thought maybe I was not thinking of this properly.Regarding the ADC on the PIC, if I need my potentiometer to be able to control that range, does that then also mean my ADC needs to be at least 1800 bits of resolution?? Or is there something I'm missing about scaling the value coming in to correspond to my needed output range? I feel like most PIC ADC's I've encountered have been 10 bit so only 1024 resolution.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 14, 2022, 07:21:28 pm
content: Yes, same for ADC, 1800 steps (not 1800 bits!). So 11 bits seems enough.However, you won't be easy to manually tune 1800 positions on a single turn potentiometer (the angle between 2 adiacent positions would be too small), unless it's a multiturn potentiometer. Then, if both the input and the output are in the form of an analog voltage, do you really need a microcontroller and an ADC/DAC conversion? Why not just wire the potentiometer directly to the filter?Also, for a 1Hz resolution in the range 200-2000 Hz, it might be easier to digitize the 200-2000 signal, and filter it in software, or maybe use a dedicated DSP.It might be more productive to tell what the final device must do, it's goal and specs, and go from there. Otherwise we might spend time clarifying things that might not be needed for your project.

author: ledtester
author_rank: Super Contributor
timestamp: April 14, 2022, 07:25:50 pm
content: Quote from: birdman on April 14, 2022, 06:57:23 pmPretty much, although there are oversampling techniques to effectively increase the resolution of a DAC. Here's an article about it:https://thecavepearlproject.org/2017/02/27/enhancing-arduinos-adc-resolution-by-dithering-oversampling/On the other hand, (not knowing anything about your application) how about using a rotary encoder to have a user set the input?

author: birdman
author_rank: Newbie
timestamp: April 14, 2022, 07:41:40 pm
content: Quote from: RoGeorge on April 14, 2022, 07:21:28 pmOoops, yes 1800 steps, not bits lol.I really don't need precise control of the exact frequency to the specific Hz I suppose, but I do want to make sure that the DAC doesn't skip over any values.Basically I'm trying to create a digitally controlled analog filter. There are lots of CV controllable filters in the modular synth world, but I think it'd be neat to be able to set my frequency digitally via midi or some other method. Mostly just a learning experience as I want to get better at embedded programming. This helps a lot, thank you!Quote from: ledtester on April 14, 2022, 07:25:50 pmThis is super interesting. A lot to take in here, thanks for the link!

author: mariush
author_rank: Super Contributor
timestamp: April 14, 2022, 08:02:27 pm
content: You may want to change your potentiometer to a rotary encoder or something similar.Here's an example :https://eu.mouser.com/ProductDetail/BI-Technologies-TT-Electronics/EN12-HN22AF18?qs=u1MaZ2%2F4xgtqjc7ucrCQZA%3D%3DYou would only need two IO pins and a bit of logic to determine in which direction the knob is turned ... the cheapest ones do 24 "ticks" per rotation.You could also do it with just two plain pushbuttons ... keep button pressed and go down 1-2 per second, after 5s or so of button being pressed start incrementing by 5, after another 5s change values in steps of 10 or something like that ... basically implement a bit of acceleration.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 14, 2022, 08:15:55 pm
content: Quote from: birdman on April 14, 2022, 07:41:40 pmNice project!For that, you might as well use a quadrature encoder instead of potentiometer + ADC. An encoder can be turned forever, but it would be hard to "jump" fast to a new pitch. Or, you may go with a fixed mouse sensor (PS/2 mice are easier to read than the USB ones), reading paper discs as a very high resolution input device and with very fine control. You might use many DJ scratch disks instead of potentiometers to control the filters, similar to the setup in this video:https://youtu.be/-xqMNNAqt1c.For the DAC part, don't bother much about resolution. You can use a DAC, but it might be easier to use high speedPWM (Pulse Width Modulation)instead of a DAC. PDM (Pulse Density Modulation) might be even better than PWMhttps://hackaday.io/project/6356-delta-sigma-versus-pwm. Either can easily have more than 12 bits.

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 14, 2022, 08:45:55 pm
content: The problem with PWM is that ususally you have to choose between low frequency and high resolution, or low resolution and high frequency.You definitely want it to be as fast as possible to make filtering easier, but the dynamic response will be heavily affected by the filter, nowhere close to the dynamic range from a proper ADC, also getting 12 bits out of the PWM might not be that easy, as there''ll be distortion and non-linearity defects.If the changes don't need to be extremely fast (ex. needing to be synced with other very fast device), it might work.But there're cheap SPI/I2C DACs that will make this extremely easy.Then use an op-amp to scale the output voltage to the required swing.The encoder is better because it won't have resolution problem, you give the value you want for each step, and can time the input changes to provide different steps depending on how fast it's being rotated.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: April 15, 2022, 06:06:21 am
content: The one thing I would offer for conversation -- if a logarithmic curve is desired instead (typical for controlling pitch, say), then a 1Hz resolution would be had at the low end, increasing to 10Hz at the high end, and needing 461 steps to span the range, or at least 9 bits; a 10-bit ADC would do.While the exponent is nontrivial to compute, given something like an Arduino (it can add, subtract and multiply at best) -- if it only needs to be computed say a few thousand times a second (likely far, far more than enough for an audio effect?), that's more than feasible; and the standard library (floating point) has the implementation covered.Tim

author: RoGeorge
author_rank: Super Contributor
timestamp: April 15, 2022, 07:30:36 am
content: In audio, logarithmic variations are a must.To use something linear as an input device it would need very high resolution, so either use a lookup tablehttps://en.wikipedia.org/wiki/Lookup_tableto calculate a logarithmic variation for the output, or a logarithmic amplifierhttps://en.wikipedia.org/wiki/Log_amplifierinstead.It would be good to know how much pitch error can be in a note before being perceived as a false note. That might not be very important in an analog synth. The tolerance depends a lot from one listener to another. Some are saying 1 cent should be enoughhttps://en.wikipedia.org/wiki/Cent_(music) .