	.module velocity.c
	.dbfile velocity.c
	.area text
;  IX -> 0,x
_SCI_isr::
	.dbfile C:\ICCTJP\include/isrdecl.h
	.dbfunc SCI_isr
	.dbline 41
; /************************************************************************************************************************
; *	Program:		velocity.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 20, 2000					*
; ************************************************************************************************************************/
; 
; /**************************** Constants *********************************/
; #define pulse_handler TOC2_isr
; #define tolerance 10 
; #define valve_sensor analog(1)
; /**************************** End of Constants **************************/
; 
; /*************************** Interrupts *********************************/
; #pragma interrupt_handler TOC2_isr, RTI_isr, TOF_isr;
; /*************************** End of Interrupts **************************/
; 
; /************************** 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 error = 0;
; int gain;
; int desired = 150;
; long count = 0;
; 	
; /************************ End of Global Variables ***********************/
; 
; 
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 47
; /************************** Function Declarations  **********************/
; void init_pulse();		//Initilizes TOC for PWM interrupts
; void pulse_handler();	//This is the function executed at each TOC2_isr
; /******************** End of Function Declarations  *********************/
; 
; 
L3:
	rti
;  IX -> 0,x
_PAIE_isr::
	.dbfunc PAIE_isr
	.dbline 53
; /**************************** Main **************************************/
; 
; void main(void)
; {
; 	/* VT100 clear screen */ 
; 	char clear[]= "\x1b\x5B\x32\x4A\x04"; 
L4:
	rti
;  IX -> 0,x
_PAV_isr::
	.dbfunc PAV_isr
	.dbline 59
; 	
; 	/* VT100 position cursor at (x,y) = (3,12) command is "\x1b[3;12H"*/
;   	char place[]= "\x1b[1;1H";	/*Home*/
;  
; 	SET_BIT(PACTL, 0x80);
; 	CLEAR_BIT(PACTL, 0x03); //Set RTI rate
L5:
	rti
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 89
; 	SET_BIT(TMSK2, 0x40);//Enable RTI interrupt
; 	   	
;  	init_pulse();
;   	init_analog();
;   	init_serial(); 	
;   	printf("\tTitle:\t\tvalve.c\n"
;   "\tProgrammer:\tScott Nortman\n"
;   "\tDate:\t\tMarch, 2000\n"
;   "\tVersion\t\t1\n\n");
;   	printf("PNEUMATIC VELOCITY TESTPROGRAM\n\n");
;   	
;   	printf("\nEnter period in e clocks / 1000.\n");
;   	period = (read_int() * 1000);
;   	printf("\nEnter duty cycle in elcocks / 1000.\n");
;   	duty_cycle = (read_int() * 1000);
; 	
; 	INTR_ON();
; 	
; 	while(1)
; 	{
; 		if (valve_sensor <= 5)
; 		{
; 			SET_BIT(PORTA, 0x20);
; 		}
; 		else if (valve_sensor >= 250)
; 		{
; 			CLEAR_BIT(PORTA, 0x20);
; 		}
; 		
; 		INTR_OFF();
L6:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 101
; 		
; 	}/*End While*/
;   	
; }/*End Main*/
; 
; 
; /**************************** End of Main *******************************/
; 
; 
; 
; /************************** Function Defintions *************************/
; 
L7:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 107
; void init_pulse(void)
; {
; 	INTR_OFF();
; 	SET_BIT(TCTL1, 0x80);	//Enable OC2 for falling edge on first sucessful compare (safe default)
; 	CLEAR_BIT(TCTL1, 0x40);
; 	TOC2 = 0;	//Set TOC2 to zero
L8:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 113
; 	SET_BIT(TMSK1, 0x40);	//Enable OC2 mask
; 	//INTR_ON();
; 	
; 	printf("End of Init pulse\n\n");
; }
; 
L9:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 125
; void pulse_handler()
; {	//printf("ISR\n");
; 
; 
; 	//enable toggle
; 	//CLEAR_BIT(TCTL1, 0x80);
; 	//SET_BIT(TCTL1, 0x40);
; 	if (duty_cycle <= 100)	
; 	//This handles if duty cycle is less than or equal to 50 e clocks ( almost always off)
; 	{
; 		SET_BIT(TCTL1, 0x80);	//Enable OC2 for falling edge (make sure pin goes low)
; 		CLEAR_BIT(TCTL1, 0X40);
L10:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 131
; 		TOC2 += period;			//Add the period to TOC2
; 	}
; 	
; 	else if ((period - duty_cycle) <= 100)	//This handles what to do if the pin should almost always be high
; 	{
; 		CLEAR_BIT(TCTL1, 0x80);	//Set the pin to rising edge
L11:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 137
; 		SET_BIT(TCTL1, 0X40);
; 		TOC2 += period;			//Add period
; 	}
; 	
; 	else		//This is for the general case
; 	{
L12:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 143
; 		if (TCTL1 & 0x40)	//Test bit 6.  If it is a one, you are now high and must change to go low
; 		{
; 			CLEAR_BIT(TCTL1, 0x40);  //Clear bit 6 to set for falling edge on next interrupt
; 			SET_BIT(TCTL1, 0X80);
; 			TOC2 += duty_cycle;		//Add the duty cycle e clocks if you are now high
; 		}
L13:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 149
; 		
; 		else //if(!(TCTL1 & 0x40))	//Test bit 6.  If it is low, you are now low and must change to go high
; 		{
; 			SET_BIT(TCTL1, 0xC0);	//Set bit 6 to go high next interrupt
; 			TOC2 += (period - duty_cycle);
; 		}
L14:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 155
; 	}
; 	
; 	
; 	CLEAR_FLAG(TFLG1, 0x40)	//Clear the interrupt flag
; }	//This is the end of the interrupt routine
; 
L15:
	rti
	.area data
_drew::
	.blkw 1
	.area idata
	.word _interrupt_vectors
	.area data
_error::
	.blkb 2
	.area idata
	.word 0
	.area data
_desired::
	.blkb 2
	.area idata
	.word 150
	.area data
_count::
	.blkb 4
	.area idata
	.word 0,0
	.area text
L17:
	.byte 27,91,50,'J,4,0
L18:
	.byte 27,91,49,59,49,'H,0
;  lreg1 -> -4,x
;  lreg2 -> -8,x
;  IX -> 0,x
;  func temp: 2,x - 6,x
;          place -> 7,x
;          clear -> 14,x
_main::
	jsr __enterb
	.byte 0x94
	.dbfile velocity.c
	.dbfunc main
	.dbline 53
	ldd 0,x
	addd #14
	ldy #L17
	pshx
	xgdx
	ldd #6
	jsr __asgnblk
	pulx
	.dbline 56
	ldd 0,x
	addd #7
	ldy #L18
	pshx
	xgdx
	ldd #7
	jsr __asgnblk
	pulx
	.dbline 58
	ldy #0x1026
	bset 0,y,#128
	.dbline 59
	ldy #0x1026
	bclr 0,y,#0x3
	.dbline 60
	ldy #0x1024
	bset 0,y,#64
	.dbline 62
	jsr _init_pulse
	.dbline 63
	jsr _init_analog
	.dbline 64
	jsr _init_serial
	.dbline 65
	ldd #L19
	jsr _printf
	.dbline 69
	ldd #L20
	jsr _printf
	.dbline 71
	ldd #L21
	jsr _printf
	.dbline 72
	jsr _read_int
	std 2,x
	ldd #1000
	ldy 2,x
	jsr __muli
	jsr __d2lreg
	ldy #_period
	jsr __lreg2y
	.dbline 73
	ldd #L22
	jsr _printf
	.dbline 74
	jsr _read_int
	std 4,x
	ldd #1000
	ldy 4,x
	jsr __muli
	jsr __d2lreg
	ldy #_duty_cycle
	jsr __lreg2y
			cli

	.dbline 76
	bra L24
L23:
	.dbline 80
	ldd #1
	jsr _analog
	cpd #5
	bgt L26
	.dbline 82
	ldy #0x1000
	bset 0,y,#32
	.dbline 83
	bra L27
L26:
	.dbline 84
	ldd #1
	jsr _analog
	cpd #250
	blt L28
	.dbline 86
	ldy #0x1000
	bclr 0,y,#0x20
	.dbline 87
L28:
L27:
			sei

	.dbline 91
L24:
	.dbline 78
	bra L23
L16:
	xgdx
	addd #20
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
_init_pulse::
			sei

	.dbfunc init_pulse
	.dbline 105
	ldy #0x1020
	bset 0,y,#128
	.dbline 106
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 107
	ldd #0
	std 0x1018
	.dbline 108
	ldy #0x1022
	bset 0,y,#64
	.dbline 111
	ldd #L31
	jsr _printf
	.dbline 112
L30:
	rts
;  lreg1 -> -4,x
;  lreg2 -> -8,x
;  IX -> 0,x
_TOC2_isr::
	jsr __enterb
	.byte 0x82
	.dbfunc TOC2_isr
	.dbline 121
	ldy #_duty_cycle
	jsr __ly2reg
	ldy #L35
	jsr __ly2reg2
	jsr __lcmp
	bgt L33
	.dbline 124
	ldy #0x1020
	bset 0,y,#128
	.dbline 125
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 126
	ldy #_period
	jsr __ly2reg2
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 127
	jmp L34
L33:
	.dbline 129
	ldy #_period
	jsr __ly2reg
	ldy #_duty_cycle
	jsr __ly2reg2
	jsr __lsub
	ldy #L35
	jsr __ly2reg2
	jsr __lcmp
	bgt L36
	.dbline 131
	ldy #0x1020
	bclr 0,y,#0x80
	.dbline 132
	ldy #0x1020
	bset 0,y,#64
	.dbline 133
	ldy #_period
	jsr __ly2reg2
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 134
	bra L37
L36:
	.dbline 138
	ldy #0x1020
	brclr 0,y,#64,L38
	.dbline 140
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 141
	ldy #0x1020
	bset 0,y,#128
	.dbline 142
	ldy #_duty_cycle
	jsr __ly2reg2
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 143
	bra L39
L38:
	.dbline 147
	ldy #0x1020
	bset 0,y,#192
	.dbline 148
	ldy #_period
	jsr __ly2reg
	ldy #_duty_cycle
	jsr __ly2reg2
	jsr __lsub
	jsr __lregmov
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 149
L39:
	.dbline 150
L37:
L34:
	.dbline 153
	ldy #0x1023
	bclr 0,y,#0xbf
	.dbline 154
L32:
	inx
	inx
	txs
	pulx
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 158
; void RTI_isr(void)
; {
; 	printf("%d\n", valve_sensor);	
	ldd #1
	jsr _analog
	pshb
	psha
	ldd #L41
	jsr _printf
	puly
	.dbline 159
; 	CLEAR_FLAG(TFLG2, 0x40);
	ldy #0x1025
	bclr 0,y,#0xbf
	.dbline 160
; }
L40:
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 164
; 
; void TOF_isr(void)
; {
; 	CLEAR_FLAG(TFLG1, 0x80);
	ldy #0x1023
	bclr 0,y,#0x7f
	.dbline 165
; }
L42:
	rti
	.area bss
_gain::
	.blkb 2
_period::
	.blkb 4
_duty_cycle::
	.blkb 4
_timertjp::
	.blkb 2
_days::
	.blkb 2
_hours::
	.blkb 2
_minutes::
	.blkb 2
_seconds::
	.blkb 2
_msec::
	.blkb 2
	.area text
L41:
	.byte 37,'d,10,0
L35:
	.word 0,100
L31:
	.byte 'E,'n,'d,32,'o,'f,32,'I,'n,'i,'t,32,'p,'u,'l,'s
	.byte 'e,10,10,0
L22:
	.byte 10,'E,'n,'t,'e,'r,32,'d,'u,'t,'y,32,'c,'y,'c,'l
	.byte 'e,32,'i,'n,32,'e,'l,'c,'o,'c,'k,'s,32,47,32,49
	.byte 48,48,48,46,10,0
L21:
	.byte 10,'E,'n,'t,'e,'r,32,'p,'e,'r,'i,'o,'d,32,'i,'n
	.byte 32,'e,32,'c,'l,'o,'c,'k,'s,32,47,32,49,48,48,48
	.byte 46,10,0
L20:
	.byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'V,'E,'L,'O,'C,'I
	.byte 'T,'Y,32,'T,'E,'S,'T,'P,'R,'O,'G,'R,'A,'M,10,10
	.byte 0
L19:
	.byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
	.byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
	.byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
	.byte 'e,58,9,9,'M,'a,'r,'c,'h,44,32,50,48,48,48,10
	.byte 9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10,0
