KurtE
Senior Member+
T3.x adc.startPDB converting to T4 and shared resources:
@mjs513, @defragster, @manitou and @Paul - and others...
Will soon look at merging the ADCL_t4 stuff into ADC library... But first want to play some with how to translate the ADC library code that does Analog reads at a specific frequency:
like my well monitoring stuff sets up DMA on both ADC channels (T3.6) and I have an interval timer setup that gets N samples at a rate of 3000 times per second... So at each interval I do something like:
Luckily @manitou has examples of parts of this for T4, from me to start from (Thanks!) and again I have mentioned parts of this earlier in thread.
for now ignore DMA... The example timed sketch sets up
ADC1 to use hardware trigger with channel 16 (which maps to ADC_ETC)
ADC_ETC0 is setup with -1 chain and trigger 0 and ...
XBAR is setup as glue that says map PIT trigger 0 to ADC_ETC (XBARA1_IN_PIT_TRIGGER0, XBARA1_OUT_ADC_ETC_TRIG00)
Then PIT0 is setup to run at the speed we desire...
(Clear as MUD) Which for my own simple code I can hopefully reasonably easy hack. But more fun will be how to make it such that it works well with other libraries and system code...
Example which timer to use? Example used PIT0, which the system(library) code IntervalTimer uses and sets it's own ISR handler and when you do a begin (for the first time per object) it finds the first free channel of which there are only 4... Could either try to use IntervalTimer code or simply make sure to check/mark the channels. (TCTRL != 0) so that they don't grab same resource.
Should we instead try different timer? QTIMER? which most can be used by PWM, not sure if some of the unused ones could be used, i.e. can they be initialized in a way that does not interfere with PWM
(example I dont think any of QTIMER4 is used, nor 1-3, or 2-1, 2-2, 2-3?
QT4-2 looks like it can optionally used on pin 9...
ADC_ETC: how to choose the different trigger? i.e. should I just pick a specific one for ADC1 and another one for ADC2?
XBAR: I think this sort of takes care of itself, that is you use the register number in it of the OUTPUT Number/2 (either top or bottom half) and value is the input number, so as long as we can pick the proper timer and proper ADC_ETC then no conflict...
But again the more interesting question is how to manage usage of some of the system resources, like Timers, like ADC_ETC Channels (might be more interesting later with touch screen stuff (TSC) I think I would need to read that chapter a few more times (maybe 10)...
I have same question about other resources like FlexIO... In my flexIO library I have some classes to try to manage the timers, shifters, ... But that only works if you use my library...
Well now back to contemplating...
@mjs513, @defragster, @manitou and @Paul - and others...
Will soon look at merging the ADCL_t4 stuff into ADC library... But first want to play some with how to translate the ADC library code that does Analog reads at a specific frequency:
like my well monitoring stuff sets up DMA on both ADC channels (T3.6) and I have an interval timer setup that gets N samples at a rate of 3000 times per second... So at each interval I do something like:
Code:
_adc0_busy = true;
_adc1_busy = true;
_adc0_dma.enable();
_adc1_dma.enable();
adc->enableDMA(ADC_0);
adc->enableDMA(ADC_1);
_adc0_dma.enable();
_adc1_dma.enable();
adc->adc0->startPDB(60 * 50);
adc->adc1->startPDB(60 * 50);
Luckily @manitou has examples of parts of this for T4, from me to start from (Thanks!) and again I have mentioned parts of this earlier in thread.
for now ignore DMA... The example timed sketch sets up
ADC1 to use hardware trigger with channel 16 (which maps to ADC_ETC)
ADC_ETC0 is setup with -1 chain and trigger 0 and ...
XBAR is setup as glue that says map PIT trigger 0 to ADC_ETC (XBARA1_IN_PIT_TRIGGER0, XBARA1_OUT_ADC_ETC_TRIG00)
Then PIT0 is setup to run at the speed we desire...
(Clear as MUD) Which for my own simple code I can hopefully reasonably easy hack. But more fun will be how to make it such that it works well with other libraries and system code...
Example which timer to use? Example used PIT0, which the system(library) code IntervalTimer uses and sets it's own ISR handler and when you do a begin (for the first time per object) it finds the first free channel of which there are only 4... Could either try to use IntervalTimer code or simply make sure to check/mark the channels. (TCTRL != 0) so that they don't grab same resource.
Should we instead try different timer? QTIMER? which most can be used by PWM, not sure if some of the unused ones could be used, i.e. can they be initialized in a way that does not interfere with PWM
(example I dont think any of QTIMER4 is used, nor 1-3, or 2-1, 2-2, 2-3?
QT4-2 looks like it can optionally used on pin 9...
ADC_ETC: how to choose the different trigger? i.e. should I just pick a specific one for ADC1 and another one for ADC2?
XBAR: I think this sort of takes care of itself, that is you use the register number in it of the OUTPUT Number/2 (either top or bottom half) and value is the input number, so as long as we can pick the proper timer and proper ADC_ETC then no conflict...
But again the more interesting question is how to manage usage of some of the system resources, like Timers, like ADC_ETC Channels (might be more interesting later with touch screen stuff (TSC) I think I would need to read that chapter a few more times (maybe 10)...
I have same question about other resources like FlexIO... In my flexIO library I have some classes to try to manage the timers, shifters, ... But that only works if you use my library...
Well now back to contemplating...