Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM3S/4E/4S/V71/V70/S70/E70 Analog Comparator Controller (ACC) Driver

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:

Prerequisites

There are no prerequisites for this module.

Module Overview

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.

Special Considerations

Configuration Changes

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:

* while ((acc_get_interrupt_status(ACC) & ACC_ISR_MASK) == ACC_ISR_MASK) {
* }

I/O Lines

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.

Power Management

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.

Note
The voltage regulator must be activated before the Analog Comparator module is used.

Interrupt

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.

Fault Output

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.

Extra Information

For extra information, see Extra Information for Analog Comparator Controller. This includes:

Examples

For a list of examples related to this driver, see Examples for Analog Comparator Controller.

API Overview

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.

Parameters
[in,out]p_accModule hardware register base address pointer

References Assert.

Referenced by re200b_motion_detect_disable().

void acc_disable_interrupt ( Acc *  p_acc)

Disable the ACC comparison edge interrupt.

Parameters
[out]p_accModule hardware register base address pointer

References Assert.

Referenced by re200b_motion_detect_disable().

void acc_enable ( Acc *  p_acc)

Enable the ACC module.

Parameters
[in,out]p_accModule hardware register base address pointer

References Assert.

Referenced by re200b_motion_detect_enable().

void acc_enable_interrupt ( Acc *  p_acc)

Enable the ACC comparison edge interrupt.

Parameters
[out]p_accModule hardware register base address pointer

References Assert.

Referenced by main(), and re200b_motion_detect_enable().

uint32_t acc_get_comparison_result ( Acc *  p_acc)

Get the ACC comparison result.

Parameters
[in]p_accModule hardware register base address pointer
Returns
The ACC comparison result.
Return values
0Comparator minus input is greater than its plus input (inn>inp)
1Comparator plus input is greater than its minus input (inp>inn)

References Assert.

Referenced by re200b_motion_detect_handler().

uint32_t acc_get_interrupt_status ( Acc *  p_acc)

Get the ACC comparison edge interrupt status.

Parameters
[in]p_accModule hardware register base address pointer
Returns
The ACC comparison edge interrupt status.

References Assert.

Referenced by main(), re200b_motion_detect_handler(), and re200b_motion_detect_init().

uint32_t acc_get_writeprotect_status ( Acc *  p_acc)

Get the ACC register write-protection status.

Parameters
[in]p_accModule hardware register base address pointer
Returns
The ACC register write-protection status.
Return values
0No write-protection error
ACC_WPSR_WPROTERRWrite-protection error

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.

Note
This function performs a software reset on the ACC module prior to its initialization.
Parameters
[in,out]p_accModule hardware register base address pointer
[in]ul_select_plusSelection for the plus comparator input (inp)
[in]ul_select_minusSelection for the minus comparator input (inn)
[in]ul_edge_typeComparison flag triggering mode
[in]ul_invertInvert the comparator output mode

Where the input parameter ul_select_plus is one of the following:

Parameter Value Description
ACC_MR_SELPLUS_AD0Select AD0 as the plus input
ACC_MR_SELPLUS_AD1Select AD1 as the plus input
ACC_MR_SELPLUS_AD2Select AD2 as the plus input
ACC_MR_SELPLUS_AD3Select AD3 as the plus input
ACC_MR_SELPLUS_AD4Select AD4 as the plus input
ACC_MR_SELPLUS_AD5Select AD5 as the plus input
ACC_MR_SELPLUS_AD6Select AD6 as the plus input
ACC_MR_SELPLUS_AD7Select AD7 as the plus input

Where the input parameter ul_select_minus is one of the following:

Parameter Value Description
ACC_MR_SELMINUS_TSSelect TS as the minus input
ACC_MR_SELMINUS_ADVREFSelect ADVREF as the minus input
ACC_MR_SELMINUS_DAC0Select DAC0 as the minus input
ACC_MR_SELMINUS_DAC1Select DAC1 as the minus input
ACC_MR_SELMINUS_AD0Select AD0 as the minus input
ACC_MR_SELMINUS_AD1Select AD1 as the minus input
ACC_MR_SELMINUS_AD2Select AD2 as the minus input
ACC_MR_SELMINUS_AD3Select AD3 as the minus input

Where the input parameter ul_edge_type is one of the following:

Parameter Value Description
ACC_MR_EDGETYP_RISINGRising edge of comparator output
ACC_MR_EDGETYP_FALLINGFalling edge of comparator output
ACC_MR_EDGETYP_ANYAny edge of comparator output

Where the input parameter ul_invert is one of the following:

Parameter Value Description
ACC_MR_INV_DISComparator output is directly processed
ACC_MR_INV_ENComparator output is inverted prior to being processed

References ACC_ACR_HYST_50mv_max, and Assert.

Referenced by main(), and re200b_motion_detect_init().

void acc_reset ( Acc *  p_acc)

Software reset the ACC module.

Parameters
[out]p_accModule 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.

Parameters
[in,out]p_accModule hardware register base address pointer
[in]ul_select_minusSelection for the minus comparator input (inn)
[in]ul_select_plusSelection for the plus comparator input (inp)

Where the input parameter ul_select_minus is one of the following:

Parameter Value Description
ACC_MR_SELMINUS_TSSelect TS as the minus input
ACC_MR_SELMINUS_ADVREFSelect ADVREF as the minus input
ACC_MR_SELMINUS_DAC0Select DAC0 as the minus input
ACC_MR_SELMINUS_DAC1Select DAC1 as the minus input
ACC_MR_SELMINUS_AD0Select AD0 as the minus input
ACC_MR_SELMINUS_AD1Select AD1 as the minus input
ACC_MR_SELMINUS_AD2Select AD2 as the minus input
ACC_MR_SELMINUS_AD3Select AD3 as the minus input

Where the input parameter ul_select_plus is one of the following:

Parameter Value Description
ACC_MR_SELPLUS_AD0Select AD0 as the plus input
ACC_MR_SELPLUS_AD1Select AD1 as the plus input
ACC_MR_SELPLUS_AD2Select AD2 as the plus input
ACC_MR_SELPLUS_AD3Select AD3 as the plus input
ACC_MR_SELPLUS_AD4Select AD4 as the plus input
ACC_MR_SELPLUS_AD5Select AD5 as the plus input
ACC_MR_SELPLUS_AD6Select AD6 as the plus input
ACC_MR_SELPLUS_AD7Select 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.

Parameters
[in,out]p_accModule hardware register base address pointer
[in]ul_invertInvert comparator output
[in]ul_fault_enableFault enable
[in]ul_fault_sourceSelection of fault source

Where the input parameter ul_invert is one of the following:

Parameter Value Description
ACC_MR_INV_DISComparator output is directly processed
ACC_MR_INV_ENComparator 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_DISThe FAULT output is tied to 0
ACC_MR_FE_ENThe 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_CFThe CF flag is used to drive the FAULT output
ACC_MR_SELFS_OUTPUTThe 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.

Parameters
[out]p_accModule hardware register base address pointer
[in]ul_enable1 to enable, 0 to disable

References ACC_WPMR_WPKEY_PASSWD, and Assert.