/************************************************************************************************************************
*	Program:		crap.c							*
*	Description:	This program was written to test the pneumatic		                *
*					valves and cylinders.  It will prompt the user	*
*					to select the desired function (manual or 		*
*					automatic positioning) and to select the desired      *
*					characteristics of the PWM signal for the		*
*					valves.					*
*	Programmer:		Scott Nortman					*
*	Date:			March 16, 2000					*
************************************************************************************************************************/

/**************************** Constants *********************************/
#define pulse_handler TOC2_isr
#define valve_sensor analog(1)
#define in	0
#define out 1
#define P 0
#define I 1
#define D 2
#define dt 4096
/**************************** End of Constants **************************/

/*************************** Interrupts *********************************/

/*************************** End of Interrupts **************************/
#pragma interrupt_handler TOC2_isr, RTI_isr;
/************************** Includes ************************************/
#include <tjpbase.h>
#include <analog.h>
#include <vectors.h>
#include <mil.h>
#include <hc11.h>
/************************ End of includes *******************************/

/************************** Global Variables*****************************/
long duty_cycle;	//duty_cycle in e clocks
long period;		//period in e clocks
int desired_position;
int error[3] = {0};
int k[3] = {500, 0, 0};

/************************ End of Global Variables ***********************/


/************************** Function Declarations  **********************/

/******************** End of Function Declarations  *********************/


/**************************** Main **************************************/

void main(void)
{
	/* VT100 clear screen */ 
	char clear[]= "\x1b\x5B\x32\x4A\x04"; 
	
	/* VT100 position cursor at (x,y) = (3,12) command is "\x1b[3;12H"*/
  	char place_home[]= "\x1b[1;1H";	/*Home*/
  	
  	char place_text[] = "\x1b[10;1H";/*position for text to be entered*/
init_analog();
  	init_serial();
while(1){  	
  	duty_cycle = 500 * valve_sensor;
  	
  	printf("%s", clear);
  	printf("%s", place_home);
  	
  	printf("%d\n", duty_cycle);
  	}
} 

void TOC2_isr(void){
CLEAR_FLAG(TFLG1, 0x40);
}

void RTI_isr(void){
CLEAR_FLAG(TFLG2, 0x40);
}