Part Number: CCSTUDIO-C2000
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE
Hi,
I am trying to understand how to program ADC1 and is there any document I can refer to?
I have some existing sample codes for initialization but when i tried to print out the reading value and it seems all 0s.
void ADC_Init()
{
*(unsigned int*)0x4E58 = 7; // Workaround for InitAnalogSystemClock() Advisory
if( ((**InitAnalogSystemClock)(ACLKDIV4) | 0x8000) != 0xA005 ) {
// If return value is not 0xA005, then analog subsystem did not initialize correctly
asm (" ESTOP0");
for(;;) ;
}
EALLOW;
// Initialize the Analog Sub-System and set the clock divider to divide by 4
while((**AnalogClockEnable)(AnalogConfig1,ADC1_ENABLE)); // Enable ADC 1
while((**AnalogClockEnable)(AnalogConfig2,ADC2_ENABLE)); // Enable ADC 2
(**ReadAnalogClockStatus)(AnalogConfig2); // Wait for AnalogClockEnable function to finish
// Reset both ADC in case the last reset was a debugger reset (which doesn't
// reset the ADCs
Adc1Regs.ADCCTL1.bit.RESET = 1;
// Wait to ensure ADCs are out of reset before device cal is called
__asm(" nop");
__asm(" nop");
// Calibrate the device for temperature
(**Device_Cal)();
EDIS;
//Init the ADC
InitAdc1();
// Configure ADC readings to trigger continuously (ping-pong between ADCINT1 and ADCINT2)
EALLOW;
Adc1Regs.ADCCTL2.bit.ADCNONOVERLAP = 1; // Enable non-overlap mode i.e. conversion and future sampling events don't overlap
Adc1Regs.ADCCTL1.bit.INTPULSEPOS = 0; // ADCINT1 trips after ADCResults latch
Adc1Regs.INTSEL1N2.bit.INT1E = 1; // Enabled ADCINT1
Adc1Regs.INTSEL1N2.bit.INT2E = 1; // Enabled ADCINT2
Adc1Regs.INTSEL1N2.bit.INT1CONT = 1; // Enable ADCINT1 Continuous mode
Adc1Regs.INTSEL1N2.bit.INT2CONT = 1; // Enable ADCINT2 Continuous mode
Adc1Regs.INTSEL1N2.bit.INT1SEL = 3; // setup EOC3 to trigger ADCINT1 to fire
Adc1Regs.INTSEL1N2.bit.INT2SEL = 1; // setup EOC1 to trigger ADCINT2 to fire
Adc1Regs.ADCSOC0CTL.bit.CHSEL = 0; // set SOC0 channel select to ADC1A0 (EOC0)
Adc1Regs.ADCSOC1CTL.bit.CHSEL = 2; // set SOC1 channel select to ADC1A2 (EOC1)
Adc1Regs.ADCSOC2CTL.bit.CHSEL = 3; // set SOC2 channel select to ADC1A3 (EOC2)
Adc1Regs.ADCSOC3CTL.bit.CHSEL = 4; // set SOC3 channel select to ADC1A4 (EOC3)
Adc1Regs.ADCINTSOCSEL1.bit.SOC0 = 2; // ADCINT2 triggers SOC0
Adc1Regs.ADCINTSOCSEL1.bit.SOC1 = 2; // ADCINT2 triggers SOC1
Adc1Regs.ADCINTSOCSEL1.bit.SOC2 = 1; // ADCINT1 triggers SOC2
Adc1Regs.ADCINTSOCSEL1.bit.SOC3 = 1; // ADCINT1 triggers SOC3
Adc1Regs.ADCSOC0CTL.bit.ACQPS = 25; // set SOC0 S/H Window to 26 ADC Clock Cycles, (25 ACQPS plus 1)
Adc1Regs.ADCSOC1CTL.bit.ACQPS = 25; // set SOC1 S/H Window to 26 ADC Clock Cycles, (25 ACQPS plus 1)
Adc1Regs.ADCSOC2CTL.bit.ACQPS = 25; // set SOC2 S/H Window to 26 ADC Clock Cycles, (25 ACQPS plus 1)
Adc1Regs.ADCSOC3CTL.bit.ACQPS = 25; // set SOC3 S/H Window to 26 ADC Clock Cycles, (25 ACQPS plus 1)
EDIS;
DELAY_US(5000);
// EALLOW;
// PieVectTable.ADCINT1 = &ADC_ISR;
// EDIS; // This is needed to disable write to EALLOW protected registers
//
// // Enable ADCINT1 in PIE
// PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
// IER |= M_INT1; // Enable CPU Interrupt 1
//Manually start a conversion
Adc1Regs.ADCSOCFRC1.bit.SOC0 = 1; // trigger a conversion on SOC0
Adc1Regs.ADCSOCFRC1.bit.SOC1 = 1; // trigger a conversion on SOC1
Adc1Regs.ADCSOCFRC1.bit.SOC2 = 1; // trigger a conversion on SOC2
Adc1Regs.ADCSOCFRC1.bit.SOC3 = 1; // trigger a conversion on SOC3
}