U8 adcifa_get_values_from_sequencer(volatile avr32_adcifa_t * adcifa,
                                    U8 sequencer,
                                    adcifa_sequencer_opt_t * p_adcifa_sequencer_opt,
                                    S16* adcifa_values)
{
	U8 i;
	// Sanity Check
	Assert( adcifa!=NULL );

	// wait for end of sequence
	if(adcifa_check_eos(adcifa, sequencer) != true)
		return ADCIFA_STATUS_NOT_COMPLETED;

	switch (sequencer) {
	case 0:
		// Read values from Sequencer 0
		for (i = 0; i < p_adcifa_sequencer_opt->convnb; i++) {
			adcifa_values[i] = ADCIFA_read_resx_sequencer_0(i);
		}
		break;
	case 1:
		// Read values from Sequencer 1
		for (i = 0; i < p_adcifa_sequencer_opt->convnb; i++) {
			adcifa_values[i] = ADCIFA_read_resx_sequencer_1(i);
		}
		break;
	default:
		break;
	}

	return ADCIFA_STATUS_COMPLETED;
}
Example #2
0
File: adcifa.c Project: Mazetti/asf
void adcifa_calibrate_offset(volatile avr32_adcifa_t *adcifa,
	adcifa_opt_t *p_adcifa_opt, uint32_t pb_hz){

	/* Sequencer Configuration */
	adcifa_sequencer_opt_t adcifa_sequence_opt;
	adcifa_sequencer_conversion_opt_t
	adcifa_sequence_conversion_opt[CALIBRATION_ADCIFA_NUMBER_OF_SEQUENCE];

	/* Configure the ADC */
	p_adcifa_opt->sample_and_hold_disable  = true;
	p_adcifa_opt->single_sequencer_mode    = true;
	p_adcifa_opt->free_running_mode_enable = false;
	p_adcifa_opt->sleep_mode_enable        = false;
	p_adcifa_opt->mux_settle_more_time     = false;

	/* Clear offset calibration value before starting calibration */
	p_adcifa_opt->offset_calibration_value = 0;

	/* Configure ADCIFA core */
	adcifa_configure(&AVR32_ADCIFA, p_adcifa_opt, pb_hz);

	/* ADCIFA sequencer 0 configuration structure*/
	adcifa_sequence_opt.convnb               =
		CALIBRATION_ADCIFA_NUMBER_OF_SEQUENCE;
	adcifa_sequence_opt.resolution           =
		ADCIFA_SRES_12B;
	adcifa_sequence_opt.trigger_selection    =
		ADCIFA_TRGSEL_SOFT;
	adcifa_sequence_opt.start_of_conversion  =
		ADCIFA_SOCB_ALLSEQ;
	adcifa_sequence_opt.sh_mode              =
		ADCIFA_SH_MODE_OVERSAMP;
	adcifa_sequence_opt.half_word_adjustment =
		ADCIFA_HWLA_NOADJ;
	adcifa_sequence_opt.software_acknowledge =
		ADCIFA_SA_NO_EOS_SOFTACK;

	/* ADCIFA conversions for sequencer 0*/
	for (uint8_t i=0; i<CALIBRATION_ADCIFA_NUMBER_OF_SEQUENCE; i++){
		adcifa_sequence_conversion_opt[i].channel_p = AVR32_ADCIFA_INP_GNDANA;
		adcifa_sequence_conversion_opt[i].channel_n = AVR32_ADCIFA_INN_GNDANA;
		adcifa_sequence_conversion_opt[i].gain = ADCIFA_SHG_1;
	}
	/* Configure ADCIFA sequencer 0 */
	adcifa_configure_sequencer(&AVR32_ADCIFA, 0, &adcifa_sequence_opt,
			adcifa_sequence_conversion_opt);

	/* Start ADCIFA sequencer 0 */
	adcifa_start_sequencer(&AVR32_ADCIFA, 0);

	/* Wait end of ADCIFA sequencer 0*/
	while(!ADCIFA_is_eos_sequencer_0());

	/* The last converted value is the offset value */
	p_adcifa_opt->offset_calibration_value =
		- ADCIFA_read_resx_sequencer_0(CALIBRATION_ADCIFA_NUMBER_OF_SEQUENCE-1);

}
Example #3
0
/** \brief Return last converted value. */
static uint32_t inline rtouch_get_adc_value(void)
{
#ifdef AVR32_ADCIFA
	uint32_t value;

	if (s_current_channel < 8) {
		value = ADCIFA_read_resx_sequencer_0(0);
	} else {
		value = (~ADCIFA_read_resx_sequencer_0(0));
	}

	return value;

#else
	volatile avr32_adc_t *adc = &RTOUCH_ADC;

	return adc->lcdr;
#endif
}