SAMD10 EVENTs, ADC User never ready

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I'm working with the SAMD10D14A, trying to use the EVENT system to trigger an ADC conversion from TC1.  However, the ADC does not trigger and the Event channel always shows that the user is "not ready".  I've tried attaching another TC as the user instead of the ADC and that worked.  I'm using Atmel Studio 7 and ASF v3.47

 

Here's the code I use to set up the TC1 as the event trigger:

struct tc_module g_tc1_instance;

int adctcConfigureSampleTimer(void)
{
	// sets up TC1 with 125 us period (8000 Hz rate)

	struct tc_config config_tc;
	struct tc_events events_tc = {0};

	tc_get_config_defaults(&config_tc);
	config_tc.counter_size = TC_COUNTER_SIZE_8BIT;
	config_tc.clock_source = GCLK_GENERATOR_1;
	config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
	config_tc.counter_8_bit.period = 250;

	if (STATUS_OK != tc_init(&g_tc1_instance, TC1, &config_tc))
	{
		while (1){};
	}

	// EVENTS
	events_tc.generate_event_on_overflow = true;
	events_tc.invert_event_input = false;
	events_tc.on_event_perform_action = false;
	tc_enable_events(&g_tc1_instance, &events_tc);

	tc_enable(&g_tc1_instance);  //don't enable by default, so we don't start sampling on POR

	return 0;
} // adctcConfigureSampleTimer()

Here's the code to set up the ADC:

 

struct adc_module g_adc_instance;

int adctcConfigureADCmodule(void)
{
	// clocks must be configured first
	
	struct adc_config config_adc;

	adc_get_config_defaults(&config_adc);
	config_adc.gain_factor = ADC_GAIN_FACTOR_DIV2;
	config_adc.clock_source = GCLK_GENERATOR_1;
	config_adc.clock_prescaler = ADC_CTRLB_PRESCALER_DIV4;
	config_adc.differential_mode = false;
	config_adc.freerunning = false;
	config_adc.left_adjust = false;
	config_adc.positive_input = ADC_POSITIVE_INPUT_PIN0;	
	config_adc.negative_input = ADC_NEGATIVE_INPUT_IOGND;
	config_adc.reference = ADC_REFCTRL_REFSEL_INTVCC1;
	config_adc.resolution = ADC_RESOLUTION_12BIT;
	config_adc.sample_length = 3;
	// EVENTs
	config_adc.event_action = ADC_EVENT_ACTION_START_CONV;		

	if (STATUS_OK != adc_init(&g_adc_instance, ADC, &config_adc))
	{
		while (1){};
	}

	if (STATUS_OK != adc_enable(&g_adc_instance))
	{
		while (1){};
	}

	// configure callbacks
	adc_register_callback(&g_adc_instance, adc_complete_callback, ADC_CALLBACK_READ_BUFFER);
	adc_enable_callback(&g_adc_instance, ADC_CALLBACK_READ_BUFFER);

	return 0;
} // adctcConfigureADCmodule()

Here's the configuration of the EVENT channel:

struct events_resource g_event_tc2adc;

int adctcConfgureEvents(void)
{
    struct events_config config;

    // setup channel
    events_get_config_defaults(&config);
    config.clock_source = GCLK_GENERATOR_1;
    config.generator = EVSYS_ID_GEN_TC1_OVF;
    config.path = EVENTS_PATH_SYNCHRONOUS;	// all in same clock domain (GCLK1)
    config.edge_detect = EVENTS_EDGE_DETECT_RISING;

    if (STATUS_OK != events_allocate(&g_event_tc2adc, &config))
    {
        while (1){};
    }

    EVSYS->CTRL.bit.GCLKREQ = 1;

    // add user
    if (STATUS_OK != events_attach_user(&g_event_tc2adc, EVSYS_ID_USER_ADC_START))
    {
        while (1){};
    }

} // adctcConfgureEvents()

These setup functions get called in this order:

	adctcConfigureADCmodule();
	adctcConfigureSampleTimer();
	adctcConfgureEvents();

 

Based on the following ASF functions, called repeatedly in the main() loop, the TC1 trigger is seen by the channel but the ADC is never ready.  I've confirmed the EVSYS register CHSTATUS USRRDY bit for the assigned channel 0 is low (not ready). 

 

if (events_is_busy(&g_event_tc2adc))
    // This is always False
    
if (events_is_detected(&g_event_tc2adc))
    // this is True
    
if (events_is_overrun(&g_event_tc2adc))
    // this is True
    
if (events_is_users_ready(&g_event_tc2adc))
    // this is always false

 

Also, I can use either adc_start_conversion() or adc_read_buffer_job() to successfully trigger an ADC conversion from software, so the ADC appears configured properly to do a conversion.  What can be preventing it from "being ready" for the EVSYS event channel?

 

Thank you!

This topic has a solution.
Last Edited: Fri. Oct 4, 2019 - 06:39 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check Table 23-6. User Multiplexer Selection, 

EVENTS_PATH_SYNCHRONOUS

 is not possible for ADC start.

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lars,

 

Thank you very much for the quick and excellent reply!  I obviously missed the info in Table 23-6, which says the ADC must be an asynchronous path.  I swore I tried both async and re-reync paths.  I am now seeing the ADC sample, although the CHSTATUS USRRDY bit for the channel remains cleared.  Perhaps that is why I didn't notice the async path working before.  I now also see that channel status does not get updated for async paths.

 

Cheers,

Walt