sample ADC synced with PWM

Hi All,

I am newbie with nordic, and I need some help.

I am using nRF52832 with softdevice.

I need to generate a 128 kHz clock signal (PWM pulses with 128kHz frequency, duty cycle 50%,) and to sample Analog input at the same frequency (128 kHz) which is synced to the generated pulses (one sample to each cycle of the PWM output)

How can I do that? is there any example?

 

Regards,

Amir

Parents
  • Hi,

    It's possible to do this. It's a quite specialized use case, so I suspect you will have to interact with hardware registers directly in accordance to the product specifications instead of using the drivers. It's not particularly hard to do, but requires spending time reading the specifications for the hardware well to understand the implementation. If you set up the PWM peripheral to generate the pulse as well as a PPI event on each pulse you can trigger a measurement by the SAADC at a frequency up to 200kHz. I recommend reading the PPI documentation linked below, but to summize PPI is Nordics system for allowing two hardware peripherals to send events from one device which trigger a task in the other device without involving the CPU. The SAADC running in continuous mode should be used with this PPI channel as the trigger, and data will accumulate for the CPU to handle whenever it is available.

    Be aware that this sample rate is quite high, so you will not be able to continuously send all the data over BLE at the rate you are collecting it.

    PPI documentation

    SAADC documentation

    PWM documentation

    Note that using PPI, a timer, and the GPIO might be a suitable alternative to using the PWM peripheral. I recommended the PWM peripheral for its accuracy and flexibility, but it might be overkill to use it.

    Best regards,
    Rune Holmgren

Reply
  • Hi,

    It's possible to do this. It's a quite specialized use case, so I suspect you will have to interact with hardware registers directly in accordance to the product specifications instead of using the drivers. It's not particularly hard to do, but requires spending time reading the specifications for the hardware well to understand the implementation. If you set up the PWM peripheral to generate the pulse as well as a PPI event on each pulse you can trigger a measurement by the SAADC at a frequency up to 200kHz. I recommend reading the PPI documentation linked below, but to summize PPI is Nordics system for allowing two hardware peripherals to send events from one device which trigger a task in the other device without involving the CPU. The SAADC running in continuous mode should be used with this PPI channel as the trigger, and data will accumulate for the CPU to handle whenever it is available.

    Be aware that this sample rate is quite high, so you will not be able to continuously send all the data over BLE at the rate you are collecting it.

    PPI documentation

    SAADC documentation

    PWM documentation

    Note that using PPI, a timer, and the GPIO might be a suitable alternative to using the PWM peripheral. I recommended the PWM peripheral for its accuracy and flexibility, but it might be overkill to use it.

    Best regards,
    Rune Holmgren

Children
No Data
Related