Hi all,

I just recently started poking around in the IOIO firmware, hoping to add 
some features that aren't particularly relevant.  In any case, I started 
reading adc.c and am confused by the dance done therein.

Briefly, as I understand it, the ADC conversion complete interrupt is 
priority 6 so that it can quickly shut off the ADC.  The ADC interrupt then 
requests a CRC interrupt, down at priority 1, so that *that* interrupt can 
write to shared buffers.  The priority six interrupt might have preempted a 
priority one region of code, so it's not safe to just mutate in the ADC 
handler.  All of that makes sense, but I am vaguely uncomfortable about two 
aspects:  toggling ADON and re-purposing of the CRC IF.

The manual states that one should let the ADC stabilize after asserting 
ADON, so it may be best to leave ADON if there are any pins to be set and 
instead adjust ASAM (even though the manual says that modifying ASAM during 
with ADON asserted may not be the greatest idea -- see note in 17.4 of 
http://ww1.microchip.com/downloads/en/DeviceDoc/39705a.pdf  -- the example 
code does so, e.g. Example 17-8 of the same document).... that said, it 
does not actually discuss stabilization times despite its promise to do so. 
 Harumph.

On the point of the CRC IF, tho', I think it would suffice for adc.c to 
change the ADC IF priority dynamically: the functions which begin a 
conversion can set _AD1IP = FAST_INT_PRIORITY; as ADCInit does now, and the 
ISR itself can reset it to SLOW_INT_PRIORITY and leave the IF asserted 
after stopping the conversion.  Then, the ISR will run *again* at priority 
1 as soon as the CPU drops back to priority 0.  At that point, it's safe to 
write to the shared buffers and clear the IF; it should be very few cycles 
(a bit test and skip looking at SR's IPL or even at ADON itself...) to 
determine which of the two cases the ISR is running in.  This disentangles 
the CRC unit from the ADC and leaves it available for other use. :)

Thoughts?  If it's not crazy, I'll write a patch and test it and submit a 
pull request.

Thanks,
--nwf;

-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to