Timer triggers ADC Conversion

Hi,everyone,
I want to know how to use timer to trigger ADC conversion without DTC, only timer . And how should I do in Stack options in RA Smart Configurator. Thank you very much.

Parents Reply Children
  • ok , device is R7FA2L1AB3CFL.  RASC version is setup_fsp_v3_1_0_rasc_v2021-04. IDE is keil MDK 5.35, thank you

  • Add the ADC driver, GPT driver and ELC driver.

    volatile uint16_t g_adc_val = 0;

    /* Callback function */
    void g_adc_callback(adc_callback_args_t *p_args)
    {
    /* TODO: add your own code here */
    static volatile uint32_t j = 0;

    if (p_args->channel == 0)
    {
    j++;
    }
    }

    /*******************************************************************************************************************//**
    * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
    * is called by main() when no RTOS is used.
    **********************************************************************************************************************/
    void hal_entry(void)
    {
    /* TODO: add your own code here */
    fsp_err_t err;

    err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
    if (FSP_SUCCESS != err)
    {
    while(1);
    }

    err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
    if (FSP_SUCCESS != err)
    {
    while(1);
    }

    err = R_ADC_ScanStart(&g_adc0_ctrl);
    if (FSP_SUCCESS != err)
    {
    while(1);
    }

    err = R_ELC_Open(&g_elc_ctrl, &g_elc_cfg);
    if (FSP_SUCCESS != err)
    {
    __BKPT(0);
    }

    err = R_ELC_Enable(&g_elc_ctrl);
    if (FSP_SUCCESS != err)
    {
    __BKPT(0);
    }

    err = R_GPT_Open(&g_timer0_ctrl, &g_timer0_cfg);
    if (FSP_SUCCESS != err)
    {
    while(1);
    }

    err = R_GPT_Start(&g_timer0_ctrl);
    if (FSP_SUCCESS != err)
    {
    while(1);
    }

    while(1)
    {
    ;
    }

    #if BSP_TZ_SECURE_BUILD
    /* Enter non-secure code */
    R_BSP_NonSecureEnter();
    #endif
    }

  • hi lan, it must use ELC? Only ADC and Timer like STM32 can not work? 

  • Hi,

    Yes, the ELC must be used as it links the timer output to the ADC trigger input internally. Is there a problem with having the ELC driver used?

    Regards,

    Ian.

  • An improvement to the previous configuration. There's no need for the GPT interrupt to be enabled in the config as it will still generate events which the ELC can then send to the ADC. Please see the updated config below which will eliminate the ISR being triggered.

    Regards,

    Ian.

  • hi, lan,
    Mean i do not need to enable GPT interrupt, and ADC can select these events as follow , because ELC does the work and then send to ADC. 

    And i have a little question, should i need to use this function as follow to achieve this work?

    R_ELC_LinkSet(&g_elc_ctrl, ELC_PERIPHERAL_ADC0, ELC_EVENT_GPT4_COUNTER_OVERFLOW)

  • To answer your question

    "Mean i do not need to enable GPT interrupt, and ADC can select these events as follow , because ELC does the work and then send to ADC. "

    Correct.  All peripherals can generate hardware events, such as a timer overflow and timer compare match.  These events are always generated. 

    These events can be linked to other peripherals via the ELC.

    These events are also passed to the Interrupt controller and can be passed onto the NVIC to generate an interrupt.  This will happen if you enable the interrupt in the FSP configuration.  It is not required if you only want to use the GPT to trigger the ADC.

    No, you will not need to call

    R_ELC_LinkSet(&g_elc_ctrl, ELC_PERIPHERAL_ADC0, ELC_EVENT_GPT4_COUNTER_OVERFLOW)

    When you call the ELC open, all of the Links that are shown in the ELC tab of the configuration will be set. 

    However, during run-time you can change the ELC links if required.

    In which case you can call the R_ELC_LinkBreak(&g_elc_ctrl, ELC_PERIPHERAL_ADC0); and then call LinkSet, for example to trigger off the serial port data reception event!

    R_ELC_LinkSet(&g_elc_ctrl, ELC_PERIPHERAL_ADC0, ELC_EVENT_SCI3_RXI);

  • Yes,i understand this hesitation with your help and lan's help, thank you very much,Richard and lan.