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.

MSP432 - TI RTOS and ADC HWI



Hi,

I'm trying to configure a BIOS managed ADC interrupt, it seems to work but my adcResult is always returning 0 independently of the voltage on the pin.

Hwi Configuration:

var hwi0Params = new Hwi.Params();
hwi0Params.instance.name = "adcHwi";
Program.global.adcHwi = Hwi.create(40, "&Hwi_adc", hwi0Params);

ADC initialization:

Void Hwi_initADC() {

    /* Initializing ADC (MCLK/64/8) */
    MAP_ADC14_enableModule();
    MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_64,
        ADC_DIVIDER_8, ADC_NOROUTE);

    MAP_ADC14_setResolution(ADC_14BIT);

    /* Setting reference voltage to 2.5 */
    MAP_REF_A_setReferenceVoltage(REF_A_VREF2_5V);
    MAP_REF_A_enableReferenceVoltage();

    /* Configuring GPIO (5.4 A1) */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN4,
        GPIO_TERTIARY_MODULE_FUNCTION);

    /* Configuring ADC Memory */
    MAP_ADC14_configureSingleSampleMode(ADC_MEM1, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM1, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A1, false);

    /* Configuring Sample Timer */
    MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);

    /* Enabling interrupts */
    MAP_ADC14_enableInterrupt(ADC_INT1);
    MAP_Interrupt_enableInterrupt(INT_ADC14);
    MAP_Interrupt_enableMaster();

    /* Enables conversion of ADC data */
    MAP_ADC14_enableConversion();

    /* Start conversion */
    MAP_ADC14_toggleConversionTrigger();
}

ADC isr:

Void Hwi_adc() {
    uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
    MAP_ADC14_clearInterruptFlag(status);

    if (ADC_INT1 & status) {
        uint16_t raw = MAP_ADC14_getResult(ADC_MEM1);
        Mailbox_post(adcMail, &raw, BIOS_NO_WAIT);

        MAP_ADC14_toggleConversionTrigger();
    }
}

Task to print values:

Void Task_logger(UArg arg0, UArg arg1) {
	uint16_t value;

	while (1) {
		Mailbox_pend(adcMail, &value, BIOS_WAIT_FOREVER);
		System_printf("val: %d\n", value);
		System_flush();
	}
}

The program prints "val: 0" every time.

  • Hi Rodolfo,

    I have moved your thread to the TI-RTOS forum and someone will be able to help you solve this ADC HWI implementation.

    Sincerely,
    Sean
  • Hi Rodolfo,

    Does your code work without TI-RTOS, ie. if you handle interrupts like they do in the adc14 driverlib examples in 'C:\CCS\msp430\MSPWare_2_30_00_49\driverlib\examples\MSP432P4xx\adc14'?

    Just wondering if you are setting up the ADC correctly, interrupt handling aside.

    Best regards,
    Vincent
  • Hi Vicent,

    I uploaded the adc14_single_channel_temperature_sensor and added some "debugging" lines in other to know if ADC14_getResult is returning 0.

    #include "driverlib.h"
    
    /* Standard Includes */
    #include <stdint.h>
    
    #include <string.h>
    
    volatile float tempC;
    volatile float tempF;
    
    int main(void)
    {
        /* Halting WDT  */
        WDT_A_holdTimer();
        Interrupt_enableSleepOnIsrExit();
    
        /* Enabling the FPU with stacking enabled (for use within ISR) */
        FPU_enableModule();
        FPU_enableLazyStacking();
    
        /* Initializing ADC (MCLK/1/1) with temperature sensor routed */
        ADC14_enableModule();
        ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
                ADC_TEMPSENSEMAP);
    
        /* Configuring ADC Memory (ADC_MEM0 A22 (Temperature Sensor) in repeat
         * mode).
         */
        ADC14_configureSingleSampleMode(ADC_MEM0, true);
        ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
                ADC_INPUT_A22, false);
    
        /* Configuring the sample/hold time for TBD */
        ADC14_setSampleHoldTime(ADC_PULSE_WIDTH_192,ADC_PULSE_WIDTH_192);
    
        /* Enabling sample timer in auto iteration mode and interrupts*/
        ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
        ADC14_enableInterrupt(ADC_INT0);
    
        /* Setting reference voltage to 2.5 and enabling temperature sensor */
        REF_A_setReferenceVoltage(REF_A_VREF2_5V);
        REF_A_enableReferenceVoltage();
        REF_A_enableTempSensor();
    
        /* Enabling Interrupts */
        Interrupt_enableInterrupt(INT_ADC14);
        Interrupt_enableMaster();
    
        /* Triggering the start of the sample */
        ADC14_enableConversion();
        ADC14_toggleConversionTrigger();
    
        GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    
    /* Going to sleep */ while (1) { PCM_gotoLPM0(); } } /* This interrupt happens every time a conversion has completed. Since the FPU * is enabled in stacking mode, we are able to use the FPU safely to perform * efficient floating point arithmetic.*/ void adc_isr(void) { uint64_t status; uint32_t cal30, cal85; status = ADC14_getEnabledInterruptStatus(); ADC14_clearInterruptFlag(status); if(status & ADC_INT0) { cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF, SYSCTL_30_DEGREES_C); cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF, SYSCTL_85_DEGREES_C); uint16_t raw = ADC14_getResult(ADC_MEM0); if (raw == 0) { GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); } else { GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); } tempC = (float) (((uint32_t) raw - cal30) * (85 - 30)) / (cal85 - cal30) + 30.0f; tempF = tempC * 9.0f / 5.0f + 32.0f; } }

    After running the code the onboard led at P1.0 was ON, making me believe that the ADC14_getResult is returning 0.

  • Hi Rodolfo,


    It looks like this is not an issue specific to TI-RTOS. For help with ADC and the ADC14 driverlib API, you may want to post to the MSP device forum instead. After you have figured out the issue, you can come back to the TI-RTOS forum if you need more help with integrating TI-RTOS with your code.


    Best regards,

    Vincent