FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
analog::AnalogComparator Class Reference

Handler of the Analog Comparator feature. More...

#include <fastarduino/analog_comparator.h>

Public Member Functions

 AnalogComparator (const AnalogComparator &)=delete
 
AnalogComparatoroperator= (const AnalogComparator &)=delete
 
template<board::AnalogPin INPUT1 = board::AnalogPin::NONE, bool INPUT0_BANDGAP = false>
void begin (ComparatorInterrupt mode=ComparatorInterrupt::NONE, bool trigger_icp=false)
 Start operations of the Analog Comparator. More...
 
void end ()
 Stop operations of the Analog Comparator. More...
 
bool output () const
 Get current output of Analog Comparator. More...
 
template<board::AnalogPin INPUT1 = board::AnalogPin::NONE, bool INPUT0_BANDGAP = false>
void begin_ (ComparatorInterrupt mode=ComparatorInterrupt::NONE, bool trigger_icp=false)
 Start operations of the Analog Comparator. More...
 
void end_ ()
 Stop operations of the Analog Comparator. More...
 

Detailed Description

Handler of the Analog Comparator feature.

Only one instance is needed for all related operations.

Usage is simple:

  1. start analog comparator with begin(); interrupts may then be generated, depending on given aruments.
  2. Optionally get analog comparator output current value with output()
  3. terminate operations with end(); no interrupts can be generated anymore.

Most methods have 2 flavours:

You shall use asynchronous methods when called from an ISR, otherwise use synchronized methods.

See also
REGISTER_ANALOG_COMPARE_ISR_FUNCTION()
REGISTER_ANALOG_COMPARE_ISR_METHOD()
REGISTER_ANALOG_COMPARE_ISR_EMPTY()

Definition at line 116 of file analog_comparator.h.

Member Function Documentation

◆ begin()

template<board::AnalogPin INPUT1 = board::AnalogPin::NONE, bool INPUT0_BANDGAP = false>
void analog::AnalogComparator::begin ( ComparatorInterrupt  mode = ComparatorInterrupt::NONE,
bool  trigger_icp = false 
)
inline

Start operations of the Analog Comparator.

Once the Analog Comparator is started, you can possibly poll its output anytime with output().

Note that this method is synchronized, i.e. it disables all interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use begin_() instead.

Template Parameters
INPUT1which board::AnalogPin is used as comparator negative input; if board::AnalogPin::NONE (the default), then AIN1 pin will be used, instead of any analog input pin. If the target MCU does not support AIN1 or the provided AnalogPin, compilation will fail with an explicit assertion error.
INPUT0_BANDGAPif true, then use bandgap reference voltage (typically 1.1V) as comparator positive input, instead of AIN0 pin; if false, AIN0 pin will be used. If the target MCU has no AIN0 pin, and INPUT0_BANDGAP is false, compilation will fail with an explicit assertion error.
Parameters
modethe interrupt mode to enable for the Analog Comparator; if not ComparatorInterrupt::NONE, then the proper ISR shall have been properly registered with one of the provided macros.
trigger_icpif true, then the Analog Comparator output is wired to the Input Capture of a Timer (which one depends on the MCU target). Note that some MCU do not support Input Capture, hence this flag will be left unused for these.
See also
end()
output()
begin_()
REGISTER_ANALOG_COMPARE_ISR_FUNCTION()
REGISTER_ANALOG_COMPARE_ISR_METHOD()
REGISTER_ANALOG_COMPARE_ISR_EMPTY()

Definition at line 162 of file analog_comparator.h.

◆ end()

void analog::AnalogComparator::end ( )
inline

Stop operations of the Analog Comparator.

This also disables any related interrupts.

Note that this method is synchronized, i.e. it disables all interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use end_() instead.

See also
end_()
begin()

Definition at line 179 of file analog_comparator.h.

◆ output()

bool analog::AnalogComparator::output ( ) const
inline

Get current output of Analog Comparator.

Return values
trueif Analog Comparator output is 1 (when +input is greater than -input).
falseif Analog Comparator output is 0 (when +input is less than -input).
See also
begin()

Definition at line 192 of file analog_comparator.h.

◆ begin_()

template<board::AnalogPin INPUT1 = board::AnalogPin::NONE, bool INPUT0_BANDGAP = false>
void analog::AnalogComparator::begin_ ( ComparatorInterrupt  mode = ComparatorInterrupt::NONE,
bool  trigger_icp = false 
)
inline

Start operations of the Analog Comparator.

Once the Analog Comparator is started, you can possibly poll its output anytime with output().

Note that this method is not synchronized, hence you should ensure it is called only while global interrupts are not enabled. If you need synchronization, then you should better use begin() instead.

Template Parameters
INPUT1which board::AnalogPin is used as comparator negative input; if board::AnalogPin::NONE (the default), then AIN1 pin will be used, instead of any analog input pin. If the target MCU does not support AIN1 or the provided AnalogPin, compilation will fail with an explicit assertion error.
INPUT0_BANDGAPif true, then use bandgap reference voltage (typically 1.1V) as comparator positive input, instead of AIN0 pin; if false, AIN0 pin will be used. If the target MCU has no AIN0 pin, and INPUT0_BANDGAP is false, compilation will fail with an explicit assertion error.
Parameters
modethe interrupt mode to enable for the Analog Comparator; if not ComparatorInterrupt::NONE, then the proper ISR shall have been properly registered with one of the provided macros.
trigger_icpif true, then the Analog Comparator output is wired to the Input Capture of a Timer (which one depends on the MCU target). Note that some MCU do not support Input Capture, hence this flag will be left unused for these.
See also
end_()
output()
begin()
REGISTER_ANALOG_COMPARE_ISR_FUNCTION()
REGISTER_ANALOG_COMPARE_ISR_METHOD()
REGISTER_ANALOG_COMPARE_ISR_EMPTY()

Definition at line 232 of file analog_comparator.h.

◆ end_()

void analog::AnalogComparator::end_ ( )
inline

Stop operations of the Analog Comparator.

This also disables any related interrupts.

Note that this method is not synchronized, hence you should ensure it is called only while global interrupts are not enabled. If you need synchronization, then you should better use end() instead.

See also
begin_()
end()

Definition at line 259 of file analog_comparator.h.


The documentation for this class was generated from the following file: