SAME54 async adc

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

Hello,

I'm trying to get the adc working with multiple channels, but I'm getting stuck.

I'm using the async adc. I'm using the SamE54 chip

 

These are my defines:

/* The channel amount for ADC */
#define ADC_0_CH_AMOUNT 16

/* The buffer size for ADC */
#define ADC_0_BUFFER_SIZE 16

/* The maximal channel number of enabled channels */
#define ADC_0_CH_MAX 15

struct adc_async_descriptor         ADC_0;
struct adc_async_channel_descriptor ADC_0_ch[ADC_0_CH_AMOUNT];

static uint8_t ADC_0_buffer[ADC_0_BUFFER_SIZE];
static uint8_t ADC_0_buffer2[ADC_0_BUFFER_SIZE];
static uint8_t ADC_0_map[ADC_0_CH_MAX + 1];

 

This is part of the code:

hri_mclk_set_APBDMASK_ADC0_bit(MCLK);
hri_gclk_write_PCHCTRL_reg(GCLK, ADC0_GCLK_ID, CONF_GCLK_ADC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));

// Disable digital pin circuitry
gpio_set_pin_direction(VREAD, GPIO_DIRECTION_OFF);
gpio_set_pin_direction(VBAT, GPIO_DIRECTION_OFF);
gpio_set_pin_direction(VIN, GPIO_DIRECTION_OFF);
gpio_set_pin_direction(VEXT, GPIO_DIRECTION_OFF);

gpio_set_pin_function(VREAD,PINMUX_PA03B_ADC0_AIN1);
gpio_set_pin_function(VBAT, PINMUX_PB03B_ADC0_AIN15);

adc_async_init(&ADC_0, ADC0, ADC_0_map, ADC_0_CH_MAX, ADC_0_CH_AMOUNT, &ADC_0_ch[0], (void *)NULL);
adc_async_register_channel_buffer(&ADC_0, 0, ADC_0_buffer, ADC_0_BUFFER_SIZE);
adc_async_register_channel_buffer(&ADC_0, 1, ADC_0_buffer2, ADC_0_BUFFER_SIZE);
adc_async_set_inputs(&ADC_0,ADC_INPUTCTRL_MUXPOS_AIN1_Val, ADC_INPUTCTRL_MUXNEG_GND_Val, 0);
adc_async_set_inputs(&ADC_0,ADC_INPUTCTRL_MUXPOS_AIN15_Val, ADC_INPUTCTRL_MUXNEG_GND_Val, 1);

adc_async_enable_channel(&ADC_0, 0);
adc_async_register_callback(&ADC_0, 0, ADC_ASYNC_CONVERT_CB, convert_cb_ADC_0);
adc_async_enable_channel(&ADC_0, 1);
adc_async_register_callback(&ADC_0, 1, ADC_ASYNC_CONVERT_CB, convert_cb_ADC_1);

adc_async_start_conversion(&ADC_0);

 

But only callback for channel 0 is called

 

I'm probably missing something obvious.

 

Thanks in advance.

 

Last Edited: Mon. Mar 23, 2020 - 10:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are multiple inputs but not multiple channels (for SAME54), you would notice this if you follow the code to the implementation, e.g. :

/**
 * \brief Enable ADC
 */
void _adc_async_enable_channel(struct _adc_async_device *const device, const uint8_t channel)
{
    (void)channel;

    hri_adc_set_CTRLA_ENABLE_bit(device->hw);
}

/Lars

 

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

Thanks, but the SamE54 datasheet says: 

Dual 12-bit, 1 MSPS Analog-to-Digital Converter (ADC) with up to 16 channels each

ASF doesn't implement/ use the channel system? 

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

It's just about naming, the channel concept in the start API is not applicable to the SAME54. Use adc_async_set_inputs. You can also look at the start example which does this using DMA.

/Lars