This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ADC EVENTS_END failed

Hello,

I'm using: nRF51422-QFAA E00 and SDK - nRF51 5.2.0

My problem with ADC is that I stucked when waiting for event - end of conversion. I used the code from Nordic examples called "simultaneous-adc-sampling-from-two-inputs".

Firts strange thing in this code is configuration. Unlike the other examples here they are not using IRQ handler at all and config is:

NRF_ADC->INTENSET = (ADC_INTENSET_END_Disabled << ADC_INTENSET_END_Pos);

Later they force conversion and wait for event (even when it's disabled by config - or event will appear even if interupt for this is disabled?):

// enable ADC		
	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;					  													/* Bit 0 : ADC enable. */		
	
	// start ADC conversion
	NRF_ADC->TASKS_START = 1;
	
	// wait for conversion to end
	while (!NRF_ADC->EVENTS_END)
	{}
	NRF_ADC->EVENTS_END	= 0; 

I always stucked waiting for EVENTS_END. I changed the config to use IRQ and defined IRQ handler but that doesn't help. Finally I found a trick: put 1ms delay between NRF_ADC->ENABLE and TASK_START. But it's not described in Ref. manual or PAN so I don't know if this will help always (I'm working on critical app).

  • Hi

    Hmm, the example should work on your nRF51422 chip. Are you running the code unmodified?

    One thing I think you are misunderstanding. With the line

    	NRF_ADC->INTENSET = (ADC_INTENSET_END_Disabled << ADC_INTENSET_END_Pos);
    

    disables the ADC interrupt. The interrupt is disabled by default so this line is actually not necessary but I think anyway it makes it clear that the ADC interrupt is not enabled. So the ADC_END event and the ADC interrupt are in fact two separate things. If the ADC interrupt handler would be enabled, the ADC interrupt would be triggered on ADC_END event and we would be able to have the ADC interrupt handler to execute on the ADC_END event. The comments for this code are anyway not very good and that may have caused your confusion. I will try to improve them. The ADC_END event is however still enabled and we check for that event with the code

    	while (!NRF_ADC->EVENTS_END)  {}
    

    and then the event flag is cleared so it can be monitored next time we start ADC conversion. You could try to clear the event flag before you start the ADC conversion, with the code

    NRF_ADC->EVENTS_END	= 0;
    
    // start ADC conversion
    NRF_ADC->TASKS_START = 1;
    
    // wait for conversion to end
    while (!NRF_ADC->EVENTS_END)
    {}
    NRF_ADC->EVENTS_END	= 0;
    

    Let me know what you find out.

  • Hi, thanks for reply.

    Well I ADC_INTENSET_END_Disabled was used in example, but in comment for this line is enable. I tried even with enabled option with same result. The problem is that I'm using 2 Analog channels so I have to make CONFIG each time before I'm starting TASK. And here is a problem. Without that 1ms delay I mentioned above it really doesn't work. Same problem but with LCOMP has Michael and delay help him too -> here : devzone.nordicsemi.com/.../

    Even more strange is that with interrupt disabled and with 1ms delay trick event is generated and all working good!

  • I made some experiments and here is a result:

    If I'm enabling IRQ and handling event inside IRQ handler all works good even without any delay between CONFIG and TASK_START.

    If I'm not using IRQ (ADC_INTENSET_END_Disabled) , events are generated anyway so it's OK to use it as in my first post. BUT delay between CONFIG and TASK START is necessary! As i tried now, 1ms is too much, a few clocks should be enough.

    Since app is critical I'll use IRQ solution coz that seems it's prefered(and tested) by Nordic.

Related