Xmega Application Note


ac_driver.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00066 #include "ac_driver.h"
00067 
00076 void AC_Enable(AC_t * ac, AC_COMP_t comp, bool highSpeed)
00077 {
00078         /* Access correct registers based on which comparator submodule indicated. */
00079         if(comp == 0){
00080                 ac->AC0CTRL = (ac->AC0CTRL & ~AC_HSMODE_bm)|
00081                               (AC_ENABLE_bm | (highSpeed ? AC_HSMODE_bm : 0));
00082         }else{
00083                 ac->AC1CTRL = (ac->AC1CTRL & ~AC_HSMODE_bm)|
00084                                   (AC_ENABLE_bm | (highSpeed ? AC_HSMODE_bm : 0));
00085         }
00086 }
00087 
00095 void AC_Disable(AC_t * ac, AC_COMP_t comp)
00096 {
00097         /* Access correct registers based on which comparator submodule indicated. */
00098         if(comp == 0){
00099                 ac->AC0CTRL &= ~AC_ENABLE_bm;
00100         }else{
00101                 ac->AC1CTRL &= ~AC_ENABLE_bm;
00102         }
00103 }
00104 
00105 
00115 void AC_ConfigInterrupt(AC_t * ac, AC_COMP_t comp, AC_INTMODE_t interruptMode,
00116                                                 AC_INTLVL_t interruptLevel)
00117 {
00118         /* Access correct registers based on which comparator submodule indicated. */
00119         if(comp == 0){
00120                 ac->AC0CTRL = (ac->AC0CTRL & ~(AC_INTMODE_gm | AC_INTLVL_gm))|
00121                               ((uint8_t) interruptMode | interruptLevel);
00122         }else{
00123                 ac->AC1CTRL = (ac->AC1CTRL & ~(AC_INTMODE_gm | AC_INTLVL_gm)) |
00124                                   ((uint8_t) interruptMode | interruptLevel);
00125         }
00126 }
00127 
00128 
00137 void AC_ConfigHysteresis(AC_t * ac, AC_COMP_t comp, AC_HYSMODE_t hysteresisMode)
00138 {
00139         /* Access correct registers based on which comparator submodule indicated. */
00140         if(comp == 0){
00141                 ac->AC0CTRL = (ac->AC0CTRL & ~AC_HYSMODE_gm) | hysteresisMode;
00142         }else{
00143                 ac->AC1CTRL = (ac->AC1CTRL & ~AC_HYSMODE_gm) | hysteresisMode;
00144         }
00145 }
00146 
00156 void AC_ConfigMUX(AC_t * ac, AC_COMP_t comp, AC_MUXPOS_t pos, AC_MUXNEG_t neg)
00157 {
00158         /* Access correct registers based on which comparator submodule indicated. */
00159         if(comp == 0){
00160                 ac->AC0MUXCTRL = (ac->AC0MUXCTRL & ~(AC_MUXPOS_gm | AC_MUXNEG_gm)) |
00161                                  ((uint8_t) pos | neg);
00162         }else{
00163                 ac->AC1MUXCTRL = (ac->AC1MUXCTRL & ~(AC_MUXPOS_gm | AC_MUXNEG_gm)) |
00164                                      ((uint8_t) pos | neg);
00165         }
00166 }
00167 
00168 
00178 void AC_ConfigVoltageScaler(AC_t * ac, uint8_t scaleFactor)
00179 {
00180         /* Scale factor gets truncated to bit field size. */
00181         ac->CTRLB = (ac->CTRLB & ~AC_SCALEFAC_gm) |
00182                     ((scaleFactor << AC_SCALEFAC_bp) & AC_SCALEFAC_gm);
00183 }
00184 
00185 
00198 void AC_EnableWindowMode(AC_t * ac, AC_WINTMODE_t interruptMode,
00199                          AC_WINTLVL_t interruptLevel)
00200 {
00201         ac->WINCTRL = (ac->WINCTRL & ~(AC_WINTMODE_gm | AC_WINTLVL_gm)) |
00202                       (AC_WEN_bm | interruptMode | interruptLevel);
00203 }
00204 
00205 
00210 void AC_DisableWindowMode(AC_t * ac)
00211 {
00212         ac->WINCTRL = ~AC_WEN_bm;
00213 }
00214 
00215 
00220 void AC_EnableComparator0_Output(AC_t * ac)
00221 {
00222         ac->CTRLA |= AC_AC0OUT_bm;
00223 }
00224 
00225 
00230 void AC_DisableComparator0_Output(AC_t * ac)
00231 {
00232         ac->CTRLA &= ~AC_AC0OUT_bm;
00233 }
00234 
00235 
00245 uint8_t AC_GetComparatorState(AC_t * ac, AC_COMP_t comp)
00246 {
00247         uint8_t state = 0;
00248 
00249         /* Access correct bits based on which comparator submodule indicated. */
00250         if(comp == 0){
00251                 state = ac->STATUS & AC_AC0STATE_bm;
00252         }else if(comp == 1){
00253                 state = ac->STATUS & AC_AC1STATE_bm;
00254         }else{
00255 
00256         }
00257 
00258         return state;
00259 }
00260 
00261 
00272 uint8_t AC_GetWindowState(AC_t * ac)
00273 {
00274         return (ac->STATUS & AC_WSTATE_gm);
00275 }
00276 
00277 
00286 void AC_WaitForComparator_Blocking(AC_t * ac, AC_COMP_t comp)
00287 {
00288         /* Access correct bits based on which comparator submodule indicated.*/
00289         if(comp == 0){
00290                 /* Wait for interrupt flag to be set and clear it. */
00291                 do {} while ((ac->STATUS & AC_AC0IF_bm) == 0);
00292                 ac->STATUS = AC_AC0IF_bm;
00293         }else{
00294                 /* Wait for interrupt flag to be set and clear it. */
00295                 do {} while ((ac->STATUS & AC_AC1IF_bm) == 0);
00296                 ac->STATUS = AC_AC1IF_bm;
00297         }
00298 }
00299 
00300 
00308 void AC_WaitForWindow_Blocking(AC_t * ac)
00309 {
00310         /* Wait for interrupt flag to be set and clear it. */
00311         do {} while ((ac->STATUS & AC_WIF_bm) == 0);
00312         ac->STATUS = AC_WIF_bm;
00313 }
00314 
@DOC_TITLE@
Generated on Tue Apr 22 15:13:25 2008 for AVR1302 Using the XMEGA Analog Comparator by doxygen 1.5.5