adc configuration

Hi all,

 

I am using board PK-S5D9

I am exploring its ADC inbuilt feature Unit 0 - analog channel 0 to channel 3 Using framework module(single-scan shot).I created a thread for adc and stack of 1024 bytes

 

configuration I have done in configuration file(.xml) is  

channel 0- Use in normal/group A

channel 1- Use in normal/group A

channel 2- Use in normal/group A

channel 3- Use in normal/group A

I have read about scanning modes in usermanual section 47 but ABOVE OPTIONs IN stack propertiescaught me a question  Does the normal and single shot mode same ?

I need to know what is it scanning rate ..is the duty cycle,period value option in r_adc conguration provides scanning rate ? 

I am trying implementing a multiple channel adc framework .

 

Am I missing any  required  configuration ?

 

 

Thanks

  • Good day, Kirti!

    How are things going so far? As per ADC Module Guide:
    The module supports three operation modes: single-scan, continuous-scan, and group-scan modes.
    • Single-scan mode sequentially converts the analog inputs of selected channels in the ascending order of the channel number once per trigger.
    • Continuous-scan mode sequentially converts the analog inputs of selected channels continuously in the ascending order of the channel numbers; a single trigger is required to start off the scan.
    • Group-scan mode allows the user to add channels to one of two groups (A and B) and converts the analog inputs of the selected channels for each group in the ascending order of the channel number,
    when the specified start trigger for that group is received.
    Furthermore, the ADC HAL module supports two interrupts:
    • The normal/group-A interrupt, which fires when a scan is completed in single-scan mode or when a group-A scan is completed in group mode.
    • The group-B interrupt, which fires when a group-B scan is completed in group mode.

    You can refer to the link for more detailed explanation. I hope that helps you even for a bit.

    Best regards,
    Sai
    RenesasRulz Forum Moderator
    https://renesasrulz.com/
    https://academy.renesas.com/
    en-us.knowledgebase.renesas.com/

  • In reply to Sai:

    Hi sai,

    Thanks for this

    I am aware of the theory of scanning modes in adc

    My query is

    I am sampling the channel 0 to 3 using framework module ..not ADC HAL module

    Board : S5D9-PK

    SSP :1.7.5

    ISDE :e2 Studio

    sampling unit 0 -channel 0-channel 3

    coould You share a stepswise procedure to read adc framework result

    so configuration I have done is attached in original post ..So I wanted to confirm the configuration..please help on this 

    I have tried example this

    example gives on board device temperature ..Using the example I am sampling the analog channel as per need  instead of temperature sensor channel 

    Help on this 

     

     

    Thanks

  • In reply to Kirti:

    Hello,

     

    Does this help?

     

    Regards,

    Richard

     

    ADC_Framework_step_example.pptx

     

     

  • In reply to Richard:

    Hi Richard,

    It helped me a bit.

    What is function of auto-initialization in g_sf_periodic_adc tab which is disable .

    Sampling iteration : 10

    scan time : 20ms

    Does it mean that scanning the each channel for 20ms for 10 times sequencially?

    In this code snippet where I can actually get the raw adc count for each channel ?

    while(1)

    {

      tx_event_flags_get (&g_adc_flags, ALL_FLAGS, TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER);

              if( EVENT_FLAG_1 == (actual_flags & EVENT_FLAG_1))

              {

                  g_ioport.p_api->pinWrite( IOPORT_PORT_06_PIN_00, toggle_p60 );

                  toggle_p60 = (ioport_level_t)(1 - toggle_p60);

              }

              else if (EVENT_FLAG_2 == (actual_flags & EVENT_FLAG_2))

              {

                  // g_user_buffer[120] to g_user_buffer[239] has valid data

                  // process ADC data accordingly

                  g_ioport.p_api->pinWrite( IOPORT_PORT_06_PIN_01, toggle_p61 );

                  toggle_p61 = (ioport_level_t)(1 - toggle_p61);

              }

              else

              {

              }

    }

    g_user_buffer will give me adc raw count ?

    is it like g_user_buffer[0] to g_user_buffer[20] = channel 0 adc raw count 

    g_user_buffer[21] to g_user_buffer[40] = channel 1 adc raw count 

    so on

    am understanding it correctly ?

     

  • In reply to Kirti:

    Hi,

    Trying to answer your questions in turn:

    >> What is function of auto-initialization in g_sf_periodic_adc tab which is disable .

    If you set the to Enable, the code that opens the adc framework is automatically generated and coded for you.

    This being the case, in your application code you would not need the api call:

    /* Initialise the ADC Framework*/

       err = (g_sf_adc_periodic0.p_api->open(g_sf_adc_periodic0.p_ctrl, g_sf_adc_periodic0.p_cfg));

       if(err != SSP_SUCCESS)

       {

           __BKPT(1);

       }

    This code will be in the Synergy generated code.

    Assuming that the thread to which you have added the ADC framework is called adc_example_thread, then there will be a file called adc_example.c in the folder synergy_gen.

    If you look in the file adc_example.c, there is a function called adc_example_func().  You can see here the api call.

    This function adc_example_func is called as part of the thread creation process.

    >> Sampling iteration : 10

    >> scan time : 20ms

    >> Does it mean that scanning the each channel for 20ms for 10 times sequencially?

    Please refer to the attached PowerPoint.

    It means that the 4 channels that you have selected are scanned once, every 20ms.  After 10 iterations, the callback function is called, notifying you that data is ready.  After the first 10 iterations, the buffer [0] to [39] are populated. The buffer index will be 0

    After the next 10 iterations, the buffer [40] to [79] are populated. The buffer index will be 40.

    As the buffer is now full, the next 10 iterations will populate buffer [0] to [39] 

    This process will continue until you stop the adc framework with the API g_sf_adc_periodic0.p_api->stop

     

    >> g_user_buffer will give me adc raw count ?

    Yes

     

     

    >> is it like g_user_buffer[0] to g_user_buffer[20] = channel 0 adc raw count 

    >> g_user_buffer[21] to g_user_buffer[40] = channel 1 adc raw count 

    No.

    The data is stored

    g_user_buffer[0] = AN000 result
    g_user_buffer[1] = AN001 result
    g_user_buffer[2] = AN002 result
    g_user_buffer[3] = AN003 result
    g_user_buffer[4] = AN000 result
    g_user_buffer[5] = AN001 result
    g_user_buffer[6] = AN002 result
    g_user_buffer[7] = AN003 result
    .
    .
    .
    g_user_buffer[72] = AN000 result
    g_user_buffer[73] = AN001 result
    g_user_buffer[74] = AN002 result
    g_user_buffer[75] = AN003 result
    g_user_buffer[76] = AN000 result
    g_user_buffer[77] = AN001 result
    g_user_buffer[78] = AN002 result
    g_user_buffer[79] = AN003 result

     

     

    ADC_Framework_step_example_V2.pptx

    Regards,

    Richard

  • In reply to Richard:

     

    Thanks Richard ..it cleared my query

     __BKPT(1);    // breakpoint (1) //what is the function of this statement ?

    sorry I m asking this software breakpoint related question but here my code execution stops

    I should get the some value in g_user_buffer if I am giving 0-10 v input voltage to physical analog pins AN0,AN1,AN2,AN3(As per my understanding )

    In watch expression g_user_buffer[0] to [79] = 0; adc.zip

    I am trying to debug the code ..I am not able to understand this error ..I trust you are the right person to help me on this

    Please see the attachament

     

    Thanks Richard

  • In reply to Kirti:

    Hello,

    A few things:  (Please see point 4 - very important )

    1. You are ending up in the error call back function as you have not enabled the interrupt in the ADC configuration.  When the ADC has done a scan of the enabled channels, it generates an interrupt.  This interrupt triggers the DTC, which saves the data to the results buffer.  By default, the interrupt in disbaled, so in the configuration set an interrupt priority. Here, I have set it to 8.

     

     

    2. You have set the "Auto Initialization" option to Enabled but you still have the open api call in your code.  Either set this to Disable or remove g_sf_adc_periodic0.p_api->open(g_sf_adc_periodic0.p_ctrl, g_sf_adc_periodic0.p_cfg); from your function void adc_thread_entry(void)

     

    3. You are trying to use the BSP LED functionality.  You have defined bsp_leds_t g_leds; ,but to use it as you are

    g_ioport.p_api->pinWrite(g_leds.p_leds[0], IOPORT_LEVEL_LOW);
    g_ioport.p_api->pinWrite(g_leds.p_leds[1], IOPORT_LEVEL_HIGH);

    you have to call the function R_BSP_LedsGet(&g_leds); first.

     

    /*===============================================================*/

    /*                                                PLEASE NOTE THIS                                                                 */

    /*===============================================================*/

    4. If you apply 0-10 V to the S5D9, you will destroy it.

    The S5D9 operates at 3.3V device.  Therefore, the voltages being applied to the ADC are 0 - 3.3V.  Applying a voltage beyond this, and certainly 10V, will destroy it.

     

     

    With the changes detailed above, and applying a correctly conditioned voltage to the AN pins, this modified adc_thread_entry.c code should work

    #include <stdio.h>
    #include "adc_thread.h"
    #include "sf_adc_periodic_api.h"

    void adc_example_entry(void);

    #define EVENT_FLAG_1    0x00000001  // b 0000-0000-0000-0000-0000-0000-0000-0001
    #define EVENT_FLAG_2    0x00000002  // b 0000-0000-0000-0000-0000-0000-0000-0010

    #define ALL_FLAGS       (EVENT_FLAG_1 | EVENT_FLAG_2)
    uint32_t actual_flags;
    bsp_leds_t g_leds;
    /* ADC framework example thread entry function */
    void adc_thread_entry(void)
    {
        ssp_err_t err = SSP_SUCCESS;

        err = R_BSP_LedsGet(&g_leds);
        if(SSP_SUCCESS != err)
        {
            // Add Error correction mechanism
            __BKPT(1);
        }

        /* Initialise the ADC Framework */
        /*
         * NOT REQUIRED AS  "Auto Initialization" option set to "Enabled"
         */
        //err = g_sf_adc_periodic0.p_api->open(g_sf_adc_periodic0.p_ctrl, g_sf_adc_periodic0.p_cfg);
        //if(err != SSP_SUCCESS)
        //{
        //    __BKPT(1);
        //}

        /* Start the ADC scan */
        err = g_sf_adc_periodic0.p_api->start(g_sf_adc_periodic0.p_ctrl);
        if(SSP_SUCCESS != err)
        {
            // Add Error correction mechanism
            __BKPT(1);
        }

        while (1)
        {
            tx_event_flags_get (&g_adc_flags, ALL_FLAGS, TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER);

            if( EVENT_FLAG_1 == (actual_flags & EVENT_FLAG_1))
            {
                // g_user_buffer[0] to g_user_buffer[39] has valid data
                // process ADC data accordingly
                g_ioport.p_api->pinWrite(g_leds.p_leds[0], IOPORT_LEVEL_LOW);
                g_ioport.p_api->pinWrite(g_leds.p_leds[1], IOPORT_LEVEL_HIGH);
            }
            else if (EVENT_FLAG_2 == (actual_flags & EVENT_FLAG_2))
            {
                // g_user_buffer[40] to g_user_buffer[79] has valid data
                // process ADC data accordingly
                g_ioport.p_api->pinWrite(g_leds.p_leds[0], IOPORT_LEVEL_HIGH);
                g_ioport.p_api->pinWrite(g_leds.p_leds[1], IOPORT_LEVEL_LOW);
            }
            else
            {
            }
        }
    }


    void g_adc_framework_user_callback(sf_adc_periodic_callback_args_t * p_args)
    {
        if(p_args->event == SF_ADC_PERIODIC_EVENT_NEW_DATA)
        {
            if(p_args->buffer_index == 0)
            {
                /* Set the event flag */
                tx_event_flags_set(&g_adc_flags, EVENT_FLAG_1, TX_OR);
            }
            else
            {
                /* Set the event flag */
                tx_event_flags_set(&g_adc_flags, EVENT_FLAG_2, TX_OR);
            }
        }
    }

  • In reply to Richard:

     

    Hi

    Thanks again Richard..

    with suggested changes

    I tried to debug ,am getting error as " GDB action failed to read memory 0xffffffff....."

    execution still stuck at __BKPT(1) in project file attached in previous thread

    I have disable auto initialization ...so initialized .open( api call) in user application code file 

     

    Can you share a document which gives details of  options available in properties of various tab(pins,thread,framework,object,stack) for project configuration .. 

     

     

  • In reply to Kirti:

    Please find attached the project that works on the S5D9_PK

     

    5758.adc.zip

    Please import this into e2studio and test

    For documentation please refer to the SSP users manual

     

    https://www.renesas.com/eu/en/products/synergy/software/ssp.html

     

    Also, please refer to the module guide examples on the web

    https://www.renesas.com/eu/en/products/synergy/gallery.html

    and look at the Application Projects

     

    Regards,

    Richard

  • In reply to Richard:

    I got the configuration which was missing ..

    This is seem to be revised manual

    Thanks for this

    Is there any command so that I can see variable or statement in console window instead of "expression" tab
    something like printf("")
  • In reply to Kirti:

    Hi Kirti-
    There are several Prof IoT blog posts that describe various ways to display debugging output. Here is the first one. Look at some of the following posts for additional topics and options.

    renesasrulz.com/.../debugging-synergy-applications-setting-up-and-using-printf