Shop OBEX P1 Docs P2 Docs Learn Events
ADC Sampling Breakthrough - Page 11 — Parallax Forums

ADC Sampling Breakthrough

18911131452

Comments

  • cgraceycgracey Posts: 14,134
    TonyB_ wrote: »
    How many counters and adders are there in each smart pin?

    I'm not arguing in favour of Tukey at the expense of anything else. From the output of a binary counter, only a little logic would be needed to generate a small error term, which when added to the counter would create the Tukey value to add to the accumulator. One counter and two adders needed and Sinc3 requires two adders.

    What would be a big improvement is more bits of resolution within the same time period. We need to understand that.

    If that is not possible, the Tukey is the best approach. I just don't have my head around the more-bits thing yet. Do you understand it?
  • evanhevanh Posts: 15,858
    edited 2018-11-24 02:48
    It seems counter-intuitive that "throwing away" more bits will produce a better result, but that is result of my analysis.

    I guess there is an effective interpolation also happening at the same time in the higher order Sinc filters.

    PS: Thank you hugely for the spectral graphs!

  • cgraceycgracey Posts: 14,134
    TonyB_ wrote: »
    How many counters and adders are there in each smart pin?

    I'm not arguing in favour of Tukey at the expense of anything else. From the output of a binary counter, only a little logic would be needed to generate a small error term, which when added to the counter would create the Tukey value to add to the accumulator. One counter and two adders needed and Sinc3 requires two adders.

    There's no fixed set. It can be whatever we want.
  • ozpropdev wrote: »
    @ErNa
    Here's some real streams from P2 silicon.
    8 channels of bitstream x 64000 clocks

    That's just what I wanted to get my hands on. Thank you!
    The different colors are different ADC channels. Gio and Vio are plotted together because it should only be the DC value that is different.

    -James
    1167 x 875 - 36K
    1200 x 900 - 39K
  • cgraceycgracey Posts: 14,134
    Evanh, I'm looking at your code, the 'case 13' section that Saucy pointed out.

    So, you reset all the accumulators and differentiators, only if it's being reset.

    You run some number of ADC bits into it, updating your accumulators.

    After so many bits, you get a reading and update your differentiators.

    Can that outer loop run for infinite iterations without the need to reset the acc's and diff's?
  • cgracey wrote: »
    TonyB_ wrote: »
    cgracey wrote: »
    TonyB_, I see now that the Tukey filter is the best when you want to "open the valve" in the shortest number of samples, but if shortening the time is not critical, a triangle filter is cheap. Any trapezoid window could be improved by a Tukey window in the same place, but Tukey256 would be very expensive compared to Trap256.

    A triangular window has a gain of 0.5, whereas a Tukey window could be close to 1.0. What does that the mean for the effective number of bits?

    How is the gain pushing 2x? Double gain adds 1 bit, right?

    You lose a bit of resolution with a triangular window compared to a near rectangular one, but if you've removed more noise then it would be worth it. You need to scale the outputs from the triangular and Tukey windows so they match, then compare the noise.
  • SaucySolitonSaucySoliton Posts: 521
    edited 2018-11-24 03:03
    cgracey wrote: »
    Can that outer loop run for infinite iterations without the need to reset the acc's and diff's?

    Yes, the accumulators can run forever, they wrap around. But you don't want it to wrap around more than once between reads, because you won't know how many time it happened.

    https://dspguru.com/files/cic.pdf See section 4 about bit growth. R is the decimation factor. So reading the accumulator less frequently will require it to have more bits.

    If you resume after an extended break, or after changing channels, or changing sample rates you'll need to cycle the outer loop a few times to flush out the old diff's.

    -James
  • evanhevanh Posts: 15,858
    cgracey wrote: »
    Can that outer loop run for infinite iterations without the need to reset the acc's and diff's?

    Absolutely. That's what I call rolling or continuous.

  • evanhevanh Posts: 15,858
    edited 2018-11-24 03:13
    If you resume after an extended break, or after changing channels, or changing sample rates you'll need to cycle the outer loop a few times to flush out the old diff's.

    Right, the reset isn't even needed. But if it's in software then easy.

    The filter size thing messed with my head until I had data out. You'll note I'm unnecessarily resetting the accumulators too.

  • cgraceycgracey Posts: 14,134
    Okay. no reset necessary, as things flush out.

    I can see that sinc3acc3 would get huge fast.

    What kind of read interval were you anticipating, Evanh? 256 clocks? 4096 clocks?

    At a read interval, you would need to read all three accumulators and maintain the diff's in software, right?
  • cgraceycgracey Posts: 14,134
    edited 2018-11-24 03:18
    No, I see. You would just need to read sinc3acc3. So, that thing needs to remain within 32 bits of change per read interval?
  • evanhevanh Posts: 15,858
    edited 2018-11-24 03:27
    cgracey wrote: »
    What kind of read interval were you anticipating, Evanh? 256 clocks? 4096 clocks?
    I'd be happy with Sinc2. It seems less fragile.

    At a read interval, you would need to read all three accumulators and maintain the diff's in software, right?
    I'm imagining the diffs in software to maintain existing gate count.

    cgracey wrote: »
    No, I see. You would just need to read sinc3acc3. So, that thing needs to remain within 32 bits of change per read interval?
    Correct for both.


    [edited a hundred times :(]
  • evanhevanh Posts: 15,858
    edited 2018-11-24 03:35
    cgracey wrote: »
    What kind of read interval were you anticipating, Evanh? 256 clocks? 4096 clocks?

    Sinc3 produces 30-bit samples in 1024 clocks. So that's its limit.

    Sinc2 produces 20-bit samples in 1024 clocks and 32-bit samples takes 64k clocks.

  • Also consider the binomial filter. The coefficients are the odd rows of Pascal's triangle, and they always add up to a power of two. Its frequency response is monotonic without "bumps" at the higher frequencies.

    -Phil
  • The limit for sinc4 is about 180 clocks. So about 1.4MSPS minimum. To have to do 4 differentiations at that rate wouldn't leave much time to do anything with the result.

    Sinc3 outputting at 250ksps seems like a good rate for audio. Just add an anti-aliasing filter that reduces the rate to about 50ksps.

    I wonder if it's possible to add a 4th stage in software, running at the reduced rate.


    The good part about the sinc filter is that there is no counter to synchronize with the ADC reading process. If we generated the window in time domain, we would have to collect the output while the window is zero, to avoid edge discontinuities.
  • cgraceycgracey Posts: 14,134
    The limit for sinc4 is about 180 clocks. So about 1.4MSPS minimum. To have to do 4 differentiations at that rate wouldn't leave much time to do anything with the result.

    Sinc3 outputting at 250ksps seems like a good rate for audio. Just add an anti-aliasing filter that reduces the rate to about 50ksps.

    I wonder if it's possible to add a 4th stage in software, running at the reduced rate.


    The good part about the sinc filter is that there is no counter to synchronize with the ADC reading process. If we generated the window in time domain, we would have to collect the output while the window is zero, to avoid edge discontinuities.

    So, for 1024 clocks:

    ACC1 = 11 bits
    ACC2 = 21 bits
    ACC3 = 32 bits

    The time base and clock counter can work in the X register for automatic ACC3 reporting. WXPIN sets up the number of clock cycles for ACC3 reporting.

    ACC1 and ACC2 can work in the Y register.

    ACC3 can work in the Z register, which always reports the result via RDPIN, anyway.


  • Also consider the binomial filter. The coefficients are the odd rows of Pascal's triangle, and they always add up to a power of two. Its frequency response is monotonic without "bumps" at the higher frequencies.

    -Phil

    Very interesting, Phil. Thanks!

    The filtering performance should be about the same as sinc3 or sinc4 for the same length. But it's a different way to implement it.

    -James
  • cgraceycgracey Posts: 14,134
    edited 2018-11-24 05:00
    ...The good part about the sinc filter is that there is no counter to synchronize with the ADC reading process. If we generated the window in time domain, we would have to collect the output while the window is zero, to avoid edge discontinuities.

    Wouldn't it still be helpful to have the smart pin report ACC3 on a routine basis? Then we'll have plenty of time to pick up the sample and process it. Plus, no information will be lost in ACC3.
  • cgracey wrote: »
    So, for 1024 clocks:

    ACC1 = 11 bits
    ACC2 = 21 bits
    ACC3 = 32 bits

    The time base and clock counter can work in the X register for automatic ACC3 reporting. WXPIN sets up the number of clock cycles for ACC3 reporting.

    ACC1 and ACC2 can work in the Y register.

    ACC3 can work in the Z register, which always reports the result via RDPIN, anyway.

    All 3 ACCs might need to be 32 bits internally. But if we design for a maximum read interval of 1024 clocks, then we would only need to report the specified LSBs from ACC1 and ACC2. If we had the full ACC2 we could run longer between reads, but with less filtering. The extra length might make up for it.

    -James
  • cgracey wrote: »
    ...The good part about the sinc filter is that there is no counter to synchronize with the ADC reading process. If we generated the window in time domain, we would have to collect the output while the window is zero, to avoid edge discontinuities.

    Wouldn't it still be helpful to have the smart pin report ACC3 on a routine basis? Then we'll have plenty of time to pick up the sample and process it. Plus, no information will be lost in ACC3.

    Yes. I'm still not quite sure what all the smart pins can do. Automatically collecting ACC3 would be good.

    I guess if we were using the Tukey or trapezoid window, the smart pin would know when the report was going to happen and ramp the window down at the right time.
    The smart pin could do something like this:
    wait for report timer
    ramp window down
    read and clear accumulator
    send report
    ramp window up
    repeat
  • cgraceycgracey Posts: 14,134
    If we dedicate X, Y, and Z registers to 32-bit accumulator functions, we still have 16 bits left in some extra flops to track time and report ACC3 routinely.

    So, ideally, all ACC's should be 32 bits and rolling over with no cares, as long as we sample ACC3 before it rolls over?
  • cgraceycgracey Posts: 14,134
    edited 2018-11-24 05:59
    If we have all 32-bit accumulators, it keeps the software simpler, right?

    It seems to me that we can do 2954 samples before overflowing ACC3 at 32 bits.

    On my phone:
    a = 0
    b = 0
    c = 0
    
    for x = 1 to 2954
     c = c+b
     b = b+a
     a = a+1
    next x
    
    print a,b,c
    print (log10(a) / log10(2))
    print (log10(b) / log10(2))
    print (log10(c) / log10(2))
    


    1396 x 531 - 52K
  • cgraceycgracey Posts: 14,134
    cgracey wrote: »
    ...The good part about the sinc filter is that there is no counter to synchronize with the ADC reading process. If we generated the window in time domain, we would have to collect the output while the window is zero, to avoid edge discontinuities.

    Wouldn't it still be helpful to have the smart pin report ACC3 on a routine basis? Then we'll have plenty of time to pick up the sample and process it. Plus, no information will be lost in ACC3.

    Yes. I'm still not quite sure what all the smart pins can do. Automatically collecting ACC3 would be good.

    I guess if we were using the Tukey or trapezoid window, the smart pin would know when the report was going to happen and ramp the window down at the right time.
    The smart pin could do something like this:
    wait for report timer
    ramp window down
    read and clear accumulator
    send report
    ramp window up
    repeat

    But if we run SINC3 continuously, we won't need to do any windowing, right?
  • evanhevanh Posts: 15,858
    cgracey wrote: »
    But if we run SINC3 continuously, we won't need to do any windowing, right?

    Yep.

    I think James is thinking about how to do single discontinuous samples for instrumentation calibrating.

    As far as I can tell the ramping is built into the filters already. But a filter adds lag too, this is where software can do a better job by selectively ignoring the leading samples. Just need the accumulators in hardware.

  • cgraceycgracey Posts: 14,134
    evanh wrote: »
    cgracey wrote: »
    But if we run SINC3 continuously, we won't need to do any windowing, right?

    Yep.

    I think James is thinking about how to do single discontinuous samples for instrumentation calibrating.

    As far as I can tell the ramping is built into the filters already. But a filter adds lag too, this is where software can do a better job by selectively ignoring the leading samples. Just need the accumulators in hardware.

    Couldn't we do instrumentation calibration by waiting for the 4th sample?
  • cgracey wrote: »
    If we have all 32-bit accumulators, it keeps the software simpler, right?

    It seems to me that we can do 2954 samples before overflowing ACC3 at 32 bits.
    Not quite. We have to worry about the output stage too. Although if we did extended math on the output side it might be fine.

    This thing has a gain of G=(RM)^N. N=3 for three accumulators. So our maximum RM is 1625. The reason is 1625^3 < 2^32 -1. If we tried to go to 1626, the output would overflow. 1626^3 > 2^32 -1. In practice we could usually go a little more because we wouldn't see solid ones unless the input was above the supply.

    It also turn out that Bout bits are needed for each integrator and comb stage. (https://dspguru.com/files/cic.pdf)
    cgracey wrote: »
    cgracey wrote: »
    ...The good part about the sinc filter is that there is no counter to synchronize with the ADC reading process. If we generated the window in time domain, we would have to collect the output while the window is zero, to avoid edge discontinuities.

    Wouldn't it still be helpful to have the smart pin report ACC3 on a routine basis? Then we'll have plenty of time to pick up the sample and process it. Plus, no information will be lost in ACC3.

    Yes. I'm still not quite sure what all the smart pins can do. Automatically collecting ACC3 would be good.

    I guess if we were using the Tukey or trapezoid window, the smart pin would know when the report was going to happen and ramp the window down at the right time.
    The smart pin could do something like this:
    wait for report timer
    ramp window down
    read and clear accumulator
    send report
    ramp window up
    repeat

    But if we run SINC3 continuously, we won't need to do any windowing, right?
    Right, just read the data.
    Sinc3_rolling   713849500 3574525500 4291015625 4291015625 4291015625 4291015625 4291015625
    
    So it looks like 2 values to flush out.


    As I understand, X and Y are write only? What would be the purpose of using them for the accumulators? We only need to read one accumulator, it would be fine to mux them. In case somebody wanted first or second order value for some reason. I would prefer to loose access to part of the accumulators than loose timing accuracy.
  • evanhevanh Posts: 15,858
    cgracey wrote: »
    If we have all 32-bit accumulators, it keeps the software simpler, right?
    For a specific Sinc3 mode the software doesn't see anything of the leading accumulators so software isn't going to care what size they are.

    Can you actually make savings though? How is the existing +1 summing done?

  • evanhevanh Posts: 15,858
    cgracey wrote: »
    Couldn't we do instrumentation calibration by waiting for the 4th sample?

    Yes, that combats the lag.

  • evanhevanh Posts: 15,858
    All 3 ACCs might need to be 32 bits internally. But if we design for a maximum read interval of 1024 clocks, then we would only need to report the specified LSBs from ACC1 and ACC2. If we had the full ACC2 we could run longer between reads, but with less filtering. The extra length might make up for it.

    I'm pretty certain Chip will make these as separate smartpin modes. So when set for Sinc2 the second accumulator will become full 32-bit.

    It's not reconfigurable logic like a FPGA but the optimiser will reuse flops in particular.

  • cgraceycgracey Posts: 14,134
    Is there a reason to support both Sinc2 and Sinc3?
Sign In or Register to comment.