Other Parts Discussed in Thread: C2000WARE
void
AdcConversion_run(int *conv)
{
EALLOW;
AdcRegs.INTSEL1N2.bit.INT1E = 1;
AdcRegs.INTSEL1N2.bit.INT1CONT = 0;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcRegs.INTSEL1N2.bit.INT1SEL = 5; // EOC5 triggers ADCINT1
// Force Start SOC0-5 to begin ping-pong sampling
//
AdcRegs.ADCSOCFRC1.all = 0x003F;
//
// Wait for ADCINT1 to trigger, then add ADCRESULT0-5 registers to sum
//
while (AdcRegs.ADCINTFLG.bit.ADCINT1 == 0)
{
}
//
// Must clear ADCINT1 flag since INT1CONT = 0
//
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
conv[0]= (int)AdcResult.ADCRESULT0;
conv[1]= (int)AdcResult.ADCRESULT1;
conv[2]= (int)AdcResult.ADCRESULT2;
conv[3]= (int)AdcResult.ADCRESULT3;
conv[4]= (int)AdcResult.ADCRESULT4;
conv[5]= (int)AdcResult.ADCRESULT5;
//
// Disable ADCINT1 to STOP
//
AdcRegs.INTSEL1N2.bit.INT1E = 0;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
AdcRegs.ADCINTOVFCLR.bit.ADCINT1 = 1;
//
// reset RR pointer to 32, so that next SOC is SOC0
//
AdcRegs.SOCPRICTL.bit.SOCPRIORITY = 1;
while( AdcRegs.SOCPRICTL.bit.SOCPRIORITY != 1 );
AdcRegs.SOCPRICTL.bit.SOCPRIORITY = 0;
while( AdcRegs.SOCPRICTL.bit.SOCPRIORITY != 0 );
EDIS;
}
void
AdcChanSelect_run()
{
EALLOW;
AdcRegs.ADCSOC0CTL.bit.CHSEL= 3;
AdcRegs.ADCSOC1CTL.bit.CHSEL= 11;
AdcRegs.ADCSOC2CTL.bit.CHSEL= 4;
AdcRegs.ADCSOC3CTL.bit.CHSEL= 12;
AdcRegs.ADCSOC4CTL.bit.CHSEL= 5;
AdcRegs.ADCSOC5CTL.bit.CHSEL= 13;
Uint16 ACQPS_Value = 50;
AdcRegs.ADCSOC0CTL.bit.ACQPS = ACQPS_Value;
AdcRegs.ADCSOC1CTL.bit.ACQPS = ACQPS_Value;
AdcRegs.ADCSOC2CTL.bit.ACQPS = ACQPS_Value;
AdcRegs.ADCSOC3CTL.bit.ACQPS = ACQPS_Value;
AdcRegs.ADCSOC4CTL.bit.ACQPS = ACQPS_Value;
AdcRegs.ADCSOC5CTL.bit.ACQPS = ACQPS_Value;
AdcRegs.INTSEL1N2.bit.INT1E = 1;
// AdcRegs.INTSEL1N2.bit.INT2E = 1;
//
// Disable continuous sampling for ADCINT1 and ADCINT2
//
AdcRegs.INTSEL1N2.bit.INT1CONT = 0;
// AdcRegs.INTSEL1N2.bit.INT2CONT = 0;
//
// ADCINTs trigger at end of conversion
//
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//
// Setup ADCINT1 and ADCINT2 trigger source
//
AdcRegs.INTSEL1N2.bit.INT1SEL = 5; // EOC6 triggers ADCINT1
// AdcRegs.INTSEL1N2.bit.INT2SEL = 14; // EOC14 triggers ADCINT2
//
// Setup each SOC's ADCINT trigger source
//
AdcRegs.ADCINTSOCSEL1.bit.SOC0 = 0; // ADCINT2 starts SOC0-7
AdcRegs.ADCINTSOCSEL1.bit.SOC1 = 0;
AdcRegs.ADCINTSOCSEL1.bit.SOC2 = 0;
AdcRegs.ADCINTSOCSEL1.bit.SOC3 = 0;
AdcRegs.ADCINTSOCSEL1.bit.SOC4 = 0;
AdcRegs.ADCINTSOCSEL1.bit.SOC5 = 0;
AdcRegs.ADCINTSOCSEL1.bit.SOC6 = 0;
AdcRegs.ADCINTSOCSEL1.bit.SOC7 = 0;
AdcRegs.ADCINTSOCSEL2.bit.SOC8 = 0; // ADCINT1 starts SOC8-15
AdcRegs.ADCINTSOCSEL2.bit.SOC9 = 0;
AdcRegs.ADCINTSOCSEL2.bit.SOC10 = 0;
AdcRegs.ADCINTSOCSEL2.bit.SOC11 = 0;
AdcRegs.ADCINTSOCSEL2.bit.SOC12 = 0;
AdcRegs.ADCINTSOCSEL2.bit.SOC13 = 0;
AdcRegs.ADCINTSOCSEL2.bit.SOC14 = 0;
AdcRegs.ADCINTSOCSEL2.bit.SOC15 = 0;
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
EDIS;
}
void
main(void)
{
int conv[6];
//
// *IMPORTANT*
// The Device_cal function, which copies the ADC calibration values from TI
// reserved OTP into the ADCREFSEL and ADCOFFTRIM registers, occurs
// automatically in the Boot ROM. If the boot ROM code is bypassed during
// the debug process, the following function MUST be called for the ADC to
// function according to specification. The clocks to the ADC MUST be
// enabled before calling this function.
// See the device data manual and/or the ADC Reference
// Manual for more information.
//
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
(*Device_cal)();
EDIS;
EALLOW;
//
// To powerup the ADC the ADCENCLK bit should be set first to enable
// clocks, followed by powering up the bandgap, reference circuitry,
// and ADC core. Before the first conversion is performed a 5ms delay must
// be observed after power up to give all analog circuits time to power up
// and settle
//
//
// Please note that for the delay function below to operate correctly the
// CPU_RATE define statement in the F2806x_Examples.h file must
// contain the correct CPU clock period in nanoseconds.
//
EALLOW;
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power ADC BG
AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power reference
AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power ADC
AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC
AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; // Select interal BG
EDIS;
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
EALLOW;
AdcRegs.ADCCTL2.bit.CLKDIV2EN = 1;
EDIS;
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
InitAdcAio(); //provided by C2000ware
AdcOffsetSelfCal(); //provided C2000ware
AdcChanSelect_run(); //only run one time
AdcConversion_run(conv);
phase1_current=((float)(conv[0]-conv[1])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN0,AN1
phase3_current=((float)(conv[2]-conv[3])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN2,AN3 EO: was phase2 wrongly
phase2_current=((float)(conv[4]-conv[5])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN4,AN5 EO: was phase3 wrongly
AdcConversion_run(conv);
phase1_current=((float)(conv[0]-conv[1])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN0,AN1
phase3_current=((float)(conv[2]-conv[3])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN2,AN3 EO: was phase2 wrongly
phase2_current=((float)(conv[4]-conv[5])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN4,AN5 EO: was phase3 wrongly
AdcConversion_run(conv);
phase1_current=((float)(conv[0]-conv[1])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN0,AN1
phase3_current=((float)(conv[2]-conv[3])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN2,AN3 EO: was phase2 wrongly
phase2_current=((float)(conv[4]-conv[5])/4096.0f)*new_param.target_nominal_phase_gain; // Results for AN4,AN5 EO: was phase3 wrongly
}