⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adcfd.c

📁 PWM同步
💻 C
📖 第 1 页 / 共 2 页
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : AdcFD.C
**     Project   : Iadc
**     Processor : 56F8346
**     Beantype  : ADC
**     Version   : Bean 01.329, Driver 01.14, CPU db: 2.87.097
**     Compiler  : Metrowerks DSP C Compiler
**     Date/Time : 2009-2-10, 11:45
**     Abstract  :
**         This device "ADC" implements an A/D converter,
**         its control methods and interrupt/event handling procedure.
**     Settings  :
**         AD control register         : ADCB_ADCR1  [62016]
**         AD control register         : ADCB_ADCR2  [62017]
**         AD control register         : ADCB_ADZCC  [62018]
**         AD control register         : ADCB_ADLST1 [62019]
**         AD control register         : ADCB_ADLST2 [62020]
**         AD control register         : ADCB_ADSDIS [62021]
**         AD control register         : ADCB_ADSTAT [62022]
**         AD control register         : ADCB_ADLSTAT [62023]
**         AD control register         : ADCB_ADZCSTAT [62024]
**         AD control register         : ADCB_ADLLMT0 [62033]
**         AD control register         : ADCB_ADLLMT1 [62034]
**         AD control register         : ADCB_ADLLMT2 [62035]
**         AD control register         : ADCB_ADLLMT3 [62036]
**         AD control register         : ADCB_ADLLMT4 [62037]
**         AD control register         : ADCB_ADLLMT5 [62038]
**         AD control register         : ADCB_ADLLMT6 [62039]
**         AD control register         : ADCB_ADLLMT7 [62040]
**         AD control register         : ADCB_ADHLMT0 [62041]
**         AD control register         : ADCB_ADHLMT1 [62042]
**         AD control register         : ADCB_ADHLMT2 [62043]
**         AD control register         : ADCB_ADHLMT3 [62044]
**         AD control register         : ADCB_ADHLMT4 [62045]
**         AD control register         : ADCB_ADHLMT5 [62046]
**         AD control register         : ADCB_ADHLMT6 [62047]
**         AD control register         : ADCB_ADHLMT7 [62048]
**         AD control register         : ADCB_ADOFS0 [62049]
**         AD control register         : ADCB_ADOFS1 [62050]
**         AD control register         : ADCB_ADOFS2 [62051]
**         AD control register         : ADCB_ADOFS3 [62052]
**         AD control register         : ADCB_ADOFS4 [62053]
**         AD control register         : ADCB_ADOFS5 [62054]
**         AD control register         : ADCB_ADOFS6 [62055]
**         AD control register         : ADCB_ADOFS7 [62056]
**         AD control register         : ADCB_ADPOWER [62057]
**         AD result register          : ADCBres7    [62032]
**         AD result register          : ADCBres7    [62032]
**         Interrupt name              : INT_ADCB_Complete
**         Interrupt enable reg.       : INTC_IPR8   [61864]
**         Priority                    : 1
**         User handling procedure     : AdcFD_OnEnd
**         Number of conversions       : 1
**         AD resolution               : 12-bit
**
**         Input pins
**
**
**
**         Initialization:
**              Conversion             : Enabled
**              Event                  : Enabled
**         High speed mode
**             Prescaler               : divide-by-24
**     Contents  :
**         Enable           - byte AdcFD_Enable(void);
**         Disable          - byte AdcFD_Disable(void);
**         Start            - byte AdcFD_Start(void);
**         Measure          - byte AdcFD_Measure(bool WaitForResult);
**         EnableIntTrigger - byte AdcFD_EnableIntTrigger(void);
**         GetValue         - byte AdcFD_GetValue(void* Values);
**         GetChanValue     - byte AdcFD_GetChanValue(byte Channel,void* Value);
**         GetValue8        - byte AdcFD_GetValue8(byte *Values);
**         GetChanValue8    - byte AdcFD_GetChanValue8(byte Channel,byte *Value);
**         GetValue16       - byte AdcFD_GetValue16(word *Values);
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2005
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/

/* MODULE AdcFD. */

#include "Events.h"
#include "AdcFD.h"

#define IDLE            0              /* IDLE state           */
#define MEASURE         1              /* MESURE state         */
#define CONTINUOUS      2              /* CONTINUOUS state     */
#define SINGLE          3              /* SINGLE state         */

bool AdcFD_EnUser;                     /* Enable/Disable device */
static bool OutFlg;                    /* Measurement finish flag */
volatile byte AdcFD_ModeFlg;           /* Current state of device */

/*
** ===================================================================
**     Method      :  AdcFD_InterruptCC (bean ADC)
**
**     Description :
**         The method services the conversion complete interrupt of the 
**         selected peripheral(s) and eventually invokes the beans 
**         event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp saveall
void AdcFD_InterruptCC(void)
{
  setRegBits(ADCB_ADSTAT,2048);        /* Clear EOSI flag */
  OutFlg = TRUE;                       /* Measured values are available */
  if ((AdcFD_ModeFlg == CONTINUOUS) || (getRegBit(ADCB_ADCR1,SMODE2))) { /* Running in continuous or trigger mode? */
    if (AdcFD_ModeFlg == CONTINUOUS) { /* Running in continuous mode? */
      setRegBit(ADCB_ADCR1,START);     /* Launching of conversion */
    }
  }
  else {
    AdcFD_ModeFlg = IDLE;              /* Set the bean to the idle mode */
  }
  AdcFD_OnEnd();                       /* If yes then invoke user event */
}

/*
** ===================================================================
**     Method      :  HWEnDi (bean ADC)
**
**     Description :
**         Enables or disables the peripheral(s) associated with the bean.
**         The method is called automatically as a part of Enable, 
**         Disable and Init methods and several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void HWEnDi(void)
{
  volatile word i;

  if (AdcFD_EnUser) {                  /* Enable device? */
    if (getRegBits(ADCB_ADPOWER,(ADCB_ADPOWER_PSTS0_MASK|ADCB_ADPOWER_PSTS2_MASK))) { /* Is device enabled? */
      /* ADCB_ADPOWER: ??=0,??=0,??=0,PSTS2=0,PSTS1=0,PSTS0=0,PUDELAY=13,PSM=0,PD2=0,PD1=1,PD0=0 */
      setReg(ADCB_ADPOWER,210);        /* Enable device */
      for (i=0;i<100;i++) {}           /* Recovery time of voltage reference */
      while (ADCB_ADPOWER&((ADCB_ADPOWER_PSTS0_MASK|ADCB_ADPOWER_PSTS2_MASK))) {} /* Wait for device powered up */
    }
    if (AdcFD_ModeFlg) {               /* Launch measurement? */
      OutFlg = FALSE;                  /* Measured values are available */
      if (getRegBit(ADCB_ADCR1,SMODE2)) { /* Trigger mode? */
        setRegBit(ADCB_ADCR1,SYNC);    /* Use sync input to initiate a conversion */
        clrRegBit(ADCB_ADCR1,STOP);    /* Normal operation mode */
      }
      else {
        clrRegBits(ADCB_ADCR1,ADCB_ADCR1_SYNC_MASK | ADCB_ADCR1_STOP_MASK); /* Set normal operation mode and sync input disabled */
        setRegBit(ADCB_ADCR1,START);   /* Launching of conversion */
      }
    }
    else {
      setRegBit(ADCB_ADCR1,STOP);      /* Stop command issued */
    }
  }
  else {
    setRegBit(ADCB_ADCR1,STOP);        /* Stop command issued */
    /* ADCB_ADPOWER: ??=0,??=0,??=0,PSTS2=0,PSTS1=0,PSTS0=0,PUDELAY=13,PSM=0,PD2=1,PD1=1,PD0=1 */
    setReg(ADCB_ADPOWER,215);          /* Disable device */
  }
}

/*
** ===================================================================
**     Method      :  AdcFD_Enable (bean ADC)
**
**     Description :
**         Enables A/D converter bean. <Events> may be generated
**         (<DisableEvent>/<EnableEvent>). If possible, this method
**         switches on A/D converter device, voltage reference, etc.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte AdcFD_Enable(void)
{
  if (AdcFD_EnUser)                    /* Is the device enabled by user? */
    return ERR_OK;                     /* If yes then set the flag "device enabled" */
  AdcFD_EnUser = TRUE;                 /* Set the flag "device enabled" */
  HWEnDi();                            /* Enable the device */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AdcFD_Disable (bean ADC)
**
**     Description :
**         Disables A/D converter bean. No <events> will be
**         generated. If possible, this method switches off A/D
**         converter device, voltage reference, etc.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte AdcFD_Disable(void)
{
  if (!AdcFD_EnUser)                   /* Is the device disabled by user? */
    return ERR_OK;                     /* If yes then OK */
  AdcFD_EnUser = FALSE;                /* If yes then set the flag "device disabled" */
  HWEnDi();                            /* Enable the device */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AdcFD_Start (bean ADC)
**
**     Description :
**         This method starts continuous conversion of the A/D
**         channels. When each measurement on all channels has
**         finished the <OnEnd > event may be invoked. This method
**         is not available if the <interrupt service> is disabled
**         and the device doesn't support the continuous mode. Note:
**         If time of measurement is too short and the instruction
**         clock is too slow then the conversion complete interrupt
**         and its handler may cause a system overflow.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED - Device is disabled
**                           ERR_BUSY - A conversion is already
**                           running
** ===================================================================
*/
byte AdcFD_Start(void)
{
  if (!AdcFD_EnUser)                   /* Is the device disabled by user? */
    return ERR_DISABLED;               /* If yes then error */
  if (AdcFD_ModeFlg != IDLE)           /* Is the device in running mode? */
    return ERR_BUSY;                   /* If yes then error */
  setRegBitGroup(ADCB_ADCR1,SMODE,0);  /* Select 'Once Sequential' mode */
  AdcFD_ModeFlg = CONTINUOUS;          /* Set state of device to the continuous mode */
  HWEnDi();                            /* Enable the device */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  AdcFD_Measure (bean ADC)
**
**     Description :
**         This method performs one measurement on all channels that
**         are set in the bean inspector. (Note: If the <number of
**         conversions> is more than one the conversion of A/D
**         channels is performed specified number of times.)
**     Parameters  :
**         NAME            - DESCRIPTION
**         WaitForResult   - Wait for a result
**                           of a conversion. If <interrupt service>
**                           is disabled, A/D peripheral doesn't
**                           support measuring all channels at once
**                           or <Autoscan mode> property isn't
**                           enabled and at the same time the <number
**                           of channel> is greater than 1, then the
**                           WaitForResult parameter is ignored and
**                           the method waits for each result every
**                           time. If the <interrupt service> is
**                           disabled and a <number of conversions>
**                           is greater than 1, the parameter is
**                           ignored and the method also waits for
**                           each result every time.
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED - Device is disabled
**                           ERR_BUSY - A conversion is already
**                           running
** ===================================================================
*/
byte AdcFD_Measure(bool WaitForResult)
{
  if (!AdcFD_EnUser)                   /* Is the device disabled by user? */
    return ERR_DISABLED;               /* If yes then error */
  if (AdcFD_ModeFlg != IDLE)           /* Is the device in running mode? */
    return ERR_BUSY;                   /* If yes then error */
  setRegBitGroup(ADCB_ADCR1,SMODE,0);  /* Select 'Once Sequential' mode */
  AdcFD_ModeFlg = MEASURE;             /* Set state of device to the measure mode */
  HWEnDi();                            /* Enable the device */
  if (WaitForResult)                   /* Is WaitForResult TRUE? */
    while (AdcFD_ModeFlg == MEASURE) {} /* If yes then wait for end of measurement */
  return ERR_OK;                       /* OK */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -