Hello there,
I would like to read the data I sent through a WS2812b LED string. I drove it using I2S. Upon reading it, seems like it is not a good idea to read it using I2S.
Therefore, I am trying to read it back using COMP (as suggested by a Nordic engineer).
A problem is that I do not understand how the COMP works. I set it to call the handler every time the voltage changes (yes, I need to detect when it changes to 0 and when it changes to 1).
Here is my handler:
static void comp_event_handler(nrf_comp_event_t event) {
if (event == NRF_COMP_EVENT_CROSS) {
nrf_gpio_pin_set(DEBUG_PIN);
///nrf_delay_us(5);
nrf_gpio_pin_clear(DEBUG_PIN);
}
}
and here is my COMP initialization:
static void comp_init(void) {
#define lo_volt 0.59 // The voltage indicating "0"
#define hi_volt 1.4 // The voltage indicating "1"
double Ref_voltage = 2.4;
double ThresholdLo = (Ref_voltage / 1024) * lo_volt;
double ThresholdHi = (Ref_voltage / 1024) * hi_volt;
uint32_t err_code = NRF_SUCCESS;
nrf_drv_comp_config_t comp_config = NRF_DRV_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0);
comp_config.isource = NRF_COMP_ISOURCE_Ien5uA;
// Configure threshold voltages.
comp_config.threshold.th_down = VOLTAGE_THRESHOLD_TO_INT(ThresholdLo, Ref_voltage);
comp_config.threshold.th_up = VOLTAGE_THRESHOLD_TO_INT(ThresholdHi, Ref_voltage);
comp_config.isource = NRF_COMP_ISOURCE_Off;
comp_config.main_mode = NRF_COMP_MAIN_MODE_SE;
err_code = nrf_drv_comp_init(&comp_config, comp_event_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_CROSS_MASK, NULL);
}
From what I learned, I need to respect the power limitation on nRF52832. Therefore, I stepped-down the data from the last LED string (from 3.x V to 1.x V) using a Level Converter.
I figured out that the electricity of 1.2 V, 1.4 V or max 1.8 V indicates a 1, while the electricity of 58.59 mV indicates 0, as captured using my oscilloscope:

Using this configuration, I did not receive the output as I expected. Instead, the handler seem to be called every time a noise (as low as 39 mV) is detected (yes, the output of this LED string is really noisy, although there is no more data to be sent and the light is static).
Another problem is when I sent a bunch of data, the COMP seems not calling the handler as much as the data received. Instead, it only trigger once.

The yellow line is the signal created by the handler, and the purple line is the signal from the LED string after being stepped-down.
Is there anything I would have missed?
Thank you in advance.