1.8.2.1.2 Code
Copy-paste the following setup code to your user application:
Add to user application initialization (typically the start of main()):/* AC module software instance (must not go out of scope while in use). */staticstructac_module ac_instance;/* Comparator channel that will be used. */#define AC_COMPARATOR_CHANNEL AC_CHAN_CHANNEL_0voidconfigure_ac(void){/* Create a new configuration structure for the Analog Comparator settings* and fill with the default module settings. */structac_config config_ac;ac_get_config_defaults(&config_ac);/* Alter any Analog Comparator configuration settings here if required. *//* Initialize and enable the Analog Comparator with the user settings. */ac_init(&ac_instance, AC, &config_ac);}voidconfigure_ac_channel(void){/* Create a new configuration structure for the Analog Comparator channel* settings and fill with the default module channel settings. */structac_chan_config config_ac_chan;ac_chan_get_config_defaults(&config_ac_chan);/* Set the Analog Comparator channel configuration settings. */config_ac_chan.sample_mode = AC_CHAN_MODE_SINGLE_SHOT;config_ac_chan.positive_input = AC_CHAN_POS_MUX_PIN0;config_ac_chan.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC;config_ac_chan.vcc_scale_factor = 32;config_ac_chan.interrupt_selection = AC_CHAN_INTERRUPT_SELECTION_END_OF_COMPARE;/* Set up a pin as an AC channel input. */structsystem_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);/* Initialize and enable the Analog Comparator channel with the user* settings. */ac_chan_set_config(&ac_instance, AC_COMPARATOR_CHANNEL, &config_ac_chan);ac_chan_enable(&ac_instance, AC_COMPARATOR_CHANNEL);}voidcallback_function_ac(structac_module *constmodule_inst){callback_status =true;}voidconfigure_ac_callback(void){ac_register_callback(&ac_instance, callback_function_ac, AC_CALLBACK_COMPARATOR_0);ac_enable_callback(&ac_instance, AC_CALLBACK_COMPARATOR_0);}
system_init();configure_ac();configure_ac_channel();configure_ac_callback();ac_enable(&ac_instance);
