Other Parts Discussed in Thread: C2000WARE
I hope my question is not that naive. I want to use 14 different ADCs with my F28379D control card, for this matter I'm using ADCA, B, and C, and receive the trigger by EPWM6SOCA, to make sure that all ADC results are final I am using 6 ADCs from channel A, 5 from channel B and 3 from channel C and send the EOC trigger by SOC5. Since I am in the middle of coding I just wanted to make sure that I've understood the architecture correctly
""
void ConfigureAdc(void) {
EALLOW;
//********
AdcaRegs.ADCCTL2.bit.PRESCALE = 14; //set ADCCLK divider to /8 ADCCLK = 25MHz
AdcbRegs.ADCCTL2.bit.PRESCALE = 14; //set ADCCLK divider to /8 ADCCLK = 25MHz
AdccRegs.ADCCTL2.bit.PRESCALE = 14; //set ADCCLK divider to /8 ADCCLK = 25MHz
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
AdcSetMode(ADC_ADCC, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//Set pulse positions to late
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdccRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//power up the ADC
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; // Active low
AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; // Active low
AdccRegs.ADCCTL1.bit.ADCPWDNZ = 1; // Active low
//********
EDIS;
//delay for 1ms to allow ADC time to power up
DELAY_US(1000);
EALLOW;
//********
// ADCA
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; //SOC0 will convert pin A0
AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC1 will convert pin A1
AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC2 will convert pin A2
AdcaRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcaRegs.ADCSOC2CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcaRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC3 will convert pin A3
AdcaRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcaRegs.ADCSOC3CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcaRegs.ADCSOC4CTL.bit.CHSEL = 4; //SOC4 will convert pin A4
AdcaRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcaRegs.ADCSOC4CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcaRegs.ADCSOC5CTL.bit.CHSEL = 5; //SOC5 will convert pin A5
AdcaRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcaRegs.ADCSOC5CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
// ADCB
AdcbRegs.ADCSOC0CTL.bit.CHSEL = 0; //SOC0 will convert pin B0
AdcbRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcbRegs.ADCSOC0CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcbRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC1 will convert pin B1
AdcbRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcbRegs.ADCSOC1CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcbRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC2 will convert pin B2
AdcbRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcbRegs.ADCSOC2CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcbRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC3 will convert pin B3
AdcbRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcbRegs.ADCSOC3CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcbRegs.ADCSOC4CTL.bit.CHSEL = 4; //SOC4 will convert pin B4
AdcbRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdcbRegs.ADCSOC4CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
// ADCC
AdccRegs.ADCSOC0CTL.bit.CHSEL = 0; //SOC0 will convert pin C0
AdccRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdccRegs.ADCSOC0CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdccRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC1 will convert pin C1
AdccRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdccRegs.ADCSOC1CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdccRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC2 will convert pin C1
AdccRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps+1 SYSCLK cycles
AdccRegs.ADCSOC2CTL.bit.TRIGSEL = 0xF; //ADCTRIG15 - ePWM6, ADCSOCA trigger the ADC
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 5; //end of SOC5 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
//********
EDIS;
}
// Configure ePWM6 for ADC start of conversion trigger
void ConfigureEpwm6ADC(void) {
// TB (Time Base) Setting
EPwm6Regs.TBPRD = switching_frequency; // 1999->50kHZ, set timer period, 10 bits resolution
EPwm6Regs.TBPHS.bit.TBPHS = 0x0000; // Set phase shift as ZERO
EPwm6Regs.TBCTR = 0x0000; // Clear counter
EPwm6Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading, Slave mode
EPwm6Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm6Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm6Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm6Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm6Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm6Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm6Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group (Will be enabled in main loop )
EPwm6Regs.ETSEL.bit.SOCASEL = 4; // Enable event time-base counter equal to CMPA when the timer is incrementing
EPwm6Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm6Regs.CMPA.bit.CMPA = EPwm6Regs.TBPRD >> 4; // Set compare A value to 2048 counts
EPwm6Regs.TBCTL.bit.CTRMODE = TB_FREEZE; // freeze counter
}
""