ADC/AFEC in SAM E70, HELP!!!

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

Am trying to get the adc/afec module to work.

But for some reasons, the modules isn't working.

 

This one has been derived from the "asf/sam/drivers/afec/example1/afec_example1.c"

 

afec_enable(AFEC0);

struct afec_config afec_cfg;

afec_get_config_defaults(&afec_cfg);

afec_init(AFEC0, &afec_cfg);

afec_set_trigger(AFEC0, AFEC_TRIG_FREERUN);

struct afec_ch_config afec_ch_cfg;
afec_ch_get_config_defaults(&afec_ch_cfg);
afec_ch_cfg.gain = AFEC_GAINVALUE_0;
afec_ch_set_config(AFEC0, AFEC_CHANNEL_10, &afec_ch_cfg);
afec_channel_set_analog_offset(AFEC0, AFEC_TEMPERATURE_SENSOR, 0x200);

struct afec_temp_sensor_config afec_temp_sensor_cfg;

//afec_temp_sensor_get_config_defaults(&afec_temp_sensor_cfg);
//afec_temp_sensor_cfg.rctc = true;
//afec_temp_sensor_set_config(AFEC0, &afec_temp_sensor_cfg);
afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_10,afec_temp_sensor_end_conversion, 1);

while (1) {

    if(is_conversion_done == true) {

        ul_vol = g_ul_value * VOLT_REF / MAX_DIGITAL;
        ul_temp = (ul_vol - 720)  * 100 / 233 + 27;

        printf("ADC is: %4d\r", (int)ul_temp);
        is_conversion_done = false;

        }

   }

outside the main, i have made a slight change in the call back function as well.

static void afec_temp_sensor_end_conversion(void)
{
    g_ul_value = afec_channel_get_value(AFEC0, AFEC_CHANNEL_10);
    is_conversion_done = true;
}

 

I have marked the lines that i have made changes.

 

I changes the trigger to free running, channel to 10 & interrupt source to end of conversion in channel 10.

 

I don't know what I am missing in here.

Silly beans are always silly
:)

Last Edited: Mon. Aug 14, 2017 - 06:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The code works when temp channel is selected.

But doesn't work when any other channel is selected.

Silly beans are always silly
:)

Last Edited: Fri. Oct 28, 2016 - 09:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys, please help me on this.

Silly beans are always silly
:)

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

I haven't got any Help on the ADC section.
If anybody has got some experience on ADC, please help.

Silly beans are always silly
:)

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

I can't see where you've enable channel 10. Did you call afec_channel_enable(AFEC0, AFEC_CHANNEL_10)?

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

Thanks hraftery for notifying.

Now the program is working great.

yes

Silly beans are always silly
:)

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

Great to hear. It's so hard to know whether you're checking all the right boxes when something isn't working. The ASF documentation is rarely enlightening and often misleading. I preferred this resource when I was going through it. Although it doesn't target the E70 specifically, it still mostly applies:

 

Atmel AT03078: Using the AFEC in SAM4E Microcontroller

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

Getting used to ASF is hard.

Since we have chosen Atmel SAM E70 for our project, we have got no other choice other than to take the hard way."Do-learn-move_on".

Anyway, thanks for the help.

I might be needing more support as I proceed forth.

We are using almost every single peripheral available on SAM E70.

enlightened

Silly beans are always silly
:)

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

Hi,

 

 Found this thread and I'm using the SAME70 Xplained board, like you I wasn't able to get any channels other than the temperature sensor working.

I've tried using various channels (having discovered that some of the pins labelled "ad" on the Xplained board are connected to AFEC0 and some to AFEC1 (thanks Atmel) and all I get is value that hovers around 1135, despite attaching a pot (one end to +3v3 and the other to gnd).

 

In this example, I've followed the SAME70 datasheet - http://ww1.microchip.com/downloa...

Which showes AFEC0_AD6 as being on PA17, 

then I've followed through the schematic for the xplained board which shows Pin7 of J502 marked as AD6 and is connected to PA17

 

Here's my code (based on the above);

int main(void)
{
	int32_t ul_vol;
	int32_t ul_temp;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	configure_console();

	/* Output example information. */
	puts(STRING_HEADER);

afec_enable(AFEC0);
struct afec_config afec_cfg;
afec_get_config_defaults(&afec_cfg);
afec_init(AFEC0, &afec_cfg);
afec_set_trigger(AFEC0, AFEC_TRIG_FREERUN);
struct afec_ch_config afec_ch_cfg;
afec_ch_get_config_defaults(&afec_ch_cfg);
afec_ch_cfg.gain = AFEC_GAINVALUE_0;
afec_ch_set_config(AFEC0, AFEC_CHANNEL_6, &afec_ch_cfg);
afec_channel_set_analog_offset(AFEC0, AFEC_TEMPERATURE_SENSOR, 0x200);
struct afec_temp_sensor_config afec_temp_sensor_cfg;
//afec_temp_sensor_get_config_defaults(&afec_temp_sensor_cfg);
//afec_temp_sensor_cfg.rctc = true;
//afec_temp_sensor_set_config(AFEC0, &afec_temp_sensor_cfg);
afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_6,afec_temp_sensor_end_conversion, 1);
afec_channel_enable(AFEC0, AFEC_CHANNEL_6);

while (1) 
{
	if(is_conversion_done == true) {
		ul_vol = g_ul_value * VOLT_REF / MAX_DIGITAL;
		ul_temp = (ul_vol - 720)  * 100 / 233 + 27;
		printf("ADC is: %4d\r", (int)ul_temp);
		is_conversion_done = false;
	}
}
}

and like wise I modified the function outside of main;

static void afec_temp_sensor_end_conversion(void)
{
//	g_ul_value = afec_channel_get_value(AFEC0, AFEC_TEMPERATURE_SENSOR);
	g_ul_value = afec_channel_get_value(AFEC0, AFEC_CHANNEL_6);
	is_conversion_done = true;
}

 

Any help in advance would be very much appreciated.

 

Many thanks

Paula

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

Hi,

Today i tried working with 3 different SAME70 Xplained boards and observations were like

Actual voltage 288mV
Board A 244mV
Board B 304mV
Board C 302mV

ADC offset value 0x201
AFEC0 Ch8 PA19

Firmware used for all three boards were just the same.

Silly beans are always silly
:)

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

While varying the input voltage, for smaller voltages, value read was more than actual voltage like in the observation, approx. 20mV and when the as input voltage is increased, this difference drops down to zero & then it starts to fall behind.

When input was at 3V3, value read was more like 4mV less than actual.

frown

Silly beans are always silly
:)

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

Did you read:

 

tmel-44093A-ATARM-AFE-Calibration-on-SAM-V-E-S7x-Microcontrollers-Application Note_29-Aug-16
 

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

Did you set clock for AFEC peripheral ?

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

Yes,

but the issue seems to be limited to that particular board.

I tried with third same70 board & everything seems to be working good.

Silly beans are always silly
:)