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

📄 adc.ini

📁 USB是主从总线
💻 INI
字号:
/*-------------------------------------------------------------
This file set the analog inputs for the A/D to different
values depending on the button clicked
-------------------------------------------------------------*/
define float my_VREF;
my_VREF = 2.5

/*-------------------------------------------------------------
Create buttons -to set the analog inputs to 0.
               -to set the analog inputs to VREF.
               -to set different analog inputs.
-------------------------------------------------------------*/

define button "Inputs = 0V" ,          "Set_Inputs(00);"
define button "Inputs = High" ,        "Set_Inputs(my_VREF);"
define button "Different A/D Inputs" , "Different_Inputs();"
define button "Sine Wave (ADC0)" ,     "ADC0_Sine(my_VREF);"
define button "Sawtooth (ADC0)" ,      "ADC0_Saw(my_VREF);"
define button "Square Wave (ADC0)" ,   "ADC0_Square(my_VREF, my_VREF/2.0);"
define button "Stop Signals" ,         "signal kill ADC0_Sine;signal kill ADC0_Saw;signal kill ADC0_Square;"
define button "Set A/D 1 Voltage" ,    "ADC1 = GetDbl(\"Enter A/D 1 Voltage\");"


/*----------------------------------------------------------------------
The following function generates anolog voltages in a sine wave pattern.
Use the built-in Logic analyzer to view the output as a sine wave.
----------------------------------------------------------------------*/
signal void ADC0_Sine( float sn_limit )  {

  float frequency;    // output frequency in Hz
  float offset;       // voltage offset
  float val;

  offset    = sn_limit / 2;
  frequency = 1500;

  printf ("Sine Wave Signal on AD Channel 0.\n");

  while (1) {
    val = __sin (frequency * (((float) STATES) / CLOCK) * 2 * 3.1415926);
    ADC0 = (val * (sn_limit / 2)) + offset;
    swatch (0.00001);                // in 10 uSec steps
  }
}

/*-----------------------------------------------------------------
The following function generates a sawtooth signal pattern for ADC.  
-----------------------------------------------------------------*/
signal void ADC0_Saw(float st_limit)  {
  float frequency;    // output frequency in Hz
  float offset;       // voltage offset
  float duration;     // duration in Seconds
  float val;
  long  i, end, steps;
    
  offset    = 00;
  frequency = 1400;
  duration  = 0.5;

  printf ("Saw Tooth Signal on AD Channel 0.\n");

  steps = 100000/frequency;
  while (1) {
    end = (duration * 100000);
    for (i = 0 ; i < end; i++)  {
      val = (i % steps) / ((float) steps);
      ADC0 = (val * st_limit) + offset;
      swatch (0.00001);                // in 10 uSec increments
    }
  }
}


/*---------------------------------------------
 Generates a Square Wave Signal on AD Channel 0
---------------------------------------------*/
signal void ADC0_Square(float peak, float offset)  {
  float frequency;    // output frequency in Hz
  float duty_cycle;   //number form 0.0 to 1.0
  float duration;     // duration in Seconds
    
  frequency = 2400;
  duration  = 0.05;
  duty_cycle = 0.65;	

  printf ("Square Wave Signal on AD Channel 0.\n");

  while (duration > 00)  {
    ADC0 = peak;
    swatch (duty_cycle / frequency);
    ADC0 = offset;
    swatch ((1.0 - duty_cycle) / frequency);
    duration -= 1.0 / frequency;
  }
}


/*-------------------------------------------------------------
-------------------------------------------------------------*/



⌨️ 快捷键说明

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