In this FAQ i am going to explain about how to do ADC User-defined channel conversion order with the Enhanced Channel Selection Mode
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
In this FAQ i am going to explain about how to do ADC User-defined channel conversion order with the Enhanced Channel Selection Mode
Hi Everyone,
Using ADC, we can do the channel conversions in the user defined order.
We can implement this one with the Enhanced channel selection mode in ADC.
Again, the main purpose of enhanced channel selection mode is for to do the conversions on external channels upto 1024. Please refer below thread:
But if we made EXT_CHN_MUX_SEL bits as 0 then only the internal channel conversions will happens based on the value of INT_CHN_MUX_SEL bits.
The below are the sequence of steps to implement the ADC channel conversion in user defined order. Also refer the section in TRM "Example ADC Conversion Sequence Using Enhanced Channel Selection Mode" to understand more details.
Here i am assuming that i want to do the following conversion order 0,5,6,2,1,3 and 4 with Group-1 in ADC-1.
1. First, we have to program the LUT table to the corresponding ADC area.
I mean LUT area for ADC1 instance will start from the 0xFF3E2000 and for ADC2 instance it will start from 0xFF3A2000.
From this start address this LUT table will occupies total of 96 words, first 32 entries of 32bit words are for event group and second 32 entries 32bit words are for group-1 and third 32 entries of 32bit words are for group-2.
For example, if you are aiming to convert ADC1 and Group-1 channels then your Lookup table should start from (0xFF3E2000 + 32 * 4) that is 0xFF3E2080 address.
Now for example if you want to convert 0,5,6,2,1,3 and 4 channels in this Group-1 then you should program LUT table something as below:
Address - Value
0xFF3E2080 - 0x00000000 /*Channel-0*/
0xFF3E2084 - 0x00000005 /*Channel-5*/
0xFF3E2088 - 0x00000006 /*Channel-6*/
0xFF3E208C - 0x00000002 /*Channel-2*/
0xFF3E2090 - 0x00000001 /*Channel-1*/
0xFF3E2094 - 0x00000003 /*Channel-3*/
0xFF3E2098 - 0x00000004 /*Channel-4*/
2. Now program the ADG1MAXCOUNT register with the number of channels we want to convert, if we want to convert 7 channels then we should program this register with 6.
3. Now enable the enhanced channel selection mode by writing 0xA to the ADG1CHNSELMODECTRL register.
4. Now start the ADC conversion by setting any of the 7 bits in the ADG1SEL register. Here the bits in the ADG1SEL register will not define the channel number, the original channel number will only get from LUT table. Here we want to convert 7 channels with single trigger right so we should set- 7 bits in the ADG1SEL register. If you want to convert only a single channel with single conversion, then you should need to SET only 1 bit in this register.
5. Now wait until the ADC conversion for the Group1 to complete.
6. After completing the ADC conversion, now we can read the ADC data from the ADC RAM using adcGetData function.
7. Here we have to be careful with one thing, the id field in the conversion result in the RAM will not be the actual ID of the channel. This value is CURRENT COUNT value.
It will be always in the sequence like 0, 1, 2 ... So here again we should need to replace the id value with correct id if required using the LUT table again.
I am attaching one example project here, please refer it.
1033.ADC_Enhanced_Channel_Selection_Demo_LC4357.zip
--
Thanks & Regards,
Jagadish.