Measuring phase shift of a 10kHz analog signal: need help getting started

I'm working with a prototype sensor that changes impedance when environmental conditions change (sorry, can't provide too many details on the sensor itself).

Currently the sensor is read by generating a 10kHz sine wave, and measuring the phase difference using two fast comparators and a digital 12 bit counter with a 2MHz clock. The comparators generate a pulse on zero crossing, one starting and one stopping the counter. The sensor value is read as a 12 bit value from the counter.

I was hoping to simplify the circuit a lot with just an external sine generator, generating a 1.65V centered, 3.3V sine (single supply). And use the nRF52840 comparator to detect zero crossing (using differential mode with the negative input at 1.65V), starting a timer when the reference signal (AIN0) crosses zero, and stopping it when the sensor signal (AIN1) crosses zero. That should give me a good enough resolution. The original circuit uses a 2MHz clock, and I should be able to use the 16MHz timer.

If I understand things correctly, I need to use the comparator, PPI and timer peripherals, using PPI to route events. And that's where I get lost, the only PPI example I found is for timer to timer PPI. I'm assuming I need to set the AIN0 comparator to generate an UP event when the + input is "zero crossing" the - input set at 1.65V (my reference point for the 0 point of the 3.3V signal), and use PPI to start TimerX. Then use the UP event for AIN1 (with same reference point) to stop the timer, and store the value for further processing

Am I on the right path? Is there any guidance on how to properly initialize PPI, comparators and timer for a case like mine? I'm not expecting code, just pointers to get started and avoid going down dead ends

Parents
  • Hi,

    I think you should be on a right path, yes.

    For BLE applications: Some PPI channels and groups are reserved by the SoftDevice. Those are defined in nrf_soc.h. (The same applies for the SoftDevice Controller subsystem in nRF Connect SDK.) Also, some hardware peripherals (such as TIMER0) are restricted or blocked by the SoftDevice.

    There seems to be no pre-programmed channels that could be of any help.

    As for pointers, you are right that the PPI example itself (in nRF5 SDK) handles only the timer peripheral. The approach is however similar no matter which peripherals are involved in the PPI setup. There is use of PPI also in the GPIOTE example (examples/peripheral/gpiote/main.c) and the SAADC example (examples/peripheral/saadc/main.c). Most relevant to your project should be the source code for the capacitive sensor low-level library (components/libraries/csense_drv/nrf_drv_csense.c) which uses COMP events (although slightly differently from what you need.)

    The above assumes nRF5 SDK. If you use nRF Connect SDK, let me know and I will see what pointers we have for that one.

    Regards,
    Terje

  • Very good information, pointers and caveats, thanks a lot. And, yes, I'm using the nRF5 SDK, sorry for not mentioning it in my question.

    I have enough to get started, will ask more specific questions if I get stuck. I'm leaving this open for now, if ok, so that I can add more once I have working code (to help others in the future)

Reply Children
No Data
Related