Part Number:MSP432P401R
Hello folks,
I am looking for a sanity check on my settings of the ADC for the MSP432. If someone could please confirm everything below looks correct (without any blatant bugs that could cause jumpy ADC readings) I would be very grateful. I call initialize_adcs() function at the beginning of the program once, prioritize ADC14_IRQHandler() ISR as shown below.
MAP_Interrupt_setPriority(FAULT_SYSTICK, 0x10); MAP_Interrupt_setPriority(INT_PORT1, 0x20); MAP_Interrupt_setPriority(INT_ADC14, 0x20);
I then call the following once, prior to the main while() loop:
ADC14->CTL0 |= ADC14_CTL0_ENC | /*!< ADC14 enable conversion - same as MAP_ADC14_toggleConversionTrigger(); */ ADC14_CTL0_SC; /*!< ADC14 start conversion */
I am reading ADC 0-13 and pull the internal temperature sensor info which required some unclear modification... (which is mostly why I am concerned regarding the settings below)
void initialize_adcs(void) { // Initialize the shared reference module. By default, REFMSTR=1 => REFCTL is used to configure the internal reference while(REF_A->CTL0 & REF_A_CTL0_GENBUSY);// If ref generator busy, WAIT REF_A->CTL0 |= REF_A_CTL0_VSEL_0 | // Enable internal 1.2V reference REF_A_CTL0_ON; // Turn reference on REF_A->CTL0 |= REF_A_CTL0_ON; // Turn reference on REF_A->CTL0 &= ~REF_A_CTL0_TCOFF; // Enable temperature sensor // Turn on ADC14, extend sampling time to avoid overflow of results ADC14->CTL0 = ADC14_CTL0_ON | /*!< ADC14 on */ ADC14_CTL0_MSC | /*!< ADC14 multiple sample and conversion */ ADC14_CTL0_SHT0__192 | /*!< 192 */ ADC14_CTL0_SHP | /*!< ADC14 sample-and-hold pulse-mode select */ ADC14_CTL0_CONSEQ_3; /*!< Repeat-sequence-of-channels */ ADC14->CTL1 |= ADC14_CTL1_TCMAP; // Enable internal temperature sensor ADC14->MCTL[0] = ADC14_MCTLN_INCH_0; // ref+=AVcc, channel = A0 ADC14->MCTL[1] = ADC14_MCTLN_INCH_1; // ref+=AVcc, channel = A1 ADC14->MCTL[2] = ADC14_MCTLN_INCH_2; // ref+=AVcc, channel = A2 ADC14->MCTL[3] = ADC14_MCTLN_INCH_3; // ref+=AVcc, channel = A3 ADC14->MCTL[4] = ADC14_MCTLN_INCH_4; // ref+=AVcc, channel = A4 ADC14->MCTL[5] = ADC14_MCTLN_VRSEL_1 | ADC14_MCTLN_INCH_22; // ADC input ch A22 => temp sense // ADC14->MCTL[5] = ADC14_MCTLN_INCH_5; // original code without temperature sensor ADC14->MCTL[6] = ADC14_MCTLN_INCH_6; // ref+=AVcc, channel = A6 ADC14->MCTL[7] = ADC14_MCTLN_INCH_7; // ref+=AVcc, channel = A7 ADC14->MCTL[8] = ADC14_MCTLN_INCH_8; // ref+=AVcc, channel = A8 ADC14->MCTL[9] = ADC14_MCTLN_INCH_9; // ref+=AVcc, channel = A9 ADC14->MCTL[10] = ADC14_MCTLN_INCH_10; // ref+=AVcc, channel = A10 ADC14->MCTL[11] = ADC14_MCTLN_INCH_11; // ref+=AVcc, channel = A11 ADC14->MCTL[12] = ADC14_MCTLN_INCH_12; // ref+=AVcc, channel = A12 ADC14->MCTL[13] = ADC14_MCTLN_INCH_13| // ref+=AVcc, channel = A13 ADC14_MCTLN_EOS; ADC14->IER0 = ADC14_IER0_IE13; // Enable ADC14IFG.7 while(!(REF_A->CTL0 & REF_A_CTL0_GENRDY)); // Wait for reference generator to settle __enable_interrupt(); NVIC->ISER[0] = 1 << ((ADC14_IRQn) & 31); // Enable ADC interrupt in NVIC module } /* ADC14 interrupt service routine */ void ADC14_IRQHandler(void) { if (ADC14->IFGR0 & ADC14_IFGR0_IFG13) { A0results[0] = ADC14->MEM[0]; y1_sim = A0results[0]; A0results[1] = ADC14->MEM[1]; A0results[2] = ADC14->MEM[2]; A0results[3] = ADC14->MEM[3]; y2_sim = A0results[3]; A0results[4] = ADC14->MEM[4]; A0results[5] = ADC14->MEM[5]; temp = A0results[5]; lift_off1[0] = ADC14->MEM[6]; lift_off1[1] = ADC14->MEM[7]; lift_off1[2] = ADC14->MEM[8]; lift_off2[0] = ADC14->MEM[9]; lift_off2[1] = ADC14->MEM[10]; lift_off2[2] = ADC14->MEM[11]; A0results[12] = ADC14->MEM[12]; A0results[13] = ADC14->MEM[13]; } }
I am most concerned about ADC values jumping for no reason which could trigger unwanted effects in our system.
Thank you,
Bob