This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/MSP432P401R: MSP432P401R

Part Number: MSP432P401R
Other Parts Discussed in Thread: MSP432WARE

Tool/software: TI-RTOS

My code below works just fine. It takes an ADC reading and turns an LED on if my sonar sensor has an object close to it and turns the LED off if an object is far away. It also has 2 interrupts for the on board buttons that are supposed to change the threshold values, this was from the example code and I am not using it. My question here is...I have 7 sonar sensors. I would like to set up an ISR for each Sonar sensor that will trigger based on a specified range for each one ( that way i can control the motors if objects are close ). My question is how do I set up an interrupt on an ADC reading based on a range I specify. I am trying to make an efficient system to where I have an infinite loop that does nothing and if any of the sonar sensors detect an object at a range I specify it will trigger it's own ISR and change motor speed and so on. I am sure I can accomplish this doing a bunch of if else statements for each reading that change the motor speeds, but I feel this would be a slow inefficient system. If I am wrong please let me know. Example code or API explanations on how to accomplish this would be useful. I am using the reference code from Simplelink  TI Drivers Lab GPIO Interrupt.

  /*

   *  ======== empty.c ========

   */

  /* For usleep() */

  #include <unistd.h>

  #include <stdint.h>

  #include <stddef.h>

  /* Driver Header files */

  #include <ti/drivers/GPIO.h>

  #include <ti/drivers/ADC.h>

  #include <ti/display/Display.h>

  // #include <ti/drivers/I2C.h>

  // #include <ti/drivers/SDSPI.h>

  // #include <ti/drivers/SPI.h>

  // #include <ti/drivers/UART.h>

  // #include <ti/drivers/Watchdog.h>

  /* Board Header file */

  #include "Board.h"

  /* GLOBAL VARIABLES FOR GUI COMPOSER */

  uint16_t adcValue = 0;

  uint16_t threshold = 500;

  uint16_t trigger = 0;

  /*

   *  ======== gpioButtonFxn0 ========

   *  Callback function for the GPIO interrupt on Board_GPIO_BUTTON0.

   */

  void gpioButtonFxn0(uint_least8_t index)

  {

    /* Clear the GPIO interrupt and decrement threshold */

    if(threshold < 250){ // Ensure threshold doesn't go below zero

        threshold = 0;

    } else {

        threshold -= 250; // decrement by 250

    }

  }

  /*

   *  ======== gpioButtonFxn1 ========

   *  Callback function for the GPIO interrupt on Board_GPIO_BUTTON1.

   *  This may not be used for all boards.

   */

  void gpioButtonFxn1(uint_least8_t index)

  {

    /* Clear the GPIO interrupt and increment threshold */

    if(threshold > 16133){ // Ensure threshold doesn't go above max ADC range

        threshold = 16383;

    } else {

        threshold += 250; // increment by 250

    }

  }

  /*

   *  ======== mainThread ========

   */

  void *mainThread(void *arg0)

  {

    /* ~10 loops/second */

    uint32_t time = 100000;

    /* Call driver init functions */

    GPIO_init();

    ADC_init();

    // I2C_init();

    // SDSPI_init();

    // SPI_init();

    // UART_init();

    // Watchdog_init();

    /* Open Display Driver */

    Display_Handle    displayHandle;

    Display_Params    displayParams;

    Display_Params_init(&displayParams);

    displayHandle = Display_open(Display_Type_UART, NULL);

    /* Open ADC Driver */

    ADC_Handle adc;

    ADC_Params params;

    ADC_Params_init(&params);

    adc = ADC_open(Board_ADC6, &params);

    if (adc == NULL) {

        // Error initializing ADC channel 0

        while (1);

    }

    /* install Button callback..... 2 parameters, the IO that will

     * trigger the interrupt & the callback function that we want to

     * execute when the interrupt occurs.  */

    GPIO_setCallback(Board_GPIO_BUTTON0, gpioButtonFxn0);

    GPIO_setCallback(Board_GPIO_BUTTON1, gpioButtonFxn1);

    /* Enable interrupts */

    GPIO_enableInt(Board_GPIO_BUTTON0);

    GPIO_enableInt(Board_GPIO_BUTTON1);

    while (1) {

        int_fast16_t res;

        res = ADC_convert(adc, &adcValue);

        if (res == ADC_STATUS_SUCCESS) {

            Display_printf(displayHandle, 1, 0, "ADC Reading %d", adcValue);

            if(adcValue < threshold){

                GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);

                trigger = 1;

            } else{

                GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF);

                trigger = 0;

            }

        }

        usleep(time);

    }

  }

  • The ADC14 provides some of what you're looking for, in the form of a Window Comparator. [Ref TRM (SLAU356H) Sec. 22.2.9] Using that, you can have it interrupt only when some reading passes some threshold.

    There are only 2 threshold pairs (each hi/low), and only one interrupt pair (each hi/low) for each batch of readings, so as a practical matter you'll have to sift through all the readings in the batch to see which one(s) triggered the comparator.

    But you could still gain something, by setting the threshold(s) to the minimum or maximum (as appropriate) of all your sensor thresholds, so you'd only have to process the readings if e.g. a collision was imminent.

    This is a feature of the hardware; I don't know if/how the driver library you're using provides access to it.
  • So to make sure I am understanding. Using this ADC14 there is still only 1 ISR and it is triggered when any of the sensors readings go outside of my specified threshold. Once this happens I still have to write code to figure out which one was set off and why and then write all the code for each case in the form of if else statements or functions etc.?
  • Yes, that's pretty much it. You can run the ADC "unattended" using the Comparator to watch for (2 possible) thresholds, but once it triggers you have to figure out which channel(s) triggered it. That gains you something most of the time, but you still need the code to check every channel.

    I suppose that if you meter the ADC in the CPU (CONSEQ=3, MSC=0, SHS=0) by issuing a Start (SC) for each channel you would know which channel triggered (the one you just started) but that kind of defeats the idea of "unattended".
  • Okay I think I understand, I can see the use in this still even though the extra code is there it will allow for a "sleep" while nothing is triggered. If you don't mind helping me I have a couple questions on how to use this method. I was reading the "Resolved
    MSP432P401R: Multiple Channel Sample without Repeat only returns the first two values" post that you were involved in. I copied your code and it runs fine, but I am wondering how exactly to add these "comparators" you are talking about. I am confused with how the different CCR#, CAPTURECOMPARE_REGISTER_# AND MM# relate to which ADC pins I am using. Also do i even use the Timer Capture to do this or use a comparator function? These APIs are sort of confusing with the order and uses of them. Any sort of direction or explanation on which ones to use would be greatly appreciated! I think I understand how it works (resultsBuffer[#] holds the value of each ADC so once ISR hits simply check them), just need help setting it up.
  • The ADC Window Comparator is inside the ADC, unrelated to the timer CCRs.
    ----------------------------------
    The MSP432Ware Driverlib can set the Comparator using ADC14_setComparatorWindowValue and ADC14_enableComparatorWindow. You set the IER1 bits using the high 32 bits of the argument to ADC14_enableInterrupt.

    You appear to be using the "TI Drivers" package (I think that's what it's called) which I know very little about. You may be on your own figuring out whether that can work with the Comparator stuff.

    I should also mention that I haven't done this with the MSP432. I have done it with the MSP430, which has a similar mechanism.
    ----------------------------------
    As TRM section 22.2.9 describes, you set the low threshold as a value in the ADC14LO0 register. (There's also an ADC14HI0 register, but I'm supposing you're interested in a low threshold for sonar/collision.)

    Set ADC14WINC in each of the ADC14MCTL0-6 registers. Leave ADC14WINCTH=0 to select LO0.

    You then enable the interrupt by setting ADC14IER1:ADC14LOIE [ref Table 22-14.] If you want "unattended" you probably want to turn off the bit(s) set in ADC14IER0 [ref Table 22-13]

    Set up the ISR as usual, and check for ADC14IFGR1:ADC14LOIFG [ref Table 22-16]. There's also an ADC14IV entry (=8) for it [ref Table 22-19.]

    To run "unattended" you'll probably want either continuous-scan (CONSEQ=3 and MSC=1 -- faster than you need but simple to do) or a timer-paced single-scan (CONSEQ=1, MSC=1, SHS > 0).

    [Edit: Forgot the MCTL stuff.]

  • /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>
    
    /* TI-RTOS Header files */
    #include <ti/drivers/GPIO.h>
    
    /* Statics */
    uint16_t resultsBuffer[7];
    uint8_t resPos;
    
    int main(void)
    {
    /* Halting WDT */
    MAP_WDT_A_holdTimer();
    MAP_Interrupt_enableSleepOnIsrExit();
    resPos = 0;
    
    /* Setting up clocks
    * MCLK = MCLK = 3MHz
    * ACLK = REFO = 32Khz */
    MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    
    /* Initializing ADC (MCLK/1/1) */
    MAP_ADC14_enableModule();
    MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1, 0);
    
    /* Configuring GPIOs (5.5 A0) */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 |
    GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 , GPIO_TERTIARY_MODULE_FUNCTION);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);
    // MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);
    /* Configuring ADC Memory (ADC_MEM0 - ADC_MEM7 (A6 - A12) with no repeat)
    with internal 2.5v reference */
    MAP_ADC14_configureMultiSequenceMode(ADC_MEM0,ADC_MEM6, true);
    MAP_ADC14_configureConversionMemory(ADC_MEM0,
    ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A6, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM1,
    ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A7, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM2,
    ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A8, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM3,
    ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A9, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM4,
    ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A10, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM5,
    ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A11, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM6,
    ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A12, false);
    
    /* Setting up the sample timer to automatically step through the sequence
    * convert.*/
    MAP_ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
    
    /* Triggering the start of the sample */
    MAP_ADC14_enableConversion();
    MAP_ADC14_toggleConversionTrigger();
    
    ADC14_setComparatorWindowValue(ADC_COMP_WINDOW0,700, 2000);
    
    ADC14_enableComparatorWindow(ADC_MEM0 | ADC_MEM1 | ADC_MEM2 | ADC_MEM3 | ADC_MEM4 | ADC_MEM5 | ADC_MEM6,
    ADC_COMP_WINDOW0);
    
    /* Enabling the interrupt when a conversion on channel 7 (end of sequence)
    * is complete and enabling conversions */
    MAP_ADC14_enableInterrupt(ADC_IN_INT);
    
    /* Enabling Interrupts */
    MAP_Interrupt_enableInterrupt(INT_ADC14);
    MAP_Interrupt_enableMaster();
    
    /* Going to sleep */
    while (1)
    {
    MAP_PCM_gotoLPM0();
    }
    }
    
    /* This interrupt is fired whenever a conversion is completed and placed in
    * ADC_MEM0 */
    void ADC14_IRQHandler(void)
    {
    uint64_t status;
    uint64_t currentvalue;
    
    status = MAP_ADC14_getEnabledInterruptStatus();
    MAP_ADC14_clearInterruptFlag(status);
    
    MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
    
    if(status & ADC_INT6)
    {
    MAP_ADC14_getMultiSequenceResult(resultsBuffer);
    resultsBuffer[0] = MAP_ADC14_getResult(ADC_MEM0);
    resultsBuffer[1] = MAP_ADC14_getResult(ADC_MEM1);
    resultsBuffer[2] = MAP_ADC14_getResult(ADC_MEM2);
    resultsBuffer[3] = MAP_ADC14_getResult(ADC_MEM3);
    resultsBuffer[4] = MAP_ADC14_getResult(ADC_MEM4);
    resultsBuffer[5] = MAP_ADC14_getResult(ADC_MEM5);
    resultsBuffer[6] = MAP_ADC14_getResult(ADC_MEM6);
    }
    
    currentvalue = MAP_ADC14_getResult(ADC_MEM0);
    
    if (currentvalue < 700){//LED 1 ON WHEN OBJECTS ARE CLOSE
    MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);//LED1
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
    }
    else{//LED 2 ON WHEN OBJECTS ARE FAR
    MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);//LED2
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    }
    }

    Okay the way you explained seems pretty straight forward, but I am not getting this to work. I do not think my Comparator is even triggering the ISR at all. I have the high and low values set as the readings directly from the sonar sensors. The original code i had posted showed that a close Sonar sensor reading is below 700 and a far reading is 2000+ so I would like to work off of those values as opposed to converting to a voltage or something like that. I am not sure if maybe my MAP_ADC14_configureConversionMemory are set up incorrectly for this or not. I have the code toggling an LED if the ISR is triggered and the LED never changes from on.

  • > MAP_ADC14_enableConversion();
    > MAP_ADC14_toggleConversionTrigger();
    TRM Figure 22-19 shows ADC14WINC in blue, which means it can't be changed when ENC=1 (aka ADC14_enableConversion). I suggest you move that call (and thus the ADC14_toggleConversionTrigger as well) to follow the rest of the setup.

    The actual threshold registers (LO0/HI0) aren't blue, so you can presumably change them (ADC14_setComparatorWindowValue) any time.
  • It is a bit hard to follow with a Register Level explanation since I've been doing all my CCS code using the API's. It does not seem like there is much code required, but I still can't seem to get the 

    ADC14_IRQHandler to run at all. I have it turning on and LED inside the code and the LED never turns on. I feel like I am not setting up the pins to read the sonar reading itself. All example codes I can find are using internal references of 1.5-2.5 [V], when all I want to do is use my exact Sonar reading for my comparator. I am not sure if you can help since you said you are not familiar with the TI Driver stuff.

    P.S. Merry Christmas 

    /* Setting up the sample timer to automatically step through the sequence
        * convert.*/
        MAP_ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
    
        ADC14_enableComparatorWindow(ADC_MEM0 | ADC_MEM1 | ADC_MEM2 | ADC_MEM3 | ADC_MEM4 | ADC_MEM5 | ADC_MEM6,
            ADC_COMP_WINDOW0);
    
        ADC14_setComparatorWindowValue(ADC_COMP_WINDOW0,700, 2000);
    
        /* Enabling the interrupt when a channel drops below or above threshold of comparator */
        MAP_ADC14_enableInterrupt(ADC_IN_INT);
    
        /* Enabling Interrupts */
        MAP_Interrupt_enableInterrupt(INT_ADC14);
        MAP_Interrupt_enableMaster();
    
        /* Triggering the start of the sample */
        MAP_ADC14_enableConversion();
        MAP_ADC14_toggleConversionTrigger();
    
        /* Going to sleep */
        while (1)
        {
            MAP_PCM_gotoLPM0();
        }
    }
    
    /* This interrupt is fired whenever a conversion is completed and placed in
     * ADC_MEM0 */
    void ADC14_IRQHandler(void)
    {
        uint64_t status;
    //    uint64_t currentvalue;
    
        status = MAP_ADC14_getEnabledInterruptStatus();
        MAP_ADC14_clearInterruptFlag(status);
    
        MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);//LED1
    
        if(status & ADC_INT6)
        {
        MAP_ADC14_getMultiSequenceResult(resultsBuffer);
        resultsBuffer[0] = MAP_ADC14_getResult(ADC_MEM0);
        resultsBuffer[1] = MAP_ADC14_getResult(ADC_MEM1);
        resultsBuffer[2] = MAP_ADC14_getResult(ADC_MEM2);
        resultsBuffer[3] = MAP_ADC14_getResult(ADC_MEM3);
        resultsBuffer[4] = MAP_ADC14_getResult(ADC_MEM4);
        resultsBuffer[5] = MAP_ADC14_getResult(ADC_MEM5);
        resultsBuffer[6] = MAP_ADC14_getResult(ADC_MEM6);
        }
    
    }

  • I was able to trigger the ISR on my Launchpad with ADC_IN_INT as the status. I don't have a simple way to generate a signal, so I just run my fingers over the pins until something happens.
    ----------------------------
    I set a breakpoint at the entry to the ISR. If you're using the LED to signal you, keep in mind that the P1->OUT register is undefined at reset, so you should set P1.0 low when you set the direction (I think that's MAP_GPIO_setOutputLowOnPin). In my case it came on immediately in main, so it wasn't much of an indicator.
    ----------------------------
    > if(status & ADC_INT6)
    This is checking for MEM6 completion status. You probably wanted:
    > if(status & ADC_IN_INT)
    ----------------------------
    You're using the IN interrupt (ADC_IN_INT), which checks to see if the reading is "in" range, not high or low. If that matches with your test case that's fine. I understood you were interested in ADC_LO_INT or ADC_HI_INT.
    ----------------------------
    > MAP_ADC14_getMultiSequenceResult(resultsBuffer);
    This function is in the ROM so I expect it's (still) broken. The lines that follow it replace that call, so just remove that line.
    ----------------------------
    > MAP_ADC14_configureConversionMemory(ADC_MEM2,ADC_VREFPOS_INTBUF_VREFNEG_VSS,ADC_INPUT_A8, false);
    If you don't want the 2.5V Vref, I'm guessing you want to use VCC (3.3V) as your reference:
    > MAP_ADC14_configureConversionMemory(ADC_MEM2,ADC_VREFPOS_AVCC_VREFNEG_VSS,ADC_INPUT_A8, false);
    ----------------------------
    I think you're pretty much there, you just need to get the input levels just right.
  • Thank you! Finally go it working! I matched all the inputs together correctly like you said and I was missing the MAP_ADC14_enableModule();

    function, which made it work. I greatly appreciate your patience and quick responses! Very knowledgable even though you were unfamiliar with the

    TI Drivers example. I am going to post my code for anyone else who would like to accomplish this. I used example from CCS:

    Resource Explorer > MSP432P401R LaunchPad - Red 2.x (Red) > SimpleLink MSP432P4 SDK - v:2.30.00.14 > Examples > Development Tools >

    MSP432P401R LaunchPad - Red 2.x (Red) > DriverLib > adc14_single_conversion_repeat_timera_source.c

    and copy paste this code it should work just fine and the pins can be altered for an individuals application.

    *********************************START PROGRAM**********************************
    /*  	DLUG = MSP432_DriverLib_Users_Guide-MSP432P4xx-2_20_00_08    	*/
    
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>
    /* TI-RTOS Header files */
    #include <ti/drivers/GPIO.h>
    /* Statics */
    uint16_t resultsBuffer[7];//Buffer to hold ADC readings of each Sonar Sensor
    /* DLUG section: 2.6.2.25 | Registers an interrupt handler for the ADC interrupt.  */
    void ADC14_registerInterrupt(void (*ADC14_IRQHandler)(void));
    int main(void)
    {
        /* Halting WDT  */
        MAP_WDT_A_holdTimer();
        MAP_Interrupt_enableSleepOnIsrExit();
        /* DLUG section: 2.6.2.14 | This will enable operation of the ADC block. */
        MAP_ADC14_enableModule();
    //	MAP_ADC14_initModule(ADC_CLOCKSOURCE_ADCOSC, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
    //	0);
        /* Configuring GPIOs for Tertiary Function and inputs on Port 4 Pins 1-7 inclusive */
        MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 |
                          GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 , GPIO_TERTIARY_MODULE_FUNCTION);
        /* Setting LED1 and LED2 on board as outputs and initializing them as low */
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);//LED1(left and red)
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);//LED2(right and green)
    //	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);
        /* DLUG section: 2.6.2.3 | Configuring ADC Memory (ADC_MEM0 - ADC_MEM6 (A6 - A12)  with no repeat)
         * with internal 3.3[V] reference */
        MAP_ADC14_configureMultiSequenceMode(ADC_MEM0,ADC_MEM6, true);
        /* DLUG section: 2.6.2.2 | Configures individual memory locations for each ADC module.
         *  (memory locations, type of voltage reference, which channel is being used for
         *  ADC sampling, false for non-differential inputs) */
        //ADC_VREFPOS_INTBUF_VREFNEG_VSS (does 2.5[V] reference voltage)
        MAP_ADC14_configureConversionMemory(ADC_MEM0,
            ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A6, false);//ADC6 = P4.7 = MEM0
        MAP_ADC14_configureConversionMemory(ADC_MEM1,
            ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A7, false);//ADC7 = P4.6 = MEM1
        MAP_ADC14_configureConversionMemory(ADC_MEM2,
            ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A8, false);//ADC8 = P4.5 = MEM2
        MAP_ADC14_configureConversionMemory(ADC_MEM3,
            ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A9, false);//ADC9 = P4.4 = MEM3
        MAP_ADC14_configureConversionMemory(ADC_MEM4,
            ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A10, false);//ADC10 = P4.3 = MEM4
        MAP_ADC14_configureConversionMemory(ADC_MEM5,
            ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A11, false);//ADC11 = P4.2 = MEM5
        MAP_ADC14_configureConversionMemory(ADC_MEM6,
            ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A12, false);//ADC12 = P4.1 = MEM6
        /* DLUG section: 2.6.2.16 | Setting up the sample timer to automatically step through the sequence convert
         * After one sample/convert is finished, the ADC module will automatically continue on to the next sample.*/
        MAP_ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
        /*DLUG section: 2.6.2.11 | Enables the specified mask of memory channels to use the specified comparator window. The
        ADCC module has two different comparator windows that can be set with this function.*/
        ADC14_enableComparatorWindow(ADC_MEM0 | ADC_MEM1 | ADC_MEM2 | ADC_MEM3 | ADC_MEM4 | ADC_MEM5 | ADC_MEM6,
            ADC_COMP_WINDOW0);
    //	ADC14_enableComparatorWindow(ADC_MEM0 | ADC_MEM1 | ADC_MEM2 | ADC_MEM3 | ADC_MEM4 | ADC_MEM5 | ADC_MEM6,
    //        	ADC_COMP_WINDOW1);
        /* DLUG section: 2.6.2.26 | Sets the lower and upper limits of the specified window comparator.
         * (window 0 or 1, lower limit, upper limit) */
        ADC14_setComparatorWindowValue(ADC_COMP_WINDOW0,550, 2000);
    //	ADC14_setComparatorWindowValue(ADC_COMP_WINDOW1,550, 2000);
        /* DLUG section: 2.6.2.13 | Enabling the interrupt when a channel drops below threshold of comparator,
         * if use ADC_HI_INT enables interrupt when channel goes above threshold of comparator or
         * ADC_IN_INT enables interrupt channel when channel is whithin threshold */
        MAP_ADC14_enableInterrupt(ADC_LO_INT);
    //	MAP_ADC14_enableInterrupt(ADC_HI_INT);
    //	MAP_ADC14_enableInterrupt(ADC_IN_INT);
        /* DLUG section: 12.4.2.4 - 12.4.2.5 | Enabling Interrupts */
        MAP_Interrupt_enableInterrupt(INT_ADC14);
        MAP_Interrupt_enableMaster();
        /* DLUG section: 2.6.2.12 & 2.6.2.32 | Enables conversion of ADC data. Triggering the start of the sample.
         * Toggles the trigger for conversion of the ADC module by toggling the trigger software bit.*/
        MAP_ADC14_enableConversion();
        MAP_ADC14_toggleConversionTrigger();
        /* Going to sleep */
        while (1)
        {
            MAP_PCM_gotoLPM0();
        }
    }
    /* This interrupt is fired whenever a Sonar Reading is whatever the comparator says and the MAP_ADC14_enableInterrupt(X) says. */
    void ADC14_IRQHandler(void)
    {
        uint64_t status;
        status = MAP_ADC14_getEnabledInterruptStatus();//gets interrupt status for comparison
        MAP_ADC14_clearInterruptFlag(status);//clears interrupt flag for next interrupt check
        if(status & ADC_LO_INT)//
        {
    //	MAP_ADC14_getMultiSequenceResult(resultsBuffer);
        resultsBuffer[0] = MAP_ADC14_getResult(ADC_MEM0);//P4.7
        resultsBuffer[1] = MAP_ADC14_getResult(ADC_MEM1);//P4.6
        resultsBuffer[2] = MAP_ADC14_getResult(ADC_MEM2);//P4.5
        resultsBuffer[3] = MAP_ADC14_getResult(ADC_MEM3);//P4.4
        resultsBuffer[4] = MAP_ADC14_getResult(ADC_MEM4);//P4.3
        resultsBuffer[5] = MAP_ADC14_getResult(ADC_MEM5);//P4.2
        resultsBuffer[6] = MAP_ADC14_getResult(ADC_MEM6);//P4.1
        }
    //	MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
        if (resultsBuffer[0] < 550 ){//LED 1 ON WHEN OBJECTS ARE CLOSE (RED)
           MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);//LED1 (left)
           MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
        }
        else{//LED 2 ON WHEN OBJECTS ARE FAR (GREEN)
           MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);//LED2 (right)
           MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
        }
    }
    

**Attention** This is a public forum