Shop OBEX P1 Docs P2 Docs Learn Events
ADC idea for smart pins — Parallax Forums

ADC idea for smart pins

cgraceycgracey Posts: 14,133
edited 2018-11-17 14:25 in Propeller 2
Imagine this mode:

- At the start of each measurement period, some 16-bit (negative) constant is loaded into a 16-bit accumulator.

- On each clock, another 16-bit constant is added into the accumulator if the ADC output bit is high.

- At the end of the measurement period, the accumulator is output for reading via RDPIN.


Now, if we could automate the production of those calibration constants, we could have a smart pin ADC mode that returns proper conversions that are scaled and zeroed.

Comments

  • cgraceycgracey Posts: 14,133
    edited 2018-11-17 14:57
    On second thought, there would be a 32-bit accumulator.

    The initial 16-bit constant gets loaded into the top 16 bits of the accumulator. Bottom 16 bits are cleared.

    The 16-bit adder constant adds into the 32-bit accumulator.

    The upper 16 bits of the accumulator are the result.
  • cgraceycgracey Posts: 14,133
    I dreamed about this all night. I realize that this is the question:

    For an 8-bit conversion, how many clocks does it take to get a variance of 255 one's between GIO and VIO calibration modes?

    Then, we have a measurement period and a (negative) one's offset. No adders are needed, just counters with preloads. Very simple. Time is not constant, although, we can reasonably know what the worst case could be.

  • jmgjmg Posts: 15,148
    cgracey wrote: »
    Now, if we could automate the production of those calibration constants, we could have a smart pin ADC mode that returns proper conversions that are scaled and zeroed.

    That's the tricky bit... The 'calibration constants' vary with process and temperature and voltage....
    The temperature drift seems to be one practical ADC limiting factor, which is not helped by the larger thermal cycling seen in P2 operation ...

    You would probably also want to be able to set the sampling clock.
    There are limits to what the on-chip analog can do, & I think the smart pins can co-operate well with external ADC blocks, like OpAmp+D-FF+Vref for those needing higher ADC resolutions.
  • The scaled aspect of each data point is compelling, without the computational expense of most scaling algorithms, it leaves the cog free do do more with the measurement. Off-loading computation into a smart pin like this makes sense.

    On the other hand, doing the computations with raw measurements and then scaling the final output can enhance accuracy.

    It would be nice to have the option.
  • I think you end up with the same mathematical result as you do currently, with a post-acquisition scale and zero

    The advantage is that scale and zero constants are loaded once at the start, after that you just read the value upon each acquisition, without further math. So that is marginally nicer, but at the expense of hardware complexity.

    What you're describing has some similarities with Goertzel implementation, but you'd need +1 and 0 multipliers instead of +1 and -1, and you'd need the ability to preload the accumulation register. Then, you'd just load the LUT table with a kind of 'dithered constant' - say you need a scaling value of 200.25, you'd load up the LUT with
    200,201,200,200,...

    Its good that you think about these things, Chip.
  • cgraceycgracey Posts: 14,133
    edited 2018-11-17 20:09
    cgracey wrote: »
    I dreamed about this all night. I realize that this is the question:

    For an 8-bit conversion, how many clocks does it take to get a variance of 255 one's between GIO and VIO calibration modes?

    Then, we have a measurement period and a (negative) one's offset. No adders are needed, just counters with preloads. Very simple. Time is not constant, although, we can reasonably know what the worst case could be.

    No scaling needed, as explained above. At least, no higher math than increment.

    Here's how it could work:

    Pick a reasonable estimate for the clocks required (N=300), given a desired sample range of 0..255, then:

    (1) Measure GIO for N clocks, record number of 1's into GIO_ONES.
    (2) Measure Pin for N clocks, subtract GIO_ONES, output sample.
    (3) Measure VIO for N clocks, record number of ones into VIO_ONES.
    (4) Measure Pin for N clocks, subtract GIO_ONES, output sample.
    (5) DIFF_ONES = VIO_ONES - GIO_ONES.
    (6) If DIFF_ONES > 255 then N--, else if DIFF_ONES < 255 then N++
    (7) goto (1)

    So, the calibration works like a tracking ADC and a sample is taken and reported between each alternate GIO and VIO calibration, allowing half the time for actual sample acquisition.

  • cgraceycgracey Posts: 14,133
    Those comparisons could be worked as counters kept during the calibration phases. No need for wide compares.
  • Ok thats kind on nifty. I wonder how much noise the N bouncing around introduces, however.

    Because OzProp has the pin streaming working, we can record some real streams and run some simulations
  • Since you're sampling the pin, does this mean you need to disconnect the pin from the acquisition source in order to calibrate it? How is it disconnected?
  • cgraceycgracey Posts: 14,133
    edited 2018-11-17 20:18
    pedward wrote: »
    Since you're sampling the pin, does this mean you need to disconnect the pin from the acquisition source in order to calibrate it? How is it disconnected?

    There are internal calibration modes where you can connect the ADC input to GIO (GND) or VIO.
  • cgraceycgracey Posts: 14,133
    edited 2018-11-17 20:21
    Tubular wrote: »
    Ok thats kind on nifty. I wonder how much noise the N bouncing around introduces, however.

    Because OzProp has the pin streaming working, we can record some real streams and run some simulations

    There are smart pin modes which count time until so many highs or lows are counted.

    Oh, the N doesn't bounce around if the diff is 255. It need only adjust N if above or below.
  • jmgjmg Posts: 15,148
    cgracey wrote: »
    cgracey wrote: »
    I dreamed about this all night. I realize that this is the question:

    For an 8-bit conversion, how many clocks does it take to get a variance of 255 one's between GIO and VIO calibration modes?

    Then, we have a measurement period and a (negative) one's offset. No adders are needed, just counters with preloads. Very simple. Time is not constant, although, we can reasonably know what the worst case could be.

    No scaling needed, as explained above. At least, no higher math than increment.

    Here's how it could work:

    Pick a reasonable estimate for the clocks required (N=300), given a desired sample range of 0..255, then:

    (1) Measure GIO for N clocks, record number of 1's into GIO_ONES.
    (2) Measure Pin for N clocks, subtract GIO_ONES, output sample.
    (3) Measure VIO for N clocks, record number of ones into VIO_ONES.
    (4) Measure Pin for N clocks, subtract GIO_ONES, output sample.
    (5) DIFF_ONES = VIO_ONES - GIO_ONES.
    (6) If DIFF_ONES > 255 then N--, else if DIFF_ONES < 255 then N++
    (7) goto (1)

    So, the calibration works like a tracking ADC and a sample is taken and reported between each alternate GIO and VIO calibration, allowing half the time for actual sample acquisition.

    That all sounds useful, it would likely need some signal to show when it was correctly tracking ? - because it could take many readings, before the 255 calibrate was attained.


    How would you select differing numbers of resolution bits ? Does that need 2 registers (N & resolution) ?
  • cgraceycgracey Posts: 14,133
    edited 2018-11-17 20:46
    I would like it to be enable-able via a shorthand WRPIN instruction, so that there are 8/10/12-bit modes with preset N starting values in the smart pin logic.

    The point is to make a type of ADC conversion that is dirt simple, at the expense of flexibility. The C flag on RDPIN could tell you if it's tracking.

    The sample rate would be constant for each mode. 8/10/12-bit modes would take something like 640/2560/10240 clocks. IN would go high on each sample report. So, you could exploit this as a timebase for a sampled system.
  • jmgjmg Posts: 15,148
    cgracey wrote: »
    I would like it to be enable-able via a shorthand WRPIN instruction, so that there are 8/10/12-bit modes with preset N starting values in the smart pin logic.

    The point is to make a type of ADC conversion that is dirt simple, at the expense of flexibility. The C flag on RDPIN could tell you if it's tracking.

    The sample rate would be constant for each mode. 8/10/12-bit modes would take something like 640/2560/10240 clocks. IN would go high on each sample report. So, you could exploit this as a timebase for a sampled system.

    That does sound easy to explain and document.
  • cgraceycgracey Posts: 14,133
    edited 2018-11-17 20:56
    I really want to make DAC and ADC pins accessible to people venturing into assembly language.

    And these shorthand WRPIN instructions even work on spans of pins. So, with a single long instruction, you can fire up a whole range of ADC pins that are synchronized. Then, you can read each one via RDPIN.

    Phil's been complaining that the chip is too complex, so stuff like this will make it simpler.
  • ElectrodudeElectrodude Posts: 1,621
    edited 2018-11-17 20:59
    cgracey wrote: »
    Phil's been complaining that the chip is too complex, so stuff like this will make it simpler.
    Things like these shorthand WRPIN instructions just make it more complex! This is what compiler macros are for!
  • cgraceycgracey Posts: 14,133
    cgracey wrote: »
    Phil's been complaining that the chip is too complex, so stuff like this will make it simpler.
    Things like these shorthand WRPIN instructions just make it more complex! This is what compiler macros are for!

    I've been programming smart pins for a while and I see there's a huge need for this. It keeps your head clear by keeping your code clean.
  • jmgjmg Posts: 15,148
    cgracey wrote: »
    ... The C flag on RDPIN could tell you if it's tracking.

    The sample rate would be constant for each mode. 8/10/12-bit modes would take something like 640/2560/10240 clocks. IN would go high on each sample report. So, you could exploit this as a timebase for a sampled system.

    Sounds a good start - those sample times could be tested on a Rev A device, (maybe with low noise VIO ?) to see if they needed tuning, before being locked into silicon.
    I'm not sure much testing has been done on many ADC's running, to check for crosstalk effects etc.
  • cgraceycgracey Posts: 14,133
    Yeah, I will test this concept on the current silicon when I get home today. I could completely model what the smart pin would do using existing smart pin modes.
  • RaymanRayman Posts: 13,892
    What if pin is beyond the rails?
  • cgraceycgracey Posts: 14,133
    edited 2018-11-17 21:40
    Rayman wrote: »
    What if pin is beyond the rails?

    Then you get a negative or overly positive number. Due to some noise, that would happen under normal circumstances.

    There will need to be an option to clip samples to 0 or 255.
  • ElectrodudeElectrodude Posts: 1,621
    edited 2018-11-17 22:32
    cgracey wrote: »
    cgracey wrote: »
    Phil's been complaining that the chip is too complex, so stuff like this will make it simpler.
    Things like these shorthand WRPIN instructions just make it more complex! This is what compiler macros are for!

    I've been programming smart pins for a while and I see there's a huge need for this. It keeps your head clear by keeping your code clean.

    Instead of adding the new pin instructions and using up the two D/S instruction slots, can't you just change WRPIN so that prefixing it with SETQ overrides the specified config/DAC value, and then make new PINDRV/PINDAC/PINwhatever mnemonics that are really just aliases for SETQ+WRPIN $ugly_constant? The code will look the same as it would with your new shortcut instructions: each SETxxx line would just assemble to SETQ+WRPIN instead of a single native instruction.

    (Sorry, this probably should have gone in the other thread.)
  • evanhevanh Posts: 15,188
    Bunnies for transistors next. ;)

  • jmgjmg Posts: 15,148
    cgracey wrote: »
    Rayman wrote: »
    What if pin is beyond the rails?

    Then you get a negative or overly positive number. Due to some noise, that would happen under normal circumstances.

    There will need to be an option to clip samples to 0 or 255.

    Users might want to measure current sense voltages, 'thru ground', and there is also measure the +ve Clamp Diode as a means of temperature sense.
    What are the returned values for < 0 and > 255 ? Users should be able to tell where they are at all time ?
  • cgraceycgracey Posts: 14,133
    S
    jmg wrote: »
    cgracey wrote: »
    Rayman wrote: »
    What if pin is beyond the rails?

    Then you get a negative or overly positive number. Due to some noise, that would happen under normal circumstances.

    There will need to be an option to clip samples to 0 or 255.

    Users might want to measure current sense voltages, 'thru ground', and there is also measure the +ve Clamp Diode as a means of temperature sense.
    What are the returned values for < 0 and > 255 ? Users should be able to tell where they are at all time ?

    The 32-bit returned value could be slightly negative ($FFFFFFFx) or over 255 ($0000010x).
  • jmgjmg Posts: 15,148
    edited 2018-11-17 23:58
    cgracey wrote: »
    jmg wrote: »
    cgracey wrote: »
    Rayman wrote: »
    What if pin is beyond the rails?

    Then you get a negative or overly positive number. Due to some noise, that would happen under normal circumstances.

    There will need to be an option to clip samples to 0 or 255.

    Users might want to measure current sense voltages, 'thru ground', and there is also measure the +ve Clamp Diode as a means of temperature sense.
    What are the returned values for < 0 and > 255 ? Users should be able to tell where they are at all time ?

    The 32-bit returned value could be slightly negative ($FFFFFFFx) or over 255 ($0000010x).

    Thought so, those seem easy enough for users to manage without needing HW clipping ? Hardware clipping can mask problems...
    The (slightly) 'outside the rails' aspect of the P2 ADC is a useful feature.
Sign In or Register to comment.