Shop OBEX P1 Docs P2 Docs Learn Events
Will the smart pin adc measure this safely? — Parallax Forums

Will the smart pin adc measure this safely?

I'm not sure how the adc smart pins measure. Do they measure to actual ground?
The reason for asking is I want to measure the voltage drop across a resistor in a circuit and the resistor will be anywhere from 12 to 25 volts to ground. There will only be less than 1 volt drop across.
Is there a way to measure this between two pins without voltage being too high and burning out the pins,
If there is already something showing this, please let me know,
Thanks for any help.

Comments

  • JonnyMacJonnyMac Posts: 9,469
    edited 2025-10-08 15:24

    Have you considered an external helper chip like the INA219? It's designed to measure across a resistor and will give you voltage and current (via I2C to the P2).

    The P2 has a ground reference, but even that has to be calibrated to use the ADC.

    pub calibrate() : result
    
    '' Calibrate analog input pin for 0 to 3.3v input
    '' -- 12 bits, using SINC2, 2048 samples
    
      pinstart(ap, p_adc | p_adc_gio, 12-1, 0)                      ' measure ground
      waitct(getct() + (2048 << 2))                                 ' allow pin to stablize
      callo := rdpin(ap)                                            ' save ground calibration level
    
      pinstart(ap, p_adc | p_adc_vio, 12-1, 0)                      ' measure vio (3.3v)
      waitct(getct() + (2048 << 2))
      calhi := rdpin(ap)                                            ' save 3.3v calibration level
    
      pinstart(ap, p_adc | p_adc_1x,  12-1, 0)                      ' measure pin level, 1x scale
      waitct(getct() + (2048 << 2))
    
      return read()
    
  • Hi, the smart pins cannot measure in this range. The use GND and the 3V3 supply voltage with all it's noise.

    You could use a voltage divider to ground but be aware of the relative low input impedance (300k as far as I remember).
    Also you could use external cap and resistors similar to the methods used with P1.
    Be also aware, that in reality the precision (ENOB) of the smart pin adc is <11bit, so some calibration might be necessary.

  • evanhevanh Posts: 16,779
    edited 2025-10-08 15:46

    Each ADC can measure down to maybe -0.5 volts. Limited by clamping diodes. The x1 gain has roughly a 5.0 Volt span with numerical 50% centred on VIO / 2, 1.67 Volts. The x1 gain input impedance is something like 500 kOhms to the VIO / 2. Offset drifts around quite a bit so they're not great at instrumentation. Rapid recalibration helps.

  • CRST1CRST1 Posts: 105

    Yeh I though it probably would not work without external chips. But worth a try.
    Thanks for verifing.

  • evanhevanh Posts: 16,779
    edited 2025-10-08 22:09

    Oh, you have large common mode, and variable?, voltage offset! Cripes, I'd want to use an isolated measurement for that. You're inviting faults otherwise.

  • If you want to measure the current of a PWM power stage, for example of a motor driver, you can use capacitive coupling and one of the higher gain modes (p_adc_10x for 0.33V input range). You then need to take two samples, one during the on and one during the off state and subtract the results. I've sucessfully used this trick in a stepper motor driver. This allows current measurement with only one external capacitor.

    However, if you need to measure DC current and voltage you need an external IC, either an OPAMP configured as differential amplifier or a special chip especially designed for high-side shunt resistors.

  • In my solar power setup I use https://www.winson.com.tw/uploads/images/WCS1700.pdf hall sensors. Very easy to use and very easy to interface.

Sign In or Register to comment.