Copy-paste the following setup code to your user application:
static
struct ac_module ac_instance;
#define AC_COMPARATOR_CHANNEL AC_CHAN_CHANNEL_0
void configure_ac(
void)
{
struct ac_config config_ac;
ac_get_config_defaults(&config_ac);
ac_init(&ac_instance, AC, &config_ac);
}
void configure_ac_channel(
void)
{
struct ac_chan_config ac_chan_conf;
ac_chan_get_config_defaults(&ac_chan_conf);
ac_chan_conf.sample_mode = AC_CHAN_MODE_SINGLE_SHOT;
ac_chan_conf.positive_input = AC_CHAN_POS_MUX_PIN0;
ac_chan_conf.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC;
ac_chan_conf.vcc_scale_factor = 32;
struct system_pinmux_config ac0_pin_conf;
system_pinmux_get_config_defaults(&ac0_pin_conf);
ac0_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
ac0_pin_conf.mux_position = CONF_AC_MUX;
system_pinmux_pin_set_config(CONF_AC_PIN, &ac0_pin_conf);
ac_chan_set_config(&ac_instance, AC_COMPARATOR_CHANNEL, &ac_chan_conf);
ac_chan_enable(&ac_instance, AC_COMPARATOR_CHANNEL);
}
Add to user application initialization (typically the start of
main()):
system_init();
configure_ac();
configure_ac_channel();
ac_enable(&ac_instance);