示例#1
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);

	/* 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 A interrupt callback function
 *
 * This function is called when an interrupt has occurred on a channel in analog
 * comparator A.
 *
 * \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 channel 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)
{
	example_ac_update_single_leds(channel, 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);
	ac_set_interrupt_callback(&ACB, example_acb_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);

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

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

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

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

	/* Enable all the analog comparator channels. */
	ac_enable(&ACA, 0);
	ac_enable(&ACA, 1);
	ac_enable(&ACB, 0);
	ac_enable(&ACB, 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);
	status = ac_get_status(&ACB, 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(&ACB, 0, &acb_config);

	cpu_irq_enable();

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