Shop OBEX P1 Docs P2 Docs Learn Events
Could someone help with analog resolution while I wait for my new board? — Parallax Forums

Could someone help with analog resolution while I wait for my new board?

While I'm waiting for my replacement board I am trying to get a grip on the analog resolution settings.
I was using the 128 clock 8 bit sampling mode and was getting readings of 0 to 255 at around 1 to 2 volts, don't remember the exact voltages now. With voltages above or below it didn't go any higher or lower.
My interpretation of resolution would mean measuring the complete voltage range with that number of bits. IE: 1 bit would be .01 volt or 1 bit would be .001 volt. It looks like with 8 bit res you cant read the whole voltage range and more bits reads a larger voltage range.
To read from 0 to 3.3 volt do I need to use a larger number of bits. This is what I was trying to figure out when I accidentally touched the wrong pin and ruined my board.
I don't know if I'm stating this correctly.
Is there an explanation of how the resolution works in simple terms somewhere?

Thanks

Comments

  • JRoarkJRoark Posts: 1,215
    edited 2020-01-02 01:22
    Can you post your code so we can better play along?

    Edit: I’m also playing with this from the FlexBASIC side of things (making a wrapper for inline assembly) so I’m very interested in this topic.
  • JRoark wrote: »
    Can you post your code so we can better play along?

    Edit: I’m also playing with this from the FlexBASIC side of things (making a wrapper for inline assembly) so I’m very interested in this topic.

    Set up the adc pins with this:
    asm
        dirl #17
        dirl #19
        dirl #21
        dirl #23
        dirl #25
        dirl #27
        wrpin   ##%100111_0000000_00_11000_0, #17
        wxpin   #%00_1011,  #17
        wrpin   ##%100111_0000000_00_11000_0, #19
        wxpin   #%00_1011,  #19
        wrpin   ##%100111_0000000_00_11000_0, #21
        wxpin   #%00_1011,  #21
        wrpin   ##%100111_0000000_00_11000_0, #23
        wxpin   #%00_1011,  #23
        wrpin   ##%100111_0000000_00_11000_0, #25
        wxpin   #%00_1011,  #25
        wrpin   ##%100111_0000000_00_11000_0, #27
        wxpin   #%00_1011,  #27
        dirh #17
        dirh #19
        dirh #21
        dirh #23
        dirh #25
        dirh #27
      endasm
    
    And to read the pins:
    if ina[17] == 1
        asm
          rdpin  x1,  #17
        endasm
      if ina[19] == 1
        asm
          rdpin  x2,  #19
        endasm
      if ina[21] == 1
        asm
          rdpin  x3,  #21
        endasm
      if ina[23] == 1
        asm
          rdpin  x4,  #23
        endasm
      if ina[25] == 1
        asm
          rdpin  x5,  #25
        endasm
      if ina[27] == 1
        asm
          rdpin  x6,  #27
        endasm
    
  • jmgjmg Posts: 15,173
    edited 2020-01-02 03:21
    CRST1 wrote: »
    I was using the 128 clock 8 bit sampling mode and was getting readings of 0 to 255 at around 1 to 2 volts, don't remember the exact voltages now. With voltages above or below it didn't go any higher or lower.
    The usual dynamic range of the ADC (1:1) is slightly outside the rails, so it should not clamp between 1~2 volts.
    CRST1 wrote: »
    My interpretation of resolution would mean measuring the complete voltage range with that number of bits. IE: 1 bit would be .01 volt or 1 bit would be .001 volt. It looks like with 8 bit res you cant read the whole voltage range and more bits reads a larger voltage range.
    Not quite, usually the full scale divides by the number of 1:1 ADC bits.
    P2 has full scale a bit outside the rails, so let's call that a nominal 4V span for simplicity, so a 12bit ADC would have a 1mV appx LSB.


  • evanhevanh Posts: 15,916
    edited 2020-01-02 03:24
    CRST1 wrote: »
        wrpin   ##%100111_0000000_00_11000_0, #17
        wxpin   #%00_1011,  #17
    

    Your modes aren't matching the write-up. That ADC pin mode is 100x, which is roughly 50 mV (+-25 mV from VIO/2) full scale. And the smartpin mode is set to 2048 clocks per sample.

    EDIT: Here's the mode settings for 5 volts and 128 clocks.
        wrpin   ##%100011_0000000_00_11000_0, #17
        wxpin   #%00_0111,  #17
    
  • evanhevanh Posts: 15,916
    edited 2020-01-02 03:31
    CRST1 wrote: »
    Is there an explanation of how the resolution works in simple terms somewhere?
    Generally, ignoring noise limitations, more time gives greater resolution. Which is what the config table for WXPIN is saying. This is achieved mathematically pretty much as an averaging calculation.

  • Ok, so it is resolution then. I don't remember what happened on the mode setting, maybe just a mistype. So that is why it wasn't reading the full scale of voltage. That will make the difference.
    I will try it again when the boards come in.
    Thanks
Sign In or Register to comment.