Пример #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;
		}
	}
}
Пример #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);
}
Пример #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);
}