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.

configuring 2 more channels to ADC as input within a SCS generated code

Other Parts Discussed in Thread: SYSBIOS

Hi,
I have generated a code for reading voltage value using ADC at Pin DIO_23 with the help of SCS. that code giving me correct result. Now i want to configure 2 more channnels to the ADC as input . How can i add that in the existing SCS generated code? which portion i have to change?.
Thank You
Abhijith S

  • Hello Abhijith S,
    Currently you will have to include all the desired inputs within your SCS code and do decisions within the sensor controller code. So in this case you will have to rewrite your sensor controller code and compile a new project with SCS.
  •  Initialization code:

    --------------------------------------------

    // Select ADC input

    adcSelectGpioInput(AUXIO_A_BAT);

    adcSelectGpioInput(AUXIO_A_VB);

    adcSelectGpioInput(AUXIO_A_VO);

    // Schedule the first execution

    fwScheduleTask(1);

    Execution code:

    ------------------------------------------------------

    // Enable the ADC

    adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL);

    // Sample the light sensor

    S16 adcValue;

    adcGenManualTrigger();

    adcReadFifo(adcValue);

    state.adcValue = adcValue;

    // Disable the ADC

    adcDisable();

    // Schedule the next execution

    fwScheduleTask(1);


    ---------------------------------------------------------------------------------------------------------------------

    is this correct?

  • Hello,
    No.
    You need to create a loop to iterate through all the different inputs. In your current code only AUXIO_A_VO will be measured. You also need to access the different inputs by the look up table defined in cfg.pAuxioASensorOutput:
    U16 n = 0;
    adcSelectGpioInput(cfg.pAuxioASensorOutput[n]);
    // Do ADC measurement
    n = 1;
    adcSelectGpioInput(cfg.pAuxioASensorOutput[n]);
    // Do ADC measurement
    n = 2;
    adcSelectGpioInput(cfg.pAuxioASensorOutput[n]);
    // Do ADC measurement
    ...
  • Is this modifictaion to be done within initiaisation part? and where can i find "cfg.pAuxioASensorOutput"

  • hi,
    i have modified extectuion code like this, but it stops after single execution




    U16 adcValue1;
    for(U16 n=0;n<BIN_COUNT;n++){

    // Enable the ADC
    adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL);
    adcSelectGpioInput(cfg.pAuxioAAlsOutput[n]);
    adcGenManualTrigger();
    adcReadFifo(adcValue1);
    state.adcValue = adcValue1;
    if(n==2){
    n=0;
    }
    // Disable the ADC
    adcDisable();
    fwScheduleTask(1);
    }

  • if i change the code like this, it shows an error if i put index value anything other than "n". if i put n as index value in select input it works fine

    // Enable the ADC

    U16 n=0;
    U16 m=1;
    U16 o=2;
    S16 adcValue1;

    adcSelectGpioInput(cfg.pAuxioAAlsOutput[n]);
    adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL);
    adcGenManualTrigger();
    adcReadFifo(adcValue1);
    state.adcValue = adcValue1;



    // Disable the ADC
    adcDisable();
    fwScheduleTask(1);
  • You always have to use the variable n for indexing. This is explained in the Task Code Language Reference:

    The variable n is special:

    It is always stored in the R0 register

    It is used for data structure array indexing. No other variables can be used for this purpose.

    It is used as counter variable in for-loops. No other variables can be used for this purpose.

  • but if i try to use for loop as given in my comment it stop after single exectuion
  • Have you checked the value of BIN_COUNT?

    Try the following:

    // Enable the ADC
    adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL);
    
    U16 adcValue1;
    for(U16 n=0;n<BIN_COUNT;n++){
    adcSelectGpioInput(cfg.pAuxioAAlsOutput[n]);
    adcGenManualTrigger();
    adcReadFifo(adcValue1);
    state.adcValue = adcValue1;
    }
    
    // Disable the ADC
    adcDisable();
    fwScheduleTask(1);

  •  I have modified code like this Now there are 2 problems.
    1. when i go for driver code generation, the generated files does not include a main file
    2. state.adc value is an array (not as in figure, i have modified). now the pin to which input is connected shows the correct reading, but other pins shows some random values as given below.(here 1893 is expected, bu  other values expected to be zero). how can i make that to 0

  • and now i try to write my own main.c. but it shows incorrect results
    //*****************************************************************************
    // SENSOR CONTROLLER STUDIO EXAMPLE: ADC DATA LOGGER
    // Operating system: TI-RTOS
    //
    // The Sensor Controller is used to sample and buffer a single ADC channel.
    // The ADC samples are stored in a ring-buffer, and the Sensor Controller
    // maintains a head index indicating where the next sample will be written.
    // The sampling interval is specified in the call to scifStartRtcTicksNow().
    // The application wakes up at a fixed asynchronous interval, and transfers
    // the ADC samples over UART (57600 baud, 8-N-1).
    //
    // Use a terminal window to connect to the SmartRF06EB's USB Serial Port.
    //
    // The DISABLE_LOW_POWER definition can be set to 1 to allow debugging.
    //
    //
    // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
    //
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions
    // are met:
    //
    // Redistributions of source code must retain the above copyright
    // notice, this list of conditions and the following disclaimer.
    //
    // Redistributions in binary form must reproduce the above copyright
    // notice, this list of conditions and the following disclaimer in the
    // documentation and/or other materials provided with the distribution.
    //
    // Neither the name of Texas Instruments Incorporated nor the names of
    // its contributors may be used to endorse or promote products derived
    // from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    //****************************************************************************/
    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    #include <ti/sysbios/family/arm/cc26xx/Power.h>
    #include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/uart/UARTCC26XX.h>

    //#include <driverlib/aon_batmon.h>
    #include <driverlib/aux_adc.h>
    #include <driverlib/aux_wuc.h>
    #include <inc/hw_aux_evctl.h>
    #include <Board.h>
    #include "scif.h"
    #include "string.h"
    #include "stdio.h"
    #include "math.h"
    #include <inc/hw_fcfg1.h>

    #define BV(n) (1 << (n))

    #define AON_BATMON_TEMP_INT_FIELD_WIDTH 9

    #define DISABLE_LOW_POWER 0


    // Display error message if the SCIF driver has been generated with incorrect operating system setting
    #ifndef SCIF_OSAL_TIRTOS_H
    #error "Generated SCIF driver supports incorrect operating system. Please change to 'TI-RTOS' in the Sensor Controller Studio project panel and re-generate the driver."
    #endif

    // Task data
    Task_Struct myTask;
    Char myTaskStack[1024];

    void scTaskAlertCallback(void) {

    } // taskAlertCallback


    void scCtrlReadyCallback(void) {

    } // ctrlReadyCallback

    void taskFxn(UArg a0, UArg a1) {


    int32_t adcOffset = AUXADCGetAdjustmentOffset(AUXADC_REF_FIXED);
    int32_t adcGainError = AUXADCGetAdjustmentGain(AUXADC_REF_FIXED);
    int32_t adcCorrectedValue1;
    int32_t adcCorrectedValue2;
    int32_t adcCorrectedValue3;

    int32_t adcMicroVoltValue1;
    int32_t adcMicroVoltValue2;
    int32_t adcMicroVoltValue3;

    int32_t outValue1 = 0;
    int32_t outValue2 = 0;
    int32_t outValue3 = 0;

    int8_t adcVoltValue1;
    int8_t adcVoltValue2;
    int8_t adcVoltValue3;
    int8_t adcRoundValue;

    int8_t i=0;
    int32_t TemperatureSensor;

    // Initialize the Sensor Controller
    scifOsalInit();
    scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback);
    scifOsalRegisterTaskAlertCallback(scTaskAlertCallback);
    scifInit(&scifDriverSetup);
    scifStartRtcTicksNow(0x00010000 / 128);


    // Configure and start the ADC Data Logger task. The task does not signalize data exchange, but
    // has buffering capacity for 256 samples = 2 seconds
    scifStartTasksNbl(BV(SCIF_ADCEXAMPLE_TASK_ID));

    // Main loop
    while (1) {


    // Wake up every 1 seconds
    Task_sleep(1000000 / Clock_tickPeriod);


    adcCorrectedValue1 = AUXADCAdjustValueForGainAndOffset((int32_t) scifTaskData.adcexample.output.adcValue[0], adcGainError, adcOffset);
    adcCorrectedValue2 = AUXADCAdjustValueForGainAndOffset((int32_t) scifTaskData.adcexample.output.adcValue[1], adcGainError, adcOffset);
    adcCorrectedValue3 = AUXADCAdjustValueForGainAndOffset((int32_t) scifTaskData.adcexample.output.adcValue[2], adcGainError, adcOffset);


    // printf("%d\n", scifTaskData.adcDataLogger.output.pSamples[tail]);
    adcMicroVoltValue1 = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, adcCorrectedValue1 );
    adcMicroVoltValue2 = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, adcCorrectedValue2 );
    adcMicroVoltValue3 = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, adcCorrectedValue3 );

    outValue1 = outValue1 + adcMicroVoltValue1;
    outValue2 = outValue2 + adcMicroVoltValue2;
    outValue3 = outValue3 + adcMicroVoltValue3;

    i++;
    if(i==10)
    {
    i=0;
    outValue1 = (outValue1/10);
    outValue2 = (outValue2/10);
    outValue3= (outValue3/10);

    printf("%d\n", outValue1);
    printf("%d\n", outValue2);
    printf("%d\n", outValue3);
    printf("\n\n");

    outValue1 = 0;
    outValue2 = 0;
    outValue3 = 0;

    }
    // adcVoltValue = (adcMicroVoltValue/1000000);
    // adcRoundValue = ceil(adcVoltValue);
    // printf("%d\n", outValue);

    }

    } // taskFxn




    int main(void) {
    Task_Params taskParams;

    // Optional: Prevent the system from entering standby to allow debugging
    #if DISABLE_LOW_POWER
    Power_setConstraint(Power_SB_DISALLOW);
    Power_setConstraint(Power_IDLE_PD_DISALLOW);
    #endif

    // Initialize the PIN driver
    PIN_init(BoardGpioInitTable);

    // Configure the OS task
    Task_Params_init(&taskParams);
    taskParams.stack = myTaskStack;
    taskParams.stackSize = sizeof(myTaskStack);
    taskParams.priority = 3;
    Task_construct(&myTask, taskFxn, &taskParams, NULL);

    // Start TI-RTOS
    BIOS_start();
    return 0;

    } // main

  • Hello,
    1) The main file is never generated. You will have to create this yourselves. You can use the examples as reference.
    2) I don't understand. state.adcValue is a basic RAM variable array that does not have anything to do with IO mapping.
  • In main fiiles of given examples, no adcread, adcselectinput functions used in task. then how it works?
  • When i run this main, it got stuck at ADCReadfifo()
    //*****************************************************************************
    // SENSOR CONTROLLER STUDIO EXAMPLE: ADC DATA LOGGER
    // Operating system: TI-RTOS
    //
    // The Sensor Controller is used to sample and buffer a single ADC channel.
    // The ADC samples are stored in a ring-buffer, and the Sensor Controller
    // maintains a head index indicating where the next sample will be written.
    // The sampling interval is specified in the call to scifStartRtcTicksNow().
    // The application wakes up at a fixed asynchronous interval, and transfers
    // the ADC samples over UART (57600 baud, 8-N-1).
    //
    // Use a terminal window to connect to the SmartRF06EB's USB Serial Port.
    //
    // The DISABLE_LOW_POWER definition can be set to 1 to allow debugging.
    //
    //
    // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
    //
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions
    // are met:
    //
    // Redistributions of source code must retain the above copyright
    // notice, this list of conditions and the following disclaimer.
    //
    // Redistributions in binary form must reproduce the above copyright
    // notice, this list of conditions and the following disclaimer in the
    // documentation and/or other materials provided with the distribution.
    //
    // Neither the name of Texas Instruments Incorporated nor the names of
    // its contributors may be used to endorse or promote products derived
    // from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    //****************************************************************************/
    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    #include <ti/sysbios/family/arm/cc26xx/Power.h>
    #include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/uart/UARTCC26XX.h>

    //#include <driverlib/aon_batmon.h>
    #include <driverlib/aux_adc.h>
    #include <driverlib/aux_wuc.h>
    #include <inc/hw_aux_evctl.h>
    #include <Board.h>
    #include "scif.h"
    #include "string.h"
    #include "stdio.h"
    #include "math.h"
    #include <inc/hw_fcfg1.h>

    #define BV(n) (1 << (n))

    #define AON_BATMON_TEMP_INT_FIELD_WIDTH 9

    #define DISABLE_LOW_POWER 0


    // Display error message if the SCIF driver has been generated with incorrect operating system setting
    #ifndef SCIF_OSAL_TIRTOS_H
    #error "Generated SCIF driver supports incorrect operating system. Please change to 'TI-RTOS' in the Sensor Controller Studio project panel and re-generate the driver."
    #endif

    // Task data
    Task_Struct myTask;
    Char myTaskStack[1024];

    void scTaskAlertCallback(void) {

    } // taskAlertCallback


    void scCtrlReadyCallback(void) {

    } // ctrlReadyCallback


    void taskFxn(UArg a0, UArg a1) {


    int32_t adcOffset = AUXADCGetAdjustmentOffset(AUXADC_REF_FIXED);
    int32_t adcGainError = AUXADCGetAdjustmentGain(AUXADC_REF_FIXED);

    int32_t Value1;
    int32_t Value2;
    int32_t Value3;

    int32_t adcCorrectedValue1;
    int32_t adcCorrectedValue2;
    int32_t adcCorrectedValue3;

    int32_t adcMicroVoltValue1;
    int32_t adcMicroVoltValue2;
    int32_t adcMicroVoltValue3;

    int32_t outValue1 = 0;
    int32_t outValue2 = 0;
    int32_t outValue3 = 0;

    int8_t adcVoltValue1;
    int8_t adcVoltValue2;
    int8_t adcVoltValue3;
    int8_t adcRoundValue;

    int8_t i=0;
    int32_t TemperatureSensor;

    // Initialize the Sensor Controller
    scifOsalInit();
    scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback);
    scifOsalRegisterTaskAlertCallback(scTaskAlertCallback);
    scifInit(&scifDriverSetup);
    scifStartRtcTicksNow(0x00010000 / 128);

    // Configure and start the ADC Data Logger task. The task does not signalize data exchange, but
    // has buffering capacity for 256 samples = 2 seconds
    scifStartTasksNbl(BV(SCIF_ADCEXAMPLE_TASK_ID));
    AUXADCEnableSync(AUXADC_REF_FIXED , AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);
    // Main loop
    while (1) {


    // Wake up every 1 seconds
    // Task_sleep(1000000 / Clock_tickPeriod);

    AUXADCSelectInput(scifTaskData.adcexample.cfg.pAuxioAVol[0]);
    Value1 = AUXADCReadFifo();


    adcCorrectedValue1 = AUXADCAdjustValueForGainAndOffset((int32_t) scifTaskData.adcexample.output.adcValue[0], adcGainError, adcOffset);
    adcCorrectedValue2 = AUXADCAdjustValueForGainAndOffset((int32_t) scifTaskData.adcexample.output.adcValue[1], adcGainError, adcOffset);
    adcCorrectedValue3 = AUXADCAdjustValueForGainAndOffset((int32_t) scifTaskData.adcexample.output.adcValue[2], adcGainError, adcOffset);


    // printf("%d\n", scifTaskData.adcDataLogger.output.pSamples[tail]);
    adcMicroVoltValue1 = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, adcCorrectedValue1 );
    adcMicroVoltValue2 = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, adcCorrectedValue2 );
    adcMicroVoltValue3 = AUXADCValueToMicrovolts(AUXADC_FIXED_REF_VOLTAGE_NORMAL, adcCorrectedValue3 );

    outValue1 = outValue1 + adcMicroVoltValue1;
    outValue2 = outValue2 + adcMicroVoltValue2;
    outValue3 = outValue3 + adcMicroVoltValue3;

    i++;
    // if(i==10)
    // {
    // i=0;
    // outValue1 = (outValue1/10);
    // outValue2 = (outValue2/10);
    // outValue3= (outValue3/10);
    //
    // printf("%d\n", outValue1);
    // printf("%d\n", outValue2);
    // printf("%d\n", outValue3);
    // printf("\n\n");
    //
    // outValue1 = 0;
    // outValue2 = 0;
    // outValue3 = 0;
    //
    // }
    // adcVoltValue = (adcMicroVoltValue/1000000);
    // adcRoundValue = ceil(adcVoltValue);
    printf("%d\n", adcMicroVoltValue1);
    printf("%d\n", adcCorrectedValue2);
    printf("%d\n", adcCorrectedValue3);
    printf("\n\n");

    }

    } // taskFxn




    int main(void) {
    Task_Params taskParams;

    // Optional: Prevent the system from entering standby to allow debugging
    #if DISABLE_LOW_POWER
    Power_setConstraint(Power_SB_DISALLOW);
    Power_setConstraint(Power_IDLE_PD_DISALLOW);
    #endif

    // Initialize the PIN driver
    PIN_init(BoardGpioInitTable);

    // Configure the OS task
    Task_Params_init(&taskParams);
    taskParams.stack = myTaskStack;
    taskParams.stackSize = sizeof(myTaskStack);
    taskParams.priority = 3;
    Task_construct(&myTask, taskFxn, &taskParams, NULL);

    // Start TI-RTOS
    BIOS_start();
    return 0;

    } // main