r_sdadc configuration

How to configure more than 1 differential input channels for r_sdadc?

with the bellow configuration, I can only read channel 0 but not channel 1 

I could read channel 1 if I deleted channel 0.

Regards.

  • Hi Cooper-
    Can you share your configuration settings and pin settings for the SDADC configuration- are you just using the defaults?

    When you say you can't read channel 1, do you get an error status returned when you try, or no error, but a value you don't expect?


    Thanx!

  • Hi Warren,

    There isn't any error, the call back show conversion completed. I tried to read channel 1 and it always 0 with the configuration as shown. Only channel 0 return value. However, if I delete channel0 in the configuration then I'll be able to read channel 1. I tried to create 2 different stack to use one for each channel, but this method is not allowed in the configuration.  below is the code snippet 

     

    r_sdadc.p_api->open(r_sdadc.p_ctrl, r_sdadc.p_cfg);
    r_sdadc.p_api->scanCfg(r_sdadc.p_ctrl, r_sdadc.p_channel_cfg);

    r_sdadc.p_api->offsetSet(r_sdadc.p_ctrl, ADC_REG_CHANNEL_0, ADC_GAIN_OFFSET);
    r_sdadc.p_api->offsetSet(r_sdadc.p_ctrl, ADC_REG_CHANNEL_1, ADC_GAIN_OFFSET);

    r_sdadc.p_api->scanStart(r_sdadc.p_ctrl);

    while (conversion_complete == false); 
    conversion_complete = false; 


    r_sdadc.p_api->read32(r_sdadc.p_ctrl, ADC_REG_CHANNEL_0, &adc0Buffer[0]);
    r_sdadc.p_api->read32(r_sdadc.p_ctrl, ADC_REG_CHANNEL_1, &adc1Buffer[0]);

    r_sdadc.p_api->scanStop(r_sdadc.p_ctrl);

    Same for channel 1

     

  • Hi Cooper-
    Thanx for providing the above.

    How about the Callback- are you checking for the callback event? Which one(s) are you checking for?
  • Hi Cooper,

    As Warren as suggested, you need to check which ADC has completed its conversion and read the appropriate channel.  The callback can be used for this.

    Can you try something like this:

    /* HAL-only entry function */
    #include "hal_data.h"


    volatile bool calibration_complete = false;
    volatile bool conversion0_complete = false;
    volatile bool conversion1_complete = false;

    uint32_t adc0Buffer[1];
    uint32_t adc1Buffer[1];



    void hal_entry(void)
    {
        /* TODO: add your own code here */
        ssp_err_t err;
        uint32_t timeout_value = UINT32_MAX;

        err = g_adc0.p_api->open(g_adc0.p_ctrl, g_adc0.p_cfg);
        if( err != SSP_SUCCESS )
        {
            __BKPT(1);
        }


        err = g_adc0.p_api->scanCfg(g_adc0.p_ctrl, g_adc0.p_channel_cfg);
        if( err != SSP_SUCCESS )
        {
            __BKPT(1);
        }

        sdadc_calibrate_args_t calibrate_args;

        calibrate_args.mode = SDADC_CALIBRATION_INTERNAL_GAIN_OFFSET;
        calibrate_args.channel = ADC_REG_CHANNEL_0;
        err = g_adc0.p_api->calibrate(g_adc0.p_ctrl, &calibrate_args);
        if( err != SSP_SUCCESS )
        {
            __BKPT(1);
        }


        do{
            err = g_adc0.p_api->scanStatusGet (g_adc0.p_ctrl);
            timeout_value--;
        }while (SSP_SUCCESS != err && timeout_value != 0);


        if( true == calibration_complete )
        {
            err = g_adc0.p_api->scanStart(g_adc0.p_ctrl);
            if( err != SSP_SUCCESS )
            {
                __BKPT(1);
            }

            while(1)
            {
                while ((false == conversion0_complete) && (false == conversion1_complete));


                if( conversion0_complete == true )
                {
                    err = g_adc0.p_api->read32(g_adc0.p_ctrl, ADC_REG_CHANNEL_0, &adc0Buffer[0]);
                    if( err != SSP_SUCCESS )
                    {
                        __BKPT(1);
                    }
                    conversion0_complete = false;
                }


                if( conversion1_complete == true )
                {
                    err = g_adc0.p_api->read32(g_adc0.p_ctrl, ADC_REG_CHANNEL_1, &adc1Buffer[0]);
                    if( err != SSP_SUCCESS )
                    {
                        __BKPT(1);
                    }
                    conversion1_complete = false;
                }
            }
        }
        else
        {
            __BKPT(1); // Calibration error
        }
    }


    void cb_adc0(adc_callback_args_t *p_args)
    {
        /*Check if calibration is complete and set flag */
        if (ADC_EVENT_CALIBRATION_COMPLETE == p_args->event)
        {
            calibration_complete = true;
        }

        if( ADC_EVENT_CONVERSION_COMPLETE == p_args->event)
        {
           if(p_args->channel == ADC_REG_CHANNEL_0)
           {
               conversion0_complete = true;
           }
           else if(p_args->channel == ADC_REG_CHANNEL_1)
           {
               conversion1_complete = true;
           }
           else
           {

           }
        }
    }

  • Thank you Warren and Richard.
    I got it works. I add the while loop to wait for the conversion complete after every channel reading.
  • Hi Richard,

    Using your sample, I see only channel 1 updating even though p_args->channel == ADC_REG_CHANNEL_0 in the callback is called. Do you have any suggestion?

    Also, I see that you only calibrate channel 0. my question is doing so will also calibrate the rest of configured channels or individual channel has to be calibrated?

    Thanks.