Analog Comparator Functions - PalouseRobosub/SUBLIBinal GitHub Wiki
Comparator Functions
This page is designed to describe all of the functions enabled by the comparator library within SUBLIBinal. Please select the appropriate function from the list below to be redirected to the appropriate documentation.
Functions
initialize_Comparator
Prototype
Error initialize_Comparator(Comparator_Config config);
Description
This function will configure and initialize a comparator module. This function will internally call updateVReference_Comparator to configure the internal reference as close to your provided reference as possible. Note that if you configure multiple comparators on different channels, then they will all use the same reference of the most recently initialized comparator.
Parameters
- Comparator_Config config: This parameter should be a completely filled out configuration structure. Ensure that the callback function is set or initialized to NULL, or the comparator interrupt will cause undefined behavior within your program.
Return
This function will return the following errors:
ERR_INVALID_PIN
: This will be returned if the pin specified is not available for the specified comparison channel.ERR_INVALID_VREF
: This parameter will be returned if the voltage_reference parameter of the structure is below 0 or above 75% of 3.3V - these values are not attinable internally. If this error is returned, the comparator is still properly configured. However, the reference terminal is specified to be the external reference pin (RB3 for COMP_CH_1, RB1 for COMP_CH_2, and RB15 for COMP_CH_3).
enable_Comparator
Prototype
void enable_Comparator(Comparator_Channel channel);
Description
This function will enable a comparator and the associated interrupt on a specified channel.
Parameters
- Comparator_Channel channel: This parameter specifies which channel should be enabled.
Return
This function does not return any values.
disable_Comparator
Prototype
void disable_Comparator(Comparator_Channel channel);
Description
This function will disable a comparator and the associated interrupt on a specified channel.
Parameters
- Comparator_Channel channel: This parameter specifies which channel should be disabled.
Return
This function does not return any values.
updateVReference_Comparator
Prototype
Error updateVReference_Comparator(float voltage_reference);
Description
This function will attempt to reconfigure the internal voltage reference for use by the analog comparators. There is only a single internal reference, so all comparators must share the same internal reference. For different references for each comparator, external inputs must be used. The function will attempt to generate a voltage as close as possible to the specified reference.
Parameters
- float voltage_reference: This parameter is a value (in Volts) that the reference should be adjusted to. The function can generate voltages between 0% - 75% of Vdd (3.3V) allowing for a range from 0V - 2.475V.
Return
This function will return an error code associated with it's success
ERR_INVALID_VREF
: This will be returned if the function fails to generate a reference. This is only returned if the provided reference is outside of the absolute bounds of the function input parameters.