Product: nrf52840 DK
Softdevice: 17.0.2
Hello,
I would like to start with a very humble statement that I am new to this nrf52 SoCs and would appreciate any of your help.
I am working on a project with a photodiode and two LEDs with different wavelengths. I would like to read the analog values from the photodiode let's say every 0.1ms. There are two gpio outputs from the nrf which toggles the LED each 10 ms. So each GPIO pins are producing 100 Hhz 50% duty cycle PWM signals but are opposite to each other. So once the LED1 is ON, LED2 is OFF and so on.
For the application, synchronization of SAADC SAMPLE START and GPIO transitions are very important.
So I have managed to toggle both the GPIOs with 100 Hz frequency with opposite polarity with the help of a single external timer instance. Let's say NRF_DRV_TIMER_INSTANCE(1). I have used two different PPI channels to assign tasks and events. So the idea was to set the GPIO2 at a different initial state(HIGH) to obtain the result. So GPIO1 start from LOTOHIGH and GPIO2 starts from HITOLOW. Now I have assigned a different timer (NRF_DRV_TIMER_INSTANCE(2)) for the SAADC. This timer ticks at every 0.1ms to trigger the sampling. Also here I have assigned PPI channel to assign the sampling task and timer event. I am reading the value from the saadc_callback handler.
Now I would like to know how to synchronize the operation. That is to trigger the clock or to start the sampling at the rising edge of GPIO1.
1. How can I use the interrupt at the rising edge of the GPIO1 to trigger the SAADC sampling? This is crucial because the first 100 readings from the SAADC will be the analog value from the photosensor caused due to LED1 and the next 100 readings will be generated due to LED2.
2. Is this approach the correct method or is there any other better method?
3. This question covers a different issue but still, I would like to ask. My application is using a BLE features to send the analog value to a central device. Values are sent to the central device inside the saadc_callback handler. If I had to start the sampling and the GPIO output state transition only after a successful connection is established with the central device, what would be the right way to program the firmware? Are there existing example codes explaining similar usage? (I believe the answer is YES. But I was not able to find any. Please help me out with this.)
Again thank you for your time and would appreciate any of your valuable suggestions.
Karlz