Hi,
However, If two ADC channles are used, the ADCCMD_1 register should be set whenever before each ADC channel is used.
(is it right?) and so ADCCMD_1 register should be seperated from the ADC_Init Code.
Yes, it is right.
You can define commands in the same way like variables and then use it in the main or ISRs etc.
Each command is actually the sum of 4 ADC command register. This gives 32-bit number (dword). For example:
volatile dword ADC_Command1 = 0x00CDA000;
/* CMD0 = Normal Conversion no interrupts = 0x00
* CMD1 = VRH1, VRL1, HVI (Internal 5)= 0xCD
* CMD2 = 24 clock cycles = 0xA0
* CMD3 = Index = 0x00
*/
You can have more of these defined (ADC_Command2, ADC_Command3,...). For each command you shoul have result variable defined as well (ADC_Result1, ADC_Result2,...)
A better way is to have two arrays defined: ADC Command List and ADC Result List. For example:
volatile char ADC0CL[3][4] = {
{0x00,0xD0,0x00,0x00}, // Normal Conversion + no int [C0], Analog Input Channel AN0 [D0], 4 clock cycles sample time [00], reserved [00]
{0x00,0xD1,0x00,0x00}, // Normal Conversion]+ no int [C0], Analog Input Channel AN1 [D1], 4 clock cycles sample time [00], reserved [00]
{0x00,0x00,0x00,0x00},
}
volatile unsigned int ADC0RL[3] = {0, 0, 0};
The module init function can be something like below:
void InitADC0(void)
{
/*Set ADC0*/
ADC0CTL_0 = 0x0D; /*Dual access, trigger mode*/
/*single CSL & RVL buffers, Normal access Automatic restart after stop*/
ADC0CTL_1 = 0x10;
ADC0STS = 0x00; /*Select CSL 0 & RVL 0*/
ADC0TIM = 0x01; /*Select 32MHz/(2*(1+1)) = 8MHz*/
ADC0FMT = 0x82; /*10Bits right justified*/
/////////////////////////////////////////////////////////////////
/*Set the command pointers*/
ADC0CBP = ADC0CL;
/*Set the results pointer*/
ADC0RBP = ADC0RL;
///////////////////////////////////////////////////////////////
/*Start Conversion*/
ADC0CTL_0 |= 0x80; /*Enable ADC*/
ADC0FLWCTL = 0x20; /*Trigger Restart event*/
}
As you can see there command base pointer register used to get the values which is then used to calculate the final address from which the conversion commands will be loaded.
And aslo result base pointer register which defines address in the RAM to which conversion results will be stored to at the end of a conversion.
See S12ZVx ref. manulal for detailed information.
I am preparing the SW example which wil demonstrate ADC conversions on the S12ZVM device. This should be posted on the community soon.
Regards,
iggi