Create an AC device instance struct, which will be associated with an Analog Comparator peripheral hardware instance.
staticstructac_module ac_instance;
Note: Device instance structures shall never go out of scope when in use.
Define a macro to select the comparator channel that will be sampled, for convenience.
#defineAC_COMPARATOR_CHANNEL AC_CHAN_CHANNEL_0
Create a new function configure_ac(), which will be used to configure the overall Analog Comparator peripheral.
void configure_ac(void){
Create an Analog Comparator peripheral configuration structure that will be filled out to set the module configuration.
structac_config config_ac;
Fill the Analog Comparator peripheral configuration structure with the default module configuration values.
ac_get_config_defaults(&config_ac);
Initialize the Analog Comparator peripheral and associate it with the software instance structure that was defined previously.
ac_init(&ac_instance, AC, &config_ac);
Create a new function configure_ac_channel(), which will be used to configure the overall Analog Comparator peripheral.
void configure_ac_channel(void){
Create an Analog Comparator channel configuration structure that will be filled out to set the channel configuration.
structac_chan_config config_ac_chan;
Fill the Analog Comparator channel configuration structure with the default channel configuration values.
ac_chan_get_config_defaults(&config_ac_chan);
Alter the channel configuration parameters to set the channel to one-shot mode, with the correct negative and positive MUX selections and the desired voltage scaler.
Enable the now initialized Analog Comparator peripheral.
ac_enable(&ac_instance);
Note: This should not be done until after the AC is setup and ready to be used.
The online versions of the documents are provided as a courtesy. Verify all content and data in the device’s PDF documentation found on the device product page.