PWM to DC - Page 1
Forum section: electronics / projects

author: brownt
author_rank: Regular Contributor
timestamp: July 06, 2018, 01:29:40 pm
content: HI, I am using Autocorrelation in an embedded system to determine audio frequencies 80 - 1400Hz.After correlation I am using PWM to represent that frequency then passing it through an RC filter, and using the resulting DC as an input to an A/D on another system/enclosure via a 15cm cable.I am using 1Kohm and1uF for the filter, which according to my calculations should settle at 90% within 1mS. However, it seems to be taking much longer. I can change it to 100uF which should be 100mS settle time, but it doesn't seem to make any difference. It is all part of an audio system and there is a noticeable audible delay.I can visually see the slow DC change on an oscilloscope compared to a much faster visual change on the PWM pin.And I wonder if the impedance of the A/D is a significant part of the equation that I am missing, or something else.thanks

author: JPortici
author_rank: Super Contributor
timestamp: July 06, 2018, 02:19:40 pm
content: If you are not buffering the PWM output before going into the ADC then i would be expecting this behaviour.Usually the integrated ADC in MCUs are of the SAR type.During the sampling phase the ADC is charging a sampling Capacitor, then during conversio phase the capacitor is disconnected from the analog input and connected to the ADC network.if you are not buffering you can see your circuit as two RC cells in series.The first being the one pole low pass filter with R=1k and C=1uThe second being the sampling switch internal resistance with the sampling capacitor. (refer to the datasheet for their typical values.)this is one of the reasons why there is a maximum recommended source impedance, the other being the internal parasitic currents, if source impedance is too high = input current too low, the parasitics will affect the accuracy of the result.If you are not buffering the first cell i would expect this behaviour, as the sampling capacitor charging current is limited both by the sampling switch resistor and the 1kThe solution would be buffering, or using a different method (like sending the PWM directly to a digital pin and acquire the period/duty cycle with input capture or a timer and and EXTI/change notification interrupt.This, if you are not buffering the PWM filter

author: Kleinstein
author_rank: Super Contributor
timestamp: July 06, 2018, 04:07:44 pm
content: A filter with 1 K and 1 µF results in a 1 ms times constant. That is it takes 1 ms to settle to about 67 % and thus more like 2-3 ms to get to 90%. So final settling may to some 5 ms.Mot buffering the filter output mainly effects the accuracy, but settling is not much effected, it might even get a slightly faster settling as the input impedance of the following stage is effectively in parallel to the 1 K resistor.It is an odd way to use PWM to transfer data from µC to µC - the more logical way would be an UART or similar.

author: brownt
author_rank: Regular Contributor
timestamp: July 07, 2018, 08:15:23 am
content: Thanks for all the info. Very informative. Using that I can see that the major part of the delay is in the software.Yes the micro is a shabby one. 16Mhz ATmega.I did try FFT but it gave a few false frequencies which was causing a problem for the application. Auto correlation was not be as accurate but it is consistent, so I used that.I have a 64MHz PIC18F26k40. So I will try that as it will reduce the delay x 4, barely noticeable at 30mS. Though I'd like the delay to be under whatever the time is for audible difference, I guess about 20mS.

author: EmmanuelFaure
author_rank: Regular Contributor
timestamp: July 08, 2018, 08:01:26 am
content: Have a look at that chip : LTC2644. 12 bits PWM -> DC conversion in one cycle.

author: brownt
author_rank: Regular Contributor
timestamp: July 11, 2018, 01:22:42 am
content: thanks for that. But it is not the PWM to DC conversion that is significant. Rather, it is the autocorrelation processing.thanks though, good to know.