Shop OBEX P1 Docs P2 Docs Learn Events
higher resolution adc — Parallax Forums

higher resolution adc

Peter VerkaikPeter Verkaik Posts: 3,956
edited 2006-10-01 10:22 in General Discussion
I did some calculations for a higher resoluton adc, adapting the 8bit adc schematic.
See attachement.
For this to work, I think the high byte output (Ux, original 8bit output) must be hold at the
highest possible value below VCC/2, then find·the low byte output value (Uy).
Has anyone tried this before? Is this workable? 16bits probably won't work due to
discharge (and noise) effects, but 12bits (by increasing/decreasing the low byte in 0x10 steps)
should be possible.
The way I try it now, it requires 512 isr·cycles to complete a conversion.
(256 cycles for high byte and 256 cycles for low byte)
Does anybody know a way to do it in 256 isr cycles (as the 8bit)? Or less?

Edit: I attached some code I came up with.

regards peter



Post Edited (Peter Verkaik) : 9/9/2006 4:17:27 PM GMT

Comments

  • pjvpjv Posts: 1,903
    edited 2006-09-09 18:23
    Hi Peter;

    For precision measurement of resistance (temperature) of a 100 Ohm RTD without any amplifiers, I'm doing something similar to your suggestion, but with a significant difference.

    I use two DACs with appropriately scaled resistors and a single capacitor; a "coarse" (8 bits) to get me close to the temperature range I'm interested in , then a "fine" (8 bits) to get better resolution. I do not scale the two DACs by 256X as you are suggesting, as all I want for resolution is one byte at (near) a chosen temperature. Both DACs have a DUTY value and an accumulator, and each output port bit is toggled on the corresponding overflow.

    This approach works great for my application as I'm easily able to achieve 1 millivolt resolution. I have not tried, but I believe that with some more software filtering/averaging, a sensitivity of 100 microvolts or better can be achieved.

    What you are doing sounds good in concept, but I believe you are stalling the coarse DAC's PWM inappropriately, and that will cause errors. If you treat them independently, then the concept should work.

    Also, I do have concerns about you being able to pick resistors accurately enough to match the two ranges.

    Anyhow, try it and let us know what you find.

    Aren't these virtual ADC's wonderful?

    Cheers,

    Peter (pjv)
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-09-09 19:08
    Hi pjv,

    The resistor values are probably a problem, however for 12bits resolution
    I could use R3=16R instead of 256R, and then use 0 <= Ny <= 15 (or 16).

    The stalling of the outH pin is another problem. If however the pwm's are independant
    then outH may be turned high leading to Ut > VCC/2 and this then interferes with
    the outL pin. I think with an appropiate C value the charge/discharge time due to outH
    should be so that the rise/fall of Ut is within the time needed to find outL.

    Or perhaps adding extra C's to have some 'stable' Ux and Uy.
    Any suggestions?
    Edit: after outH is done, I should make outH pin (Ux) an input,
    then C is only charged/discharged via pin outL (Uy)

    regards peter


    Post Edited (Peter Verkaik) : 9/9/2006 7:20:15 PM GMT
  • pjvpjv Posts: 1,903
    edited 2006-09-09 20:41
    Hi Peter;

    No, you can't fudge the C value to hold things stable as it that effect will also telegraph through to the desired readings.

    What you might try instead is to turn the coarse DAC's output pin into an input (Hi-Z) while you are didling with the fine DAC.

    What is the speed of analog input you might want to follow? If it is slow, then there is another approach that should work, similar to my approach... do a coarse aquisition, and then "track" the input with the fine DAC. This allows accuracy within one bit per pass.

    Of course the same resistor problem exists; keeping the result monotonic as the fine range rolls over and bumps the coarse range by one. This may be a considerable detriment.

    Eliminating the monotonicity (resistor) issue is of course desirable. So why not just stretch the standard 8 bit DUTY value and ACCUMULATOR into a 12 bit (or higher) widths, and you're done. Yes, it does slow things down proportionately, but eliminates a lot of other headaches.

    Furthermore, you can dynamically run different width systems..... make your ACCUMULATOR 16 bits, and pick whichever bit you like as the "roll-over/carry" bit to get variable resolution. Naturally, your DUTY width must match your selection of ACCUMULATOR width at the time. In this manner, you could keep 8 (or less) bits while the input is changing rapidly, and increase the bit resolution as things slow down. A long time ago I have actually done this with good results as I recall.

    Anyhow, just some of my thoughts.....

    Cheers,

    Peter (pjv)
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-09-09 23:19
    pjv,

    Do you happen to know the range for RC in respect to Tisr (interrupt cycle time)?
    I like to know Trc = k*Tisr
    After all, if R=10k and C=10000u it takes far more than 256 isr cycles to charge C to VCC/2.
    So there must be a lower and upper limit for RC, in respect to Tisr.

    For the 8bit adc, is the optimum RC = Tisr ?

    regards peter
  • pjvpjv Posts: 1,903
    edited 2006-09-10 00:12
    Hi Peter;

    You know, I have actually not spent much time studying that. On my scope I can see every positive/negative excursion of the capacitor's voltage, and typically it has been in the several millivolt range. The range of 5 Volts divided by 256 is about 20 mV per count.

    I'm going to do some experimentation, but off-hand I suspect that an RC of one epoch would be slow enough. So for 8 bits, that is 256 ISR events.

    Gotta run, more later.

    Cheers,

    Peter (pjv)
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-09-10 19:37
    pjv,

    I took the time to figure out the relation between RC, Ti (interrupt cycle time),·N (resolution)
    and the ripple across the C.
    The resulting formulae are quite·simple.
    Pick a ripple·and you get RC expressed in·Ti.

    Edit: attached an adapted 8bit version that allows for up to 15bit resolution.
    This uses a 16bit accumulator as you suggested.
    I also add calculations to find the real Umin and Umax.
    The formulea for those do not incorporate the charging up to Vcc/2
    and therefore are only accurate when Uin = Vcc/2
    The correction calculation makes it work for all Uin.

    regards peter

    Post Edited (Peter Verkaik) : 9/11/2006 3:24:00 PM GMT
  • ellizardellizard Posts: 106
    edited 2006-09-30 16:06
    Hello Peter and pjv,

    I'm interested in developing a sensor for batteries status, the measures to be measured are: Voltage, Current and Temperature.
    The resolution needed by Voltage is 8bit, for Current at least 12 bit, and for temperature 8 bit.

    I've done till now with usual components, LTC1298 for current and ADC0832 plus Basic Stamp for rest of the program.

    I am mumblering around from several months now if it was possible to obtain with only one sx the same result (measuring, meaning and serial sending).
    reading several spots, i made a succesful prototipe of the two 8-bit conversions required, I came to this thread for trying to solve the 12-bit issue, but i'm facing one problem, because I need a fixed execution rate of the routines, i preferred the B Version.

    In the program Adc16Vp.src of your last post, I could not resolve to work with the B version of the routine, I did notice that the program it' a modified version of another program present in www.sxlist.com/techref/ubicom/lib/io/adc_vp.htm , could be possible to have more information of how the B version works?
    I've also thinked that B Version of the routine was not extended to 16-bit precision. could it be?

    thanks for any suggestion

    Regards
    Stefano
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-09-30 16:48
    You want the version B to be of fixed rate, using the 16bit accu and count

    ;
    ; VERSION A - smaller, quicker but with variable execution rate (16bit)
    ;
    ;:adc0··············jb····port_buff.4,:adc01··;check if adc0 triggered?
    ;···················inc···adc0L_acc···········;if so, increment accumulator
    ;···················snz
    ;···················inc···adc0H_acc
    ;:adc01············ inc···adc0L_count·········;adjust adc0 timing count
    ;···················snz
    ;···················inc···adc0H_count
    ;···················mov·· w,adc0H_count
    ;···················xor···w,#RESOLUTION>>8····;RESOLUTION is $1000 for 12 bits
    ;···················jnz···:done_adcs··········;if not done, jump ahead
    ;:update_adc0· ···· mov···adc0L,adc0L_acc·····;samples ready, update adc0
    ;···················mov···adc0H,adc0H_acc
    ;:clear_adc0········clr···adc0L_acc···········; reset adc0 accumulator
    ;···················clr···adc0H_acc
    ;:clear_count····· ·clr···adc0L_count
    ;·················· clr···adc0H_count
    ;
    ; VERSION B - fixed execution rate (8bit)
    ;
    :adc0············ ··sb··· port_buff.4··· ;check if adc0 triggered
    ··················· incsz·adc0L_acc······;if so, increment accumulator
    ··················· inc···adc0L_acc······; and prevent overflowing
    ··················· dec···adc0L_acc······; by skipping second 'INC'
    ··················· mov· ·w,adc0L_acc··· ;load W from accumulator
    ··················· inc·· adc0L_count··· ;adjust adc0 timing count
    ··················· snz················ ·;are we done taking reading?
    ··················· mov·· adc0L,w······· ;if so, update adc0
    ····················snz················ ·;
    ··················· clr·· adc0L_acc····· ;if so, reset accumulator

    ;
    ; <end of version B>
    ;
    :done_adcs

    These are the code fragments you refer to?

    regards peter
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-09-30 17:20
    Here is a 16bit version B

    ; VERSION B - fixed execution rate
    ;
    :adc0·········· clrb··· Z
    ··············· sb····· port_buff.4······ ····;check if adc0 triggered?
    ················inc···· adc0L_acc·············;if so, increment accumulator
    ··············· snz
    ··············· inc··· ·adc0H_acc
    ····· ········· inc···· adc0L_count···········;adjust adc0 timing count
    ··············· snz
    ··············· inc·····adc0H_count
    ··············· mov···· w,adc0H_count
    ················xor···· w,#RESOLUTION>>8····· ;RESOLUTION is $1000 for 12 bits
    ············································· ;Z set if done
    ··············· mov··· ·w,adc0L_acc···········;load W from accumulator
    ··············· snz·························· ;done?
    ··············· mov···· adc0L,w············· ·;if so, update adc0
    ··············· mov···· w,adc0H_acc·········· ;load W from accumulator
    ··············· snz
    ··············· mov···· adc0H,w············· ·;if so, update adc0
    ··············· mov···· w,#0
    ················snz
    ··············· mov···· adc0L_acc,w···········;if so, reset accumulator
    ················snz
    ··············· mov···· adc0H_acc,w
    ··············· snz
    ··············· mov···· adc0L_count,w········ ;if so, reset counter
    ··············· snz
    ··············· mov···· adc0H_count,w

    ;
    ; <end of version B>
    ;


    regards peter


    Post Edited (Peter Verkaik) : 9/30/2006 5:45:57 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-09-30 21:16
    I put all versions in the attachement.
    Set the RESOLUTION for 1 to 15 bits and select (or not) ADCFIXED.

    regards peter

    Post Edited (Peter Verkaik) : 10/1/2006 5:03:10 AM GMT
  • ellizardellizard Posts: 106
    edited 2006-10-01 07:53
    Thanks Peter

    I knew it was something missing,

    but I'm not that clever with assembler,

    at the moment I'm only cutting and pasting trying to understand what this is for and that for.


    regards
    Stefano
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-10-01 10:22
    Here is an updated version that supports up to 16bits of resolution.
    Just set ADCBITS to the number of bits you want (1 to 16)
    and comment or uncomment ADCFIXED.


    regards peter


    Post Edited (Peter Verkaik) : 10/1/2006 10:26:17 AM GMT
Sign In or Register to comment.