コード例 #1
0
ファイル: ac_example2.c プロジェクト: InSoonPark/asf
/**
 * \brief Main function.
 */
int main(void)
{
	enum ac_status_t status;

	pmic_init();
	board_init();
	sysclk_init();
	sleepmgr_init();

	ac_set_interrupt_callback(&ACA, example_aca_interrupt_callback);

	/* Write configuration of analog comparator A channel 0. */
	ac_write_config(&ACA, 0, &aca0_config);

	/* Write predefined configuration of analog comparator A channel 1. */
	ac_write_config(&ACA, 1, &aca1_config);

	/* Enable all the analog comparator channels. */
	ac_enable(&ACA, 0);
	ac_enable(&ACA, 1);

	/*
	 * Wait for analog comparator to stabilize (muxing, voltage scaler,
	 * bandgap voltage, etc).
	 */
	mdelay(1);

	/* Check comparator status and initialize the LEDs. */
	status = ac_get_status(&ACA, 0);
	example_ac_update_single_leds(0, status);
	status = ac_get_status(&ACA, 1);
	example_ac_update_single_leds(1, status);

	cpu_irq_enable();

	for (;;) {
		/* Go to sleep, everything is handled by interrupts. */
		sleepmgr_enter_sleep();
	}
}
コード例 #2
0
/**
 * \brief Analog comparator interrupt callback function
 *
 * This function is called when an interrupt has occurred on a channel in analog
 * comparator.
 *
 * \param ac Pointer to the analog comparator (AC) base address which caused
 *           the interrupt
 * \param channel The analog comparator channel that caused the interrupt
 * \param status Analog comparator window status given by a \ref ac_status_t
 *               value
 */
static void example_aca_interrupt_callback(AC_t *ac, uint8_t channel,
		enum ac_status_t status)
{
	/*
	 * If trigger was caused by moving into above or below, switch to
	 * trigger by being inside. If trigger was caused by moving inside the
	 * window, switch to trigger on outside.
	 */
	if (status != AC_STATUS_INSIDE) {
		ac_set_interrupt_mode(&aca_config, AC_INT_MODE_INSIDE_WINDOW);
	} else {
		ac_set_interrupt_mode(&aca_config, AC_INT_MODE_OUTSIDE_WINDOW);
	}

	ac_disable(&ACA, 1);
	ac_disable(&ACA, 0);
	ac_write_config(&ACA, 0, &aca_config);
	ac_enable(&ACA, 0);
	ac_enable(&ACA, 1);

	example_ac_update_window_leds(status);
}
コード例 #3
0
/**
 * \brief Main function.
 */
int main(void)
{
	enum ac_status_t status;

	pmic_init();
	board_init();
	sysclk_init();
	sleepmgr_init();

	ac_set_interrupt_callback(&ACA, example_aca_interrupt_callback);


	/* Setup the analog comparator B in window mode. */
	ac_set_mode(&aca_config, AC_MODE_WINDOW);
	ac_set_voltage_scaler(&aca_config, 11);
	ac_set_hysteresis(&aca_config, AC_HYSMODE_LARGE_gc);
	ac_set_negative_reference(&aca_config, AC_MUXNEG_SCALER_gc);
	ac_set_positive_reference(&aca_config, AC_MUXPOS_PIN1_gc);
	ac_set_interrupt_mode(&aca_config, AC_INT_MODE_INSIDE_WINDOW);
	ac_set_interrupt_level(&aca_config, AC_INT_LVL_MED);

	/*
	 * Write configuration of analog comparator B channel 0, half of window
	 * configuration.
	 */
	ac_write_config(&ACA, 0, &aca_config);

	/* Set the lower reference of the compare window. */
	ac_set_negative_reference(&aca_config, AC_MUXNEG_BANDGAP_gc);

	/*
	 * Write configuration of analog comparator B channel 1, other half of
	 * window configuration.
	 */
	ac_write_config(&ACA, 1, &aca_config);

	/* Enable all the analog comparator channels. */
	ac_enable(&ACA, 0);
	ac_enable(&ACA, 1);

	/*
	 * Wait for analog comparator to stabilize (muxing, voltage scaler,
	 * bandgap voltage, etc).
	 */
	mdelay(1);

	/* Check comparator status and initialize the LEDs. */
	status = ac_get_status(&ACA, 0);
	example_ac_update_window_leds(status);

	/*
	 * Read back analog comparator channel 0 configuration, to be used when
	 * updating the window interrupt mode in the interrupt callback
	 * function.
	 */
	ac_read_config(&ACA, 0, &aca_config);

	cpu_irq_enable();

	for (;;) {
		/* Go to sleep, everything is handled by interrupts. */
		sleepmgr_enter_sleep();
	}
}