[Yatli AT32F421 Review] Rock-Paper-Scissors - Comparator
[Copy link]
Unlike other domestic alternatives, Arteli designers added a rail-to-rail comparator, programmable reference voltage (internal or external), hysteresis and speed, selectable output polarity, blanking output function and interference filter.
For example, it can be used to monitor analog voltage to exit low power mode to save energy (such as sensors, where the voltage is below a certain point and no processing is required). Analog voltage can be converted to digital level, etc. Of course, it can also be used as an ordinary comparator. The integrated type also saves material cost and PCB space. The price does not increase with the increase in quantity.
It can be seen that the analog part of the same direction input can be GNDA and PA0,1,5. GPIO input, the reverse direction can be GPIOA0,2,4,5, or 1/4,2/4,3/4,4/4 of the reference voltage.
Then the output is given to the digital part, after the blanker, according to our configuration, the output can be flipped or not. The following can be given to GPIO, interrupt line or timer.
There is a switch that can be connected to the same and reverse directions. I don't quite understand why this switch is used.
Let's take a look at the configuration structure members of the comparator.
/**
* [url=home.php?mod=space&uid=159083]@brief[/url] COMP Init structure definition
*/
typedef struct
{
uint32_t COMP_INMInput; /*!< 比较器的反相输入.
参数 [url=home.php?mod=space&uid=1064992]@ref[/url] COMP_INMInput */
uint32_t COMP_Output; /*!< 比较器的输出重定向.
参数 @ref COMP_Output */
uint32_t COMP_OutPolarity; /*!< 比较器的输出极性.
参数 @ref COMP_OutputPolarity */
uint32_t COMP_Hysteresis; /*!< 比较器的迟滞电压.
参数 @ref COMP_Hysteresis */
uint32_t COMP_Mode; /*!< 选择比较器的工作模式并允许调整速度/消耗.
参数 @ref COMP_Mode */
}COMP_InitType;
Member optional parameters
/** @defgroup COMP_输出
* @{
*/
#define COMP_Output_None ((uint32_t)0x00000000) /*!< COMP 输出不连接到外设 */
#ifdef AT32F421xx
#define COMP_Output_TMR1BKIN ((uint32_t)0x00000400) /*!< COMP 输出连接到 TIM1 中断输入 (BKIN) */
#define COMP_Output_TMR1IC1 ((uint32_t)0x00000800) /*!< COMP 输出连接到 TIM1 输入捕捉 1 */
#define COMP_Output_TMR1OCREFCLR ((uint32_t)0x00000C00) /*!< COMP 输出连接到 TIM1 OCREF 清除 */
#define COMP_Output_TMR3IC1 ((uint32_t)0x00001800) /*!< COMP 输出连接到 TIM3 输入捕捉 1 */
#define COMP_Output_TMR3OCREFCLR ((uint32_t)0x00001C00) /*!< COMP 输出连接到 TIM3 OCREF 清除 */
/** @defgroup COMP_反相输入
* @{
*/
#define COMP_INMInput_1_4VREFINT ((uint32_t)0x00000000) /*!< 1/4 VREFINT */
#define COMP_INMInput_1_2VREFINT ((uint32_t)0x00000010) /*!< 1/2 VREFINT */
#define COMP_INMInput_3_4VREFINT ((uint32_t)0x00000020) /*!< 3/4 VREFINT */
#define COMP_INMInput_VREFINT ((uint32_t)0x00000030) /*!< VREFINT */
#define COMP_INMInput_IN1 ((uint32_t)0x00000040) /*!< A4 */
#define COMP_INMInput_IN2 ((uint32_t)0x00000050) /*!< PA5 */
#define COMP_INMInput_IN3 ((uint32_t)0x00000060) /*!< PA0 */
#define COMP_INMInput_IN4 ((uint32_t)0x00000070) /*!< PA2 */
/** @defgroup COMP_同向输入
* @{
*/
#define COMP_INPInput_00 ((uint32_t)0x00000000) /*!< PA5 */
#define COMP_INPInput_01 ((uint32_t)0x00000080) /*!< PA1 */
#define COMP_INPInput_10 ((uint32_t)0x00000100) /*!< PA0 */
#define COMP_INPInput_11 ((uint32_t)0x00000180) /*!< VSSA */
/** @defgroup COMP_输出极性
* @{
*/
#define COMP_OutPolarity_NonInverted ((uint32_t)0x00000000) /*!< 不翻转GPIO上的输出 */
#define COMP_OutPolarity_Inverted COMP_CTRLSTS_COMP1POL /*!< 翻转GPIO上的输出*/
/** @defgroup COMP_迟滞
* @{
*/
#define COMP_Hysteresis_No ((uint32_t)0x00000000) /*!< 无滞后 */
#define COMP_Hysteresis_Low COMP_CTRLSTS_COMP1HYST_0 /*!< 滞后低*/
#define COMP_Hysteresis_Medium COMP_CTRLSTS_COMP1HYST_1 /*!< 滞后中 */
#define COMP_Hysteresis_High COMP_CTRLSTS_COMP1HYST /*!< 滞后高 */
/** @defgroup COMP_模式
* @{
*/
#define COMP_Mode_Fast ((uint32_t)0x00000000) /*!< 高速/高功耗 */
#define COMP_Mode_Medium COMP_CTRLSTS_COMP1MDE_0 /*!< 中速/总功耗 */
#define COMP_Mode_Slow COMP_CTRLSTS_COMP1MDE_1 /*!< 低速/低功耗 */
#define COMP_Mode_Very_Slow COMP_CTRLSTS_COMP1MDE /*!< 超低速/超低功耗 */
The library also provides us with some functions to call
/* 基本的重置,默认值,初始化****/
void COMP_Reset(void);
void COMP_StructInit(COMP_InitType* COMP_InitStruct);
void COMP_Init(uint32_t COMP_Selection, COMP_InitType* COMP_InitStruct);
/* Initialization and Configuration functions *********************************/
// COMP1 设置同相输入。
void COMP_SelectINPInput(uint32_t COMP_Selection, uint32_t COMP_INPInput);
//使能外设
void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState);
//控制同反向跨接开关的
void COMP_SwitchCmd(FunctionalState NewState);
//获取比较器输出电平
uint32_t COMP_GetOutputState(uint32_t COMP_Selection);
/* 配置锁定功能****************************************/
void COMP_LockConfig(uint32_t COMP_Selection);
#ifdef AT32F421xx
/* 配置消隐过滤器 ****************************************/
void COMP_FilterConfig(uint16_t COMP_HighPulseCnt, uint16_t COMP_LowPulseCnt, FunctionalState NewState);
/* 配置 COMP 消隐源****************************************/
void COMP_BlankingConfig(uint32_t Blank_Selection);
/* COMP 配置内部电压桥。****************************************/
void COMP_SCAL_BRGConfig(uint32_t SCAL_BRG);
Personally, I think it would be better to equip it with a PGA (programmable operational amplifier).
|