1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
30 /** \addtogroup acc_module Working with ACC
\r
31 * \ingroup peripherals_module
\r
32 * The ACC driver provides the interface to configure and use the ACC peripheral.\n
\r
34 * It applies comparison on two inputs and gives a compare output.
\r
36 * To Enable a ACC Comparison,the user has to follow these few steps:
\r
38 * <li> Enable ACC peripheral clock by setting the corresponding bit in PMC_PCER1
\r
39 * (PMC Peripheral Clock Enable Register 1)
\r
41 * <li> Reset the controller by asserting ACC_CR_SWRST in ACC_CR(ACC Control Register)
\r
43 * <li> Configure the mode as following steps: </li>
\r
44 * -# Select inputs for SELMINUS and SELPLUS in ACC_MR (ACC Mode Register).
\r
45 * -# Enable Analog Comparator by setting ACEN in ACC_MR.
\r
46 * -# Configure Edge Type to detect different compare output.
\r
48 * <li> Wait until the automatic mask period expires by polling MASK bit in
\r
52 * For more accurate information, please look at the ACC section of the
\r
64 * Implementation of Analog Comparator Controller (ACC).
\r
67 /*----------------------------------------------------------------------------
\r
69 *----------------------------------------------------------------------------*/
\r
73 /*----------------------------------------------------------------------------
\r
74 * Exported functions
\r
75 *----------------------------------------------------------------------------*/
\r
78 * \brief Initialize the ACC controller
\r
80 * \param pAcc Pointer to an Acc instance.
\r
81 * \param idAcc ACC identifier
\r
82 * \param ucSelplus input connected to inp, 0~7
\r
83 * \param ucSelminus input connected to inm,0~7
\r
84 * \param wAc_en Analog comprator enabled/disabled
\r
85 * \param wEdge CF flag triggering mode
\r
86 * \param wInvert INVert comparator output,use pattern defined in the device header file
\r
88 extern void ACC_Configure( Acc *pAcc, uint8_t idAcc, uint8_t ucSelplus, uint8_t ucSelminus,
\r
89 uint16_t wAc_en, uint16_t wEdge, uint16_t wInvert )
\r
91 /* Enable peripheral clock*/
\r
92 PMC->PMC_PCER1 = 1 << (idAcc - 32) ;
\r
94 /* Reset the controller */
\r
95 pAcc->ACC_CR |= ACC_CR_SWRST ;
\r
97 /* Write to the MR register */
\r
98 ACC_CfgModeReg( pAcc,
\r
99 ( (ucSelplus<<ACC_MR_SELPLUS_Pos) & ACC_MR_SELPLUS_Msk ) |
\r
100 ( (ucSelminus<<ACC_MR_SELMINUS_Pos) & ACC_MR_SELMINUS_Msk ) |
\r
101 ( (wAc_en<<8) & ACC_MR_ACEN ) |
\r
102 ( (wEdge<<ACC_MR_EDGETYP_Pos) & ACC_MR_EDGETYP_Msk ) |
\r
103 ( (wInvert<<12) & ACC_MR_INV ) ) ;
\r
104 /* set hysteresis and current option*/
\r
105 pAcc->ACC_ACR = (ACC_ACR_ISEL_HISP | ((0x01 << ACC_ACR_HYST_Pos) & ACC_ACR_HYST_Msk));
\r
107 /* Automatic Output Masking Period*/
\r
108 while ( pAcc->ACC_ISR & (uint32_t)ACC_ISR_MASK ) ;
\r
112 * Return the Channel Converted Data
\r
113 * \param pAcc Pointer to an Acc instance.
\r
114 * \param selplus input applied on ACC SELPLUS
\r
115 * \param selminus input applied on ACC SELMINUS
\r
117 extern void ACC_SetComparisonPair( Acc *pAcc, uint8_t ucSelplus, uint8_t ucSelminus )
\r
121 assert( ucSelplus < 8 && ucSelminus < 8 ) ;
\r
123 dwTemp = pAcc->ACC_MR ;
\r
125 pAcc->ACC_MR = dwTemp & (uint32_t) ((~ACC_MR_SELMINUS_Msk) & (~ACC_MR_SELPLUS_Msk));
\r
127 pAcc->ACC_MR |= ( ((ucSelplus << ACC_MR_SELPLUS_Pos) & ACC_MR_SELPLUS_Msk) |
\r
128 ((ucSelminus << ACC_MR_SELMINUS_Pos) & ACC_MR_SELMINUS_Msk) ) ;
\r
132 * Return Comparison Result
\r
133 * \param pAcc Pointer to an Acc instance.
\r
134 * \param status value of ACC_ISR
\r
136 extern uint32_t ACC_GetComparisonResult( Acc *pAcc, uint32_t dwStatus )
\r
138 uint32_t dwTemp = pAcc->ACC_MR ;
\r
140 if ( (dwTemp & ACC_MR_INV) == ACC_MR_INV )
\r
142 if ( dwStatus & ACC_ISR_SCO )
\r
144 return 0 ; /* inn>inp*/
\r
148 return 1 ;/* inp>inn*/
\r
153 if ( dwStatus & ACC_ISR_SCO )
\r
155 return 1 ; /* inp>inn*/
\r
159 return 0 ;/* inn>inp*/
\r