Skip to content. | Skip to navigation

Personal tools

lcu/m3.cpp

lcu/m3.cpp

lcu/m3.cpp

/////////////////////////////////////////////////////////////////////////////
// MAGELLAN II
// M3 Control Program
//
//  Last updated: 04 / 24 / 2005
//      by Jose M. Soto
//      The Observatories of the Carnegie Institution of Washington
//
//  Compile using Turbo C 3.0:
//    Use huge model, Far Data Threshold = 128, Automatic far data,
//    register variables = none.
//
//  Notes: This program also uses the general-purpose source code files
//         SBCSERCK.CPP and MATH.CPP, and the hardware specific routines
//         82C55.C (Digital I/O device) and ADMAX197.C (Analog/Digital conversion)
//
/////////////////////////////////////////////////////////////////////////////

#define Version 2.2

//////// NOTES FOR THE FUTURE
//
// - Remember watchdog, see pages 32-33 in 80C188EB manual
// - Use LED2 to indicate program running...

//////// NOTES FOR THE M3 COMPUTER
//
// The SBC1190 PC/104 embeddable Computer Board is located inside the m3 turret.
// It runs constantly a program that interacts with the hardware.
// To acctually know what's going on, you must use a high level program that runs
// in the remote m3 computer at the control room.

/////////////////////////////////////////////////////////////////////////////
// LOG OF CHANGES
//   02/15/05: Added pres/vac and tilts control to the clock interrupt
//   01/14/05: Started to modify each piece of code according to
//             new clock interrupt routine
//   12/20/04: Modified sbcserck.cpp to manage a clock interrupt routine
//             and serial communications using the SBC1190 board.
//             Old specific routines in SER1190.C are not needed anymore
//   12/04/04: Started a general program optimization
//   05/25/02: A/D conversion routines.
//   05/24/02: Added digital I/O control with the 82C55 parallel interface
//   05/23/02: Separated orginal single control structure in two
//             foreground/background processes
//   05/22/02: Added several tilt/presvac variables to the EDS
//   05/22/02: Development begins
/////////////////////////////////////////////////////////////////////////////

// Global variables and constants
// Global quit flag
int Quit = 0;                                                   // Set to 1 to quit from main loop
int ClockPPM = 0;                                               // Speed up or slow down clock in PPM (for accuracy)
#define CKF 2
// Clock rate used in Hz
// A clock interrupt with a rate of 1000Hz counts the passage of millisecs
#define M3ClockRate 1000*CKF
#define MotionProfile 5000  // Motion profile array sizes

// Includes
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <malloc.h>

#include "sbcserck.cpp"  // Serial/Clock interrupt routines for SBC1190 board

#include "math.cpp"      // Various math routines

#include "82C55.C"    // Digital I/O device routines
#include "ADMAX197.C" // Analog/Digital conversion routines

// Code
#include "io.h"       // Low level I/O routines
#include "parse.h"    // Serial and keyboard command parsing
#include "tilt.h"     // M3 Mirror Tilt control and status
#include "dgh.h"      // Low level DGH module control and status
#include "edslog.h"   // Engineering data stream routines
#include "presvac.h"  // Pressure/vacuum control behind the mirror

#include "io.cpp"
#include "parse.cpp"
#include "tilt.cpp"
#include "dgh.cpp"
#include "edslog.cpp"
#include "presvac.cpp"

// M3 Clock interrupt - performs all tasks necessary during a clock interrupt
void M3ClockInterrupt()
{
  // Pressure/Vaccuum control
  PresVacClockInterrupt();
  // Tilts control
  TiltInterrupt();
}

void main(int _argc,const char * _argv[])
{
  long mem1;
  char z[100];

  // Initialize egineering data stream
  EDSLog.Init(100);

  // Initialize digital and analog I/O cards
  InitHardwareIO();

  // Initialize clock interrupt, which occurs at 2000Hz
  InitClock(M3ClockRate); // Enable clock interrupt control

  // Initialize serial port parameters
  InitPorts();

  // Use PPM here?, in this local resident program?
  // Speed up or slow down clock, based on INI file
  //SetNewClockPPM(ClockPPM);

  // Initialize subsystems
  Tilt.Init();
  PresVac.Init();

  // Point clock interrupt to our code
  UserClockInterrupt = &M3ClockInterrupt;

//  mem1 = _memavl();
//  EDSLog.Add(999,"Program startup (v%0.2f) mem=%luk",Version,mem1/1024);

  // Main loop
  do
  {
    // Update periodic EDS entries
    UpdateEDS();

    // Parse serial input
    Parse();

    // Update pressure/vacuum control system
    PresVac.Update();

    // Update subsystems
    Tilt.Update();

  } while (!Quit);

  sprintf(z,"\n\rClock Overruns=%d\n\r",Overruns);
  SerialPutString(Host,z);
//  EDSLog.Add(998,"Clock Overruns: %d",Overruns);

  // Restore all hardware to a safe status
  StepperPowerOffNow();
  CloseComPorts();
  CloseHardwareIO();
  CloseClock();
}

Generated by GNU Enscript 1.6.5.2.
Document Actions