Hi,
I have set up the PWM to trigger the ADC via PPI. It works but now i want to verify the exact behaviour by setting a GPIO when the ADC starts a conversion and when it stops. Once the ADC has a new value it will report it via
NRF_DRV_SAADC_EVT_DONE
But how do I do know when the ADC started the task?
The ADC only has following events:
/** @brief Macro for forwarding the new implementation. */ #define NRF_DRV_SAADC_EVT_DONE NRFX_SAADC_EVT_DONE /** @brief Macro for forwarding the new implementation. */ #define NRF_DRV_SAADC_EVT_LIMIT NRFX_SAADC_EVT_LIMIT /** @brief Macro for forwarding the new implementation. */ #define NRF_DRV_SAADC_EVT_CALIBRATEDONE NRFX_SAADC_EVT_CALIBRATEDONE /** @brief Macro for forwarding the new implementation. */ #define nrf_drv_saadc_evt_type_t nrfx_saadc_evt_type_t /** @brief Macro for forwarding the new implementation. */ #define nrf_drv_saadc_done_evt_t nrfx_saadc_done_evt_t /** @brief Macro for forwarding the new implementation. */ #define nrf_drv_saadc_limit_evt_t nrfx_saadc_limit_evt_t /** @brief Macro for forwarding the new implementation. */ #define nrf_drv_saadc_evt_t nrfx_saadc_evt_t /** @brief Macro for forwarding the new implementation. */ #define nrf_drv_saadc_event_handler_t nrfx_saadc_event_handler_t
So I guess with the ADC this is not possible. Then I though of finding the "ADC start" with the PWM.
The PWM is set up this way:
APP_ERROR_CHECK(nrfx_pwm_init(&pwm_instance_s, &pwm_config_s, pwmHandler));
With this handler:
void pwmHandler(nrfx_pwm_evt_type_t event_type, void * p_context) { nrf_gpio_pin_set(gpio.pin_number); }
But this way it would trigger on every event. So I need to specify it. Since the PWM triggers the ADC on NRF_PWM_EVENT_SEQSTARTED0 I need to check it in the handler.
nrfx_ppi_channel_assign(GENAPI_ppi_channels_as[0], nrfx_pwm_event_address_get(&pwm_instance_s, NRF_PWM_EVENT_SEQSTARTED0), nrfx_saadc_sample_task_get());
But the events are different:
void pwmHandler(nrfx_pwm_evt_type_t event_type, void * p_context) { if(event_type == NRF_PWM_EVENT_SEQSTARTED0) //left side of "==" has different event than right side { nrf_gpio_pin_set(gpio.pin_number); } }
PWM event type 1 which is used for PPI:
/** @brief PWM events. */ typedef enum { NRF_PWM_EVENT_STOPPED = offsetof(NRF_PWM_Type, EVENTS_STOPPED), ///< Response to STOP task, emitted when PWM pulses are no longer generated. NRF_PWM_EVENT_SEQSTARTED0 = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[0]), ///< First PWM period started on sequence 0. NRF_PWM_EVENT_SEQSTARTED1 = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[1]), ///< First PWM period started on sequence 1. NRF_PWM_EVENT_SEQEND0 = offsetof(NRF_PWM_Type, EVENTS_SEQEND[0]), ///< Emitted at the end of every sequence 0 when its last value has been read from RAM. NRF_PWM_EVENT_SEQEND1 = offsetof(NRF_PWM_Type, EVENTS_SEQEND[1]), ///< Emitted at the end of every sequence 1 when its last value has been read from RAM. NRF_PWM_EVENT_PWMPERIODEND = offsetof(NRF_PWM_Type, EVENTS_PWMPERIODEND), ///< Emitted at the end of each PWM period. NRF_PWM_EVENT_LOOPSDONE = offsetof(NRF_PWM_Type, EVENTS_LOOPSDONE) ///< Concatenated sequences have been played the specified number of times. } nrf_pwm_event_t;
PWM event type 2 which is available in the handler:
/** @brief PWM driver event type. */ typedef enum { NRFX_PWM_EVT_FINISHED, ///< Sequence playback finished. NRFX_PWM_EVT_END_SEQ0, /**< End of sequence 0 reached. Its data can be safely modified now. */ NRFX_PWM_EVT_END_SEQ1, /**< End of sequence 1 reached. Its data can be safely modified now. */ NRFX_PWM_EVT_STOPPED, ///< The PWM peripheral has been stopped. } nrfx_pwm_evt_type_t;
My question is: how is it possible to measure with an oscilloscope via GPIOs when the ADC that is triggered via PPI from PWM exactly starts and stops.