Example #1
0
/**
 * \internal
 * \brief Test for AC comparison in single shot mode.
 *
 * This test checks the single shot comparison of the AC.
 * 0.5V is applied to the negative input of AC from internal voltage scaler.
 * 0V and 1V from DAC is applied to the positive input and the results
 * are verified.
 *
 * \param test Current test case.
 */
static void run_ac_single_shot_test(const struct test_case *test)
{
	volatile uint32_t state = AC_CHAN_STATUS_UNKNOWN;

	/* Skip test if initialization failed */
	test_assert_true(test, ac_init_success,
			"Skipping test due to failed AC initialization");

	/* Test for positive input < negative input */
	dac_chan_write(&dac_inst, DAC_CHANNEL_0, DAC_VAL_ZERO_VOLT);
	delay_ms(1);
	ac_chan_trigger_single_shot(&ac_inst, AC_CHAN_CHANNEL_0);
	while (!ac_chan_is_ready(&ac_inst, AC_CHAN_CHANNEL_0)) {
	}
	state = ac_chan_get_status(&ac_inst, AC_CHAN_CHANNEL_0);
	state = state & AC_CHAN_STATUS_NEG_ABOVE_POS;
	test_assert_true(test, state == AC_CHAN_STATUS_NEG_ABOVE_POS,
			"AC comparison failed: POS < NEG not detected");

	/* Test for negative input < positive input */
	state = AC_CHAN_STATUS_UNKNOWN;
	dac_chan_write(&dac_inst, DAC_CHANNEL_0, DAC_VAL_ONE_VOLT);
	delay_ms(1);
	ac_chan_trigger_single_shot(&ac_inst, AC_CHAN_CHANNEL_0);
	while (!ac_chan_is_ready(&ac_inst, AC_CHAN_CHANNEL_0)) {
	}
	state = ac_chan_get_status(&ac_inst, AC_CHAN_CHANNEL_0);
	state = state & AC_CHAN_STATUS_POS_ABOVE_NEG;
	test_assert_true(test, state == AC_CHAN_STATUS_POS_ABOVE_NEG,
			"AC comparison failed: Interrupt not detected");
	ac_chan_clear_status(&ac_inst, AC_CHAN_CHANNEL_0);
}
Example #2
0
int main(void)
{
	//! [setup_init]
	system_init();
	configure_ac();
	configure_ac_channel();
	//! [setup_14]
	ac_enable(&ac_instance);
	//! [setup_14]
	//! [setup_init]

	//! [main]
	//! [main_1]
	ac_chan_trigger_single_shot(&ac_instance, AC_COMPARATOR_CHANNEL);
	//! [main_1]

	//! [main_2]
	uint8_t last_comparison = AC_CHAN_STATUS_UNKNOWN;
	//! [main_2]

	//! [main_3]
	while (true) {
	//! [main_3]
	//! [main_4]
		if (ac_chan_is_ready(&ac_instance, AC_COMPARATOR_CHANNEL)) {
	//! [main_4]
			//! [main_5]
			do {
				last_comparison = ac_chan_get_status(&ac_instance,
						AC_COMPARATOR_CHANNEL);
			} while (last_comparison & AC_CHAN_STATUS_UNKNOWN);
			//! [main_5]

			//! [main_6]
			port_pin_set_output_level(LED_0_PIN,
					(last_comparison & AC_CHAN_STATUS_NEG_ABOVE_POS));
			//! [main_6]

			//! [main_7]
			ac_chan_trigger_single_shot(&ac_instance, AC_COMPARATOR_CHANNEL);
			//! [main_7]
		}
	}
	//! [main]
}