Esempio n. 1
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
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_SW);

	struct afec_ch_config afec_ch_cfg;
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_TEMPERATURE_SENSOR, &afec_ch_cfg);

	/*
	 * Because the internal ADC offset is 0x800, it should cancel it and shift
	 * down to 0.
	 */
	afec_channel_set_analog_offset(AFEC0, AFEC_TEMPERATURE_SENSOR, 0x800);

	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_15,
			afec_temp_sensor_end_conversion, 1);

	while (1) {

		if(is_conversion_done == true) {

			ul_vol = g_ul_value * VOLT_REF / MAX_DIGITAL;

			/*
			 * According to datasheet, The output voltage VT = 1.44V at 27C
			 * and the temperature slope dVT/dT = 4.7 mV/C
			 */
			ul_temp = (ul_vol - 1440)  * 100 / 470 + 27;

			printf("Temperature is: %4d\r", (int)ul_temp);
			is_conversion_done = false;
		}
	}
}
Esempio n. 2
0
/**
 * \brief AFEC(ADC) configuration.
 */
static void dsp_configure_adc(void)
{
	pmc_enable_periph_clk(ID_AFEC0);

	struct afec_config afec_cfg;
	struct afec_ch_config afec_ch_cfg;

	/* AFEC0 enable, init and configuration*/
	afec_enable(AFEC0);
	afec_get_config_defaults(&afec_cfg);
	afec_init(AFEC0, &afec_cfg);

	/* Set to Software trigger*/
	afec_set_trigger(AFEC0, AFEC_TRIG_SW);

	/* AFEC0 channals configuration*/
	afec_channel_enable(AFEC0,ADC_CHANNEL_POTENTIOMETER);
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_ch_set_config(AFEC0, ADC_CHANNEL_POTENTIOMETER,&afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_TEMPERATURE_SENSOR, &afec_ch_cfg);

	/*
	 * Because the internal ADC offset is 0x800, it should cancel it and
	 * shift down to 0.
	 */
	afec_channel_set_analog_offset(AFEC0, ADC_CHANNEL_POTENTIOMETER, 0x800);
	afec_channel_set_analog_offset(AFEC0, AFEC_TEMPERATURE_SENSOR, 0x800);

	afec_channel_enable(AFEC0,AFEC_TEMPERATURE_SENSOR);
	afec_channel_enable(AFEC0,ADC_CHANNEL_MICROPHONE);

	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);

	/* Perform an auto cab on the ADC Channel 4. */
	afec_start_calibration(AFEC0);
	while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) !=
			AFEC_ISR_EOCAL);

	/* Enable potentiometer channel, disable microphone. */
	afec_channel_disable(AFEC0, ADC_CHANNEL_MICROPHONE);
	afec_channel_enable(AFEC0, AFEC_TEMPERATURE_SENSOR);
	afec_channel_enable(AFEC0, ADC_CHANNEL_MICROPHONE);

	/* Start the first conversion*/
	afec_start_software_conversion(AFEC0);
}
Esempio n. 3
0
/*
*	Inialise the temp sensor
*
*/
void temp_init(void)
{
	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_SW);
	struct afec_ch_config afec_ch_cfg;
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_TEMPERATURE_SENSOR, &afec_ch_cfg);
	afec_channel_set_analog_offset(AFEC0, AFEC_TEMPERATURE_SENSOR, 0x800);
	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_15, afec_temp_sensor_end_conversion, 1);
}
Esempio n. 4
0
// Enable or disable a channel. Use AnalogCheckReady to make sure the ADC is ready before calling this.
void AnalogInEnableChannel(AnalogChannelNumber channel, bool enable)
{
	if ((unsigned int)channel < numChannels)
	{
		if (enable)
		{
			activeChannels |= (1u << channel);
#if SAM3XA || SAM4S
			adc_enable_channel(ADC, GetAdcChannel(channel));
#if SAM4S
			adc_set_calibmode(ADC);										// auto calibrate at start of next sequence
#endif
			if (GetAdcChannel(channel) == ADC_TEMPERATURE_SENSOR)
			{
				adc_enable_ts(ADC);
			}
#elif SAM4E || SAME70
			afec_ch_config cfg;
			afec_ch_get_config_defaults(&cfg);
			afec_ch_set_config(GetAfec(channel), GetAfecChannel(channel), &cfg);
			afec_channel_set_analog_offset(GetAfec(channel), GetAfecChannel(channel), 2048);	// need this to get the full ADC range
			afec_channel_enable(GetAfec(channel), GetAfecChannel(channel));
#if SAM4E
			afec_start_calibration(GetAfec(channel));					// do automatic calibration
#endif
#endif
		}
		else
		{
			activeChannels &= ~(1u << channel);
#if SAM3XA || SAM4S
			adc_disable_channel(ADC, GetAdcChannel(channel));
			if (GetAdcChannel(channel) == ADC_TEMPERATURE_SENSOR)
			{
				adc_disable_ts(ADC);
			}
#elif SAM4E || SAME70
			afec_channel_disable(GetAfec(channel), GetAfecChannel(channel));
#endif
		}
	}
}
void init_adc(void)
{
	struct afec_config afec_cfg;
	struct afec_ch_config afec_ch_cfg;

	
	afec_enable(AFEC0);
	afec_enable(AFEC1);

	afec_get_config_defaults(&afec_cfg);
	afec_cfg.resolution = AFEC_12_BITS;
	afec_init(AFEC0, &afec_cfg);
	afec_init(AFEC1, &afec_cfg);
	
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_ch_cfg.gain = AFEC_GAINVALUE_3;
	
	afec_ch_set_config(AFEC1, AFEC_CHANNEL_9, &afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_4, &afec_ch_cfg);
	afec_ch_set_config(AFEC1, AFEC_CHANNEL_4, &afec_ch_cfg);
	afec_ch_set_config(AFEC1, AFEC_CHANNEL_5, &afec_ch_cfg);

	afec_set_trigger(AFEC0, AFEC_TRIG_SW);
	afec_set_trigger(AFEC1, AFEC_TRIG_SW);

	afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, afec0_data_ready, 1);
	afec_set_callback(AFEC1, AFEC_INTERRUPT_DATA_READY, afec1_data_ready, 1);

// Got this calibration code from a SAM4E example, supposedly code compatible with the SAME70, but this doesn't build
//	afec_start_calibration(AFEC0);
//	while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
	
//	afec_start_calibration(AFEC1);
//	while((afec_get_interrupt_status(AFEC1) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
	
}
Esempio n. 6
0
/**
 *  \brief ACC example application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t uc_key;
	int16_t s_volt = 0;
	uint32_t ul_value = 0;
	volatile uint32_t ul_status = 0x0;
	int32_t l_volt_dac0 = 0;

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

	/* Initialize debug console */
	configure_console();

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

	/* Initialize DACC */
	/* Enable clock for DACC */
	pmc_enable_periph_clk(ID_DACC);
	/* Reset DACC registers */
	dacc_reset(DACC);
	/* External trigger mode disabled. DACC in free running mode. */
	dacc_disable_trigger(DACC, DACC_CHANNEL_0);
	/* Half word transfer mode */
	dacc_set_transfer_mode(DACC, 0);
#if (SAM3S) || (SAM3XA)
	/* Power save:
	 * sleep mode  - 0 (disabled)
	 * fast wakeup - 0 (disabled)
	 */
	dacc_set_power_save(DACC, 0, 0);
#endif

	/* Enable output channel DACC_CHANNEL */
	dacc_enable_channel(DACC, DACC_CHANNEL_0);
	/* Setup analog current */
	dacc_set_analog_control(DACC, DACC_ANALOG_CONTROL);

	/* Set DAC0 output at ADVREF/2. The DAC formula is:
	 *
	 * (5/6 * VOLT_REF) - (1/6 * VOLT_REF)     volt - (1/6 * VOLT_REF)
	 * ----------------------------------- = --------------------------
	 *              MAX_DIGITAL                       digit
	 *
	 * Here, digit = MAX_DIGITAL/2
	 */
	dacc_write_conversion_data(DACC, MAX_DIGITAL / 2, DACC_CHANNEL_0);
	l_volt_dac0 = (MAX_DIGITAL / 2) * (2 * VOLT_REF / 3) / MAX_DIGITAL +
			VOLT_REF / 6;

	/* Enable clock for AFEC */
	afec_enable(AFEC0);

	struct afec_config afec_cfg;

	afec_get_config_defaults(&afec_cfg);
	/* Initialize AFEC */
	afec_init(AFEC0, &afec_cfg);

	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_POTENTIOMETER, &afec_ch_cfg);
	/*
	 * Because the internal ADC offset is 0x200, it should cancel it and shift
	 * down to 0.
	 */
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_POTENTIOMETER, 0x200);

	afec_set_trigger(AFEC0, AFEC_TRIG_SW);

	/* Enable channel for potentiometer. */
	afec_channel_enable(AFEC0, AFEC_CHANNEL_POTENTIOMETER);

	/* Enable clock for ACC */
	pmc_enable_periph_clk(ID_ACC);
	
	/* Initialize ACC */
	acc_init(ACC, ACC_MR_SELPLUS_AFE0_AD0, ACC_MR_SELMINUS_DAC0,
			ACC_MR_EDGETYP_ANY, ACC_MR_INV_DIS);

	/* Enable ACC interrupt */
	NVIC_EnableIRQ(ACC_IRQn);

	/* Enable */
	acc_enable_interrupt(ACC);

	dsplay_menu();

	while (1) {
		while (usart_read(CONSOLE_UART, &uc_key)) {
		}

		printf("input: %c\r\n", uc_key);

		switch (uc_key) {
		case 's':
		case 'S':
			printf("Input DAC0 output voltage (%d~%d mv): ",
					(VOLT_REF / 6), (VOLT_REF * 5 / 6));
			s_volt = get_input_voltage();
			puts("\r");

			if (s_volt > 0) {
				l_volt_dac0 = s_volt;
				/* The DAC formula is:
				 *
				 * (5/6 * VOLT_REF) - (1/6 * VOLT_REF)     volt - (1/6 * VOLT_REF)
				 * ----------------------------------- = --------------------------
				 *              MAX_DIGITAL                       digit
				 *
				 */
				ul_value = ((s_volt - (VOLT_REF / 6))
					* (MAX_DIGITAL * 6) / 4) / VOLT_REF;
				dacc_write_conversion_data(DACC, ul_value, DACC_CHANNEL_0);
				puts("-I- Set ok\r");
			} else {
				puts("-I- Input voltage is invalid\r");
			}
			break;
		case 'v':
		case 'V':
			/* Start conversion */
			afec_start_software_conversion(AFEC0);
			ul_status = afec_get_interrupt_status(AFEC0);
			while ((ul_status & AFEC_ISR_EOC0) != AFEC_ISR_EOC0) {
				ul_status = afec_get_interrupt_status(AFEC0);
			}
			/* Conversion is done */
			ul_value = afec_channel_get_value(AFEC0, AFEC_CHANNEL_POTENTIOMETER);

			/*
			 * Convert AFEC sample data to voltage value:
			 * voltage value = (sample data / max. resolution) * reference voltage
			 */
			s_volt = (ul_value * VOLT_REF) / MAX_DIGITAL;
			printf("-I- Voltage on potentiometer(AD0) is %d mv\n\r", s_volt);
			printf("-I- Voltage on DAC0 is %ld mv \n\r", (long)l_volt_dac0);
			break;
			
		case 'm':
		case 'M':
			dsplay_menu();
			break;
		}
	}
}
Esempio n. 7
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_key;

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

	configure_console();

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

	g_afec_sample_data.value = 0;
	g_afec_sample_data.is_done = false;
	g_max_digital = MAX_DIGITAL_12_BIT;

	afec_enable(AFEC0);

	struct afec_config afec_cfg;

	afec_get_config_defaults(&afec_cfg);
	afec_init(AFEC0, &afec_cfg);

	struct afec_ch_config afec_ch_cfg;
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_POTENTIOMETER, &afec_ch_cfg);

	/*
	 * Because the internal ADC offset is 0x800, it should cancel it and shift
	 * down to 0.
	 */
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_POTENTIOMETER, 0x800);

	afec_set_trigger(AFEC0, AFEC_TRIG_SW);

	/* Enable channel for potentiometer. */
	afec_channel_enable(AFEC0, AFEC_CHANNEL_POTENTIOMETER);

	afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, afec_data_ready, 1);

	display_menu();

	afec_start_calibration(AFEC0);
	while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);

	while (1) {
		afec_start_software_conversion(AFEC0);
		delay_ms(1000);

		/* Check if AFEC sample is done. */
		if (g_afec_sample_data.is_done == true) {
			printf("Potentiometer Voltage: %4d mv.",
					(int)(g_afec_sample_data.value * VOLT_REF
					/ g_max_digital));
			puts("\r");
			g_afec_sample_data.is_done = false;
		}

		/* Check if the user enters a key. */
		if (!uart_read(CONF_UART, &uc_key)) {
			/* Disable all afec interrupt. */
			afec_disable_interrupt(AFEC0, AFEC_INTERRUPT_ALL);
			set_afec_resolution();
			afec_enable_interrupt(AFEC0, AFEC_INTERRUPT_DATA_READY);
		}
	}
}
void tempAdcRead(void)
{
	struct afec_config afec_cfg;
	struct afec_ch_config afec_ch_cfg;

	delayCNT = 1000;

	afec_enable(AFEC0);
	afec_enable(AFEC1);

	afec_get_config_defaults(&afec_cfg);
	afec_ch_get_config_defaults(&afec_ch_cfg);

	afec_init(AFEC0, &afec_cfg);
	afec_init(AFEC1, &afec_cfg);

	afec_ch_set_config(AFEC0, AFEC_CHANNEL_0, &afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_1, &afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_2, &afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_6, &afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_14, &afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_TEMPERATURE_SENSOR, &afec_ch_cfg);
	afec_ch_set_config(AFEC1, AFEC_CHANNEL_0, &afec_ch_cfg);
	afec_ch_set_config(AFEC1, AFEC_CHANNEL_1, &afec_ch_cfg);
	afec_ch_set_config(AFEC1, AFEC_CHANNEL_2, &afec_ch_cfg);

	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_0, 0x800);
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_1, 0x800);
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_2, 0x800);
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_6, 0x800);
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_14, 0x800);
	afec_channel_set_analog_offset(AFEC0, AFEC_TEMPERATURE_SENSOR, 0x800);
	afec_channel_set_analog_offset(AFEC1, AFEC_CHANNEL_0, 0x800);
	afec_channel_set_analog_offset(AFEC1, AFEC_CHANNEL_1, 0x800);
	afec_channel_set_analog_offset(AFEC1, AFEC_CHANNEL_2, 0x800);
	
	afec_channel_enable(AFEC0, AFEC_CHANNEL_0);
	afec_channel_enable(AFEC0, AFEC_CHANNEL_1);
	afec_channel_enable(AFEC0, AFEC_CHANNEL_2);
	afec_channel_enable(AFEC0, AFEC_CHANNEL_6);
	afec_channel_enable(AFEC0, AFEC_CHANNEL_14);
	afec_channel_enable(AFEC0, AFEC_TEMPERATURE_SENSOR);
	afec_channel_enable(AFEC1, AFEC_CHANNEL_0);
	afec_channel_enable(AFEC1, AFEC_CHANNEL_1);
	afec_channel_enable(AFEC1, AFEC_CHANNEL_2);

	afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_0, afec0_temp_adcRead_ch0, 1);
	afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_1, afec0_temp_adcRead_ch1, 1);
	afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_2, afec0_temp_adcRead_ch2, 1);
	afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_6, afec0_temp_adcRead_ch6, 1);
	afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_14, afec0_temp_adcRead_ch14, 1);	
	afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_15, afec0_temp_adcRead_tempSensor, 1);
	afec_set_callback(AFEC1, AFEC_INTERRUPT_EOC_0, afec1_temp_adcRead_ch0, 1);
	afec_set_callback(AFEC1, AFEC_INTERRUPT_EOC_1, afec1_temp_adcRead_ch1, 1);
	afec_set_callback(AFEC1, AFEC_INTERRUPT_EOC_2, afec1_temp_adcRead_ch2, 1);
	
	afec_start_calibration(AFEC0);
	while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
	
	afec_start_calibration(AFEC1);
	while((afec_get_interrupt_status(AFEC1) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);

}
Esempio n. 9
0
/**
 * \brief Set AFEC test mode.
 */
static void set_afec_test(void)
{
	uint8_t uc_key;
	struct afec_config afec_cfg;
	struct afec_ch_config afec_ch_cfg;

	display_menu();

	afec_enable(AFEC0);
	afec_get_config_defaults(&afec_cfg);
	afec_ch_get_config_defaults(&afec_ch_cfg);

	while (uart_read(CONF_UART, &uc_key));

	switch (uc_key) {
	case '0':
		/*
		* This test will use AFEC0 channel4 to connect with external input.
		* Setting gain = 4, if external input voltage is 100mv,
		* the ouput result should be 1650 + 100 * 4 = 2050mv .
		*/
		puts("Gain Test \n\r");
		g_delay_cnt = 1000;
		afec_init(AFEC0, &afec_cfg);
		afec_ch_cfg.gain = AFEC_GAINVALUE_3;
		afec_ch_set_config(AFEC0, AFEC_CHANNEL_4, &afec_ch_cfg);
		afec_set_trigger(AFEC0, AFEC_TRIG_SW);
		afec_channel_enable(AFEC0, AFEC_CHANNEL_4);
		afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, afec0_data_ready, 1);
		afec_start_calibration(AFEC0);
		while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
		break;
	case '1':
		/*
		 *  This test will use AFEC0 channel5 to connect with potentiometer and
		 * AFEC1 channel0 to connect with external input. The AFEC0 conversion
		 * is triggered by software every 3s and AFEC1 conversion is triggered
		 * by TC every 1s.
		 */
		puts("Dual AFEC Conversion Test \n\r");
		g_delay_cnt = 3000;
		afec_enable(AFEC1);
		afec_init(AFEC0, &afec_cfg);
		afec_init(AFEC1, &afec_cfg);
		afec_ch_set_config(AFEC0, AFEC_CHANNEL_POTENTIOMETER, &afec_ch_cfg);
		afec_ch_set_config(AFEC1, AFEC_CHANNEL_0, &afec_ch_cfg);
		/*
		 * Because the internal AFEC offset is 0x800, it should cancel it and shift
		 * down to 0.
		 */
		afec_channel_set_analog_offset(AFEC1, AFEC_CHANNEL_0, 0x800);
		afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_POTENTIOMETER, 0x800);
		afec_set_trigger(AFEC0, AFEC_TRIG_SW);
		configure_tc_trigger();
		afec_channel_enable(AFEC1, AFEC_CHANNEL_0);
		afec_channel_enable(AFEC0, AFEC_CHANNEL_POTENTIOMETER);
		afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, afec0_data_ready, 1);
		afec_set_callback(AFEC1, AFEC_INTERRUPT_DATA_READY, afec1_data_ready, 1);
		afec_start_calibration(AFEC0);
		while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
		afec_start_calibration(AFEC1);
		while((afec_get_interrupt_status(AFEC1) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
		break;
	case '2':
		/*
		 * This test will use AFEC0 channl4 and channel5 as positive and
		 * negative input, so the output result is external input voltage subtracting
		 * potentiometer voltage. The differential voltage range is -1.65v~ +1.65v.
		 */
		puts("Differential Input Test \n\r");
		g_delay_cnt = 1000;
		afec_init(AFEC0, &afec_cfg);
		afec_ch_cfg.diff = true;
		afec_ch_set_config(AFEC0, AFEC_CHANNEL_POTENTIOMETER, &afec_ch_cfg);
		afec_ch_set_config(AFEC0, AFEC_CHANNEL_4, &afec_ch_cfg);
		afec_set_trigger(AFEC0, AFEC_TRIG_SW);
		afec_channel_enable(AFEC0, AFEC_CHANNEL_4);
		afec_channel_enable(AFEC0, AFEC_CHANNEL_POTENTIOMETER);
		afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, afec0_diff_data_ready, 1);
		afec_start_calibration(AFEC0);
		while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
		break;
	case '3':
		/*
		 * This test will configure user sequence channel1, channel0,
		 * so the first conversion is is channel1 and next is channel0.
		 * The output information will show this.
		 */
		puts("User Sequence Test \n\r");
		g_delay_cnt = 1000;
		afec_init(AFEC0, &afec_cfg);
		afec_ch_set_config(AFEC0, AFEC_CHANNEL_0, &afec_ch_cfg);
		afec_ch_set_config(AFEC0, AFEC_CHANNEL_1, &afec_ch_cfg);
		afec_channel_enable(AFEC0, AFEC_CHANNEL_0);
		afec_channel_enable(AFEC0, AFEC_CHANNEL_1);
		afec_configure_sequence(AFEC0, ch_list, 2);
		afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_0, afec_eoc_0, 1);
		afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_1, afec_eoc_1, 1);
		afec_start_calibration(AFEC0);
		while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
		break;
	case '4':
		/*
		 * This test use AFEC0 channel4 to connect with external input.
		 * It integrate the enhanced resolution test and gain and offset test.
		 */
		puts("Typical Application Test \n\r");
		g_delay_cnt = 1000;
		g_max_digital = MAX_DIGITAL_12_BIT * 16;
		afec_cfg.resolution = AFEC_16_BITS;
		afec_init(AFEC0, &afec_cfg);
		afec_ch_cfg.gain = AFEC_GAINVALUE_3;
		afec_ch_set_config(AFEC0, AFEC_CHANNEL_4, &afec_ch_cfg);
		afec_set_trigger(AFEC0, AFEC_TRIG_SW);
		afec_channel_enable(AFEC0, AFEC_CHANNEL_4);
		afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, afec0_data_ready, 1);
		afec_start_calibration(AFEC0);
		while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
		break;
	default:
		puts("Please select feature test correctly! \n\r");
		break;
	}
}