This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Analog Comparator Controller functionality.
The Analog Comparator compares two voltages, and the result of this comparison gives a compare output. The user application can select whether to use a high-speed or a low-power option as well as selecting the hysteresis level, edge detection, and polarity.
Devices from the following series can use this module:
The outline of this documentation is as follows:
There are no prerequisites for this module.
The Analog Comparator Controller configures the Analog Comparator, and generates an interrupt according to the user application's settings. The analog comparator embeds 8 to 1 multiplexers on both its plus and minus inputs.
The Analog Comparator compares two voltages, and the result of this comparison gives a compare output and an interrupt can be generated accordingly. The user application can select a high-speed or low-power option, the hysteresis level, edge detection, and polarity.
The ACC can also generate a comparison event that can be used by the Pulse Width Modulation (PWM) module.
As soon as the analog comparator settings are modified, the output of the analog comparator is masked for the time that its output may be invalid. Depending on the user application the following function calls may require the comparator output to be valid before continuing:
The following code may be used to check if the comparator output is valid before continuing:
The analog input pins (AD0-AD7 and DAC0-1) are multiplexed with general-purpose input/output (GPIO) lines. The assignment of these pins to ACC module inputs is automatically done when the corresponding input is assigned to the comparator's plus/minus inputs by the user application performing a write to the module's Mode Register.
The ACC module is clocked through the Power Management Controller (PMC), thus the user application must first configure the PMC, in order to enable the Analog Comparator Controller clock.
The ACC module has an interrupt line connected to the Nested Vectored Interrupt Controller (NVIC). Handling the ACC interrupt requires that the NVIC is configured before configuring the ACC.
The ACC module has a FAULT output that is connected to the FAULT input of the PWM module. Refer to "fault mode" and the implementation of the PWM in the device-specific datasheet.
For extra information, see Extra Information for Analog Comparator Controller. This includes:
For a list of examples related to this driver, see Examples for Analog Comparator Controller.
Functions | |
void | acc_disable (Acc *p_acc) |
Disable the ACC module. More... | |
void | acc_disable_interrupt (Acc *p_acc) |
Disable the ACC comparison edge interrupt. More... | |
void | acc_enable (Acc *p_acc) |
Enable the ACC module. More... | |
void | acc_enable_interrupt (Acc *p_acc) |
Enable the ACC comparison edge interrupt. More... | |
uint32_t | acc_get_comparison_result (Acc *p_acc) |
Get the ACC comparison result. More... | |
uint32_t | acc_get_interrupt_status (Acc *p_acc) |
Get the ACC comparison edge interrupt status. More... | |
uint32_t | acc_get_writeprotect_status (Acc *p_acc) |
Get the ACC register write-protection status. More... | |
void | acc_init (Acc *p_acc, uint32_t ul_select_plus, uint32_t ul_select_minus, uint32_t ul_edge_type, uint32_t ul_invert) |
Initialize the ACC module. More... | |
void | acc_reset (Acc *p_acc) |
Software reset the ACC module. More... | |
void | acc_set_input (Acc *p_acc, uint32_t ul_select_minus, uint32_t ul_select_plus) |
Set the ACC comparator plus/minus input sources. More... | |
void | acc_set_output (Acc *p_acc, uint32_t ul_invert, uint32_t ul_fault_enable, uint32_t ul_fault_source) |
Set the ACC output. More... | |
void | acc_set_writeprotect (Acc *p_acc, uint32_t ul_enable) |
Set the ACC register write-protection. More... | |
Hysteresis Levels | |
Refer to the "Analog Comparator Characteristics" table in the "Electrical Characteristics" chapter of the device-specific datasheet. | |
#define | ACC_ACR_HYST_0mv_max 0x00 |
#define | ACC_ACR_HYST_50mv_max 0x01 |
#define | ACC_ACR_HYST_90mv_max 0x11 |
#define ACC_ACR_HYST_0mv_max 0x00 |
#define ACC_ACR_HYST_50mv_max 0x01 |
Referenced by acc_init().
#define ACC_ACR_HYST_90mv_max 0x11 |
void acc_disable | ( | Acc * | p_acc | ) |
Disable the ACC module.
[in,out] | p_acc | Module hardware register base address pointer |
References Assert.
void acc_disable_interrupt | ( | Acc * | p_acc | ) |
Disable the ACC comparison edge interrupt.
[out] | p_acc | Module hardware register base address pointer |
References Assert.
void acc_enable | ( | Acc * | p_acc | ) |
Enable the ACC module.
[in,out] | p_acc | Module hardware register base address pointer |
References Assert.
void acc_enable_interrupt | ( | Acc * | p_acc | ) |
uint32_t acc_get_comparison_result | ( | Acc * | p_acc | ) |
Get the ACC comparison result.
[in] | p_acc | Module hardware register base address pointer |
0 | Comparator minus input is greater than its plus input (inn>inp) |
1 | Comparator plus input is greater than its minus input (inp>inn) |
References Assert.
Referenced by ACC_Handler().
uint32_t acc_get_interrupt_status | ( | Acc * | p_acc | ) |
Get the ACC comparison edge interrupt status.
[in] | p_acc | Module hardware register base address pointer |
References Assert.
Referenced by ACC_Handler().
uint32_t acc_get_writeprotect_status | ( | Acc * | p_acc | ) |
Get the ACC register write-protection status.
[in] | p_acc | Module hardware register base address pointer |
0 | No write-protection violation occurred |
ACC_WPSR_WPVS | Write-protection violation (WPEN = 1) has occurred since the last read of ACC_WPSR |
References Assert.
void acc_init | ( | Acc * | p_acc, |
uint32_t | ul_select_plus, | ||
uint32_t | ul_select_minus, | ||
uint32_t | ul_edge_type, | ||
uint32_t | ul_invert | ||
) |
Initialize the ACC module.
[in,out] | p_acc | Module hardware register base address pointer |
[in] | ul_select_plus | Selection for the plus comparator input (inp) |
[in] | ul_select_minus | Selection for the minus comparator input (inn) |
[in] | ul_edge_type | Comparison flag triggering mode |
[in] | ul_invert | Invert the comparator output mode |
Where the input parameter ul_select_plus is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_SELPLUS_AD0 | Select AD0 as the plus input |
ACC_MR_SELPLUS_AD1 | Select AD1 as the plus input |
ACC_MR_SELPLUS_AD2 | Select AD2 as the plus input |
ACC_MR_SELPLUS_AD3 | Select AD3 as the plus input |
ACC_MR_SELPLUS_AD4 | Select AD4 as the plus input |
ACC_MR_SELPLUS_AD5 | Select AD5 as the plus input |
ACC_MR_SELPLUS_AD6 | Select AD6 as the plus input |
ACC_MR_SELPLUS_AD7 | Select AD7 as the plus input |
Where the input parameter ul_select_minus is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_SELMINUS_TS | Select TS as the minus input |
ACC_MR_SELMINUS_ADVREF | Select ADVREF as the minus input |
ACC_MR_SELMINUS_DAC0 | Select DAC0 as the minus input |
ACC_MR_SELMINUS_DAC1 | Select DAC1 as the minus input |
ACC_MR_SELMINUS_AD0 | Select AD0 as the minus input |
ACC_MR_SELMINUS_AD1 | Select AD1 as the minus input |
ACC_MR_SELMINUS_AD2 | Select AD2 as the minus input |
ACC_MR_SELMINUS_AD3 | Select AD3 as the minus input |
Where the input parameter ul_edge_type is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_EDGETYP_RISING | Rising edge of comparator output |
ACC_MR_EDGETYP_FALLING | Falling edge of comparator output |
ACC_MR_EDGETYP_ANY | Any edge of comparator output |
Where the input parameter ul_invert is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_INV_DIS | Comparator output is directly processed |
ACC_MR_INV_EN | Comparator output is inverted prior to being processed |
References ACC_ACR_HYST_50mv_max, and Assert.
Referenced by main().
void acc_reset | ( | Acc * | p_acc | ) |
Software reset the ACC module.
[out] | p_acc | Module hardware register base address pointer |
References Assert.
void acc_set_input | ( | Acc * | p_acc, |
uint32_t | ul_select_minus, | ||
uint32_t | ul_select_plus | ||
) |
Set the ACC comparator plus/minus input sources.
[in,out] | p_acc | Module hardware register base address pointer |
[in] | ul_select_minus | Selection for the minus comparator input (inn) |
[in] | ul_select_plus | Selection for the plus comparator input (inp) |
Where the input parameter ul_select_minus is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_SELMINUS_TS | Select TS as the minus input |
ACC_MR_SELMINUS_ADVREF | Select ADVREF as the minus input |
ACC_MR_SELMINUS_DAC0 | Select DAC0 as the minus input |
ACC_MR_SELMINUS_DAC1 | Select DAC1 as the minus input |
ACC_MR_SELMINUS_AD0 | Select AD0 as the minus input |
ACC_MR_SELMINUS_AD1 | Select AD1 as the minus input |
ACC_MR_SELMINUS_AD2 | Select AD2 as the minus input |
ACC_MR_SELMINUS_AD3 | Select AD3 as the minus input |
Where the input parameter ul_select_plus is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_SELPLUS_AD0 | Select AD0 as the plus input |
ACC_MR_SELPLUS_AD1 | Select AD1 as the plus input |
ACC_MR_SELPLUS_AD2 | Select AD2 as the plus input |
ACC_MR_SELPLUS_AD3 | Select AD3 as the plus input |
ACC_MR_SELPLUS_AD4 | Select AD4 as the plus input |
ACC_MR_SELPLUS_AD5 | Select AD5 as the plus input |
ACC_MR_SELPLUS_AD6 | Select AD6 as the plus input |
ACC_MR_SELPLUS_AD7 | Select AD7 as the plus input |
References Assert.
void acc_set_output | ( | Acc * | p_acc, |
uint32_t | ul_invert, | ||
uint32_t | ul_fault_enable, | ||
uint32_t | ul_fault_source | ||
) |
Set the ACC output.
[in,out] | p_acc | Module hardware register base address pointer |
[in] | ul_invert | Invert comparator output |
[in] | ul_fault_enable | Fault enable |
[in] | ul_fault_source | Selection of fault source |
Where the input parameter ul_invert is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_INV_DIS | Comparator output is directly processed |
ACC_MR_INV_EN | Comparator output is inverted prior to being processed |
Where the input parameter ul_fault_enable is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_FE_DIS | The FAULT output is tied to 0 |
ACC_MR_FE_EN | The FAULT output is driven by ul_fault_source |
Where the input parameter ul_fault_source is one of the following:
Parameter Value | Description |
---|---|
ACC_MR_SELFS_CF | The CF flag is used to drive the FAULT output |
ACC_MR_SELFS_OUTPUT | The output of the Analog Comparator flag is used to drive the FAULT output |
References Assert.
void acc_set_writeprotect | ( | Acc * | p_acc, |
uint32_t | ul_enable | ||
) |
Set the ACC register write-protection.
[out] | p_acc | Module hardware register base address pointer |
[in] | ul_enable | 1 to enable, 0 to disable |
References ACC_WPMR_WPKEY_PASSWD, and Assert.