Hi there,
I'm working on nrf82382, try to use COMP function to monitor the voltage of AIN0(p0.02), but seems not working, no example for the COMP. and then I found the LDCOMP example in the SDK, and copy the some codes from that, and the LDCOMP is work fines.
here is my COMP codes:
void comp_event_handler(nrf_comp_event_t evt) { if (evt == NRF_COMP_EVENT_READY) { LED1_Toggle(); } else if (evt == NRF_COMP_EVENT_DOWN) { LED2_Toggle(); } else if (evt == NRF_COMP_EVENT_UP) { LED3_Toggle(); } else if (evt == NRF_COMP_EVENT_CROSS) { LED4_Toggle(); } } static void lpcomp_event_handler(nrf_lpcomp_event_t event) { if (event == NRF_LPCOMP_EVENT_CROSS) { LED2_Toggle(); } } static void lpcomp_init(void) { uint32_t err_code; nrf_drv_lpcomp_config_t config = NRF_DRV_LPCOMP_DEFAULT_CONFIG; config.input = NRF_LPCOMP_INPUT_0; // initialize LPCOMP driver, from this point LPCOMP will be active and provided // event handler will be executed when defined action is detected err_code = nrf_drv_lpcomp_init(&config, lpcomp_event_handler); nrf_drv_lpcomp_enable(); } int main(void) { LED_Init(); KEY_Init(); nrf_drv_comp_config_t comp_config = NRF_DRV_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0); comp_config.isource = NRF_COMP_ISOURCE_Ien5uA; uint32_t err_code = nrf_drv_comp_init(&comp_config, comp_event_handler); if (err_code != NRFX_SUCCESS) { LED3_Close(); } nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_CROSS_MASK, NRF_DRV_COMP_SHORT_STOP_AFTER_UP_EVT); while (1){ nrf_drv_comp_sample(); // try to sample manually, but still not work. nrf_delay_ms(50); if (KEY1_Down() == 0){ // use that logic to make sure MCU was not hung. LED1_Toggle(); } } }
please help, or is there any example for the COMP in nrf52832?