FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
Handler of the Analog Comparator feature. More...
#include <fastarduino/analog_comparator.h>
Public Member Functions | |
AnalogComparator (const AnalogComparator &)=delete | |
AnalogComparator & | operator= (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... | |
Handler of the Analog Comparator feature.
Only one instance is needed for all related operations.
Usage is simple:
begin()
; interrupts may then be generated, depending on given aruments.output()
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.
Definition at line 116 of file analog_comparator.h.
|
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.
INPUT1 | which 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_BANDGAP | if 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. |
mode | the 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_icp | if 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. |
Definition at line 162 of file analog_comparator.h.
|
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.
Definition at line 179 of file analog_comparator.h.
|
inline |
Get current output of Analog Comparator.
true | if Analog Comparator output is 1 (when +input is greater than -input). |
false | if Analog Comparator output is 0 (when +input is less than -input). |
Definition at line 192 of file analog_comparator.h.
|
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.
INPUT1 | which 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_BANDGAP | if 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. |
mode | the 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_icp | if 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. |
Definition at line 232 of file analog_comparator.h.
|
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.
Definition at line 259 of file analog_comparator.h.