                         .module velocity.c
 0000                   .dbfile velocity.c
                         .area text
                       ;  IX -> 0,x
 0000                 _SCI_isr::
 0000                   .dbfile C:\ICCTJP\include/isrdecl.h
 0000                   .dbfunc SCI_isr
 0000                   .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 ***********************/
                       ; 
                       ; 
 0000                 L2:
 0000 3B                rti
                       ;  IX -> 0,x
 0001                 _SPI_isr::
 0001                   .dbfunc SPI_isr
 0001                   .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  *********************/
                       ; 
                       ; 
 0001                 L3:
 0001 3B                rti
                       ;  IX -> 0,x
 0002                 _PAIE_isr::
 0002                   .dbfunc PAIE_isr
 0002                   .dbline 53
                       ; /**************************** Main **************************************/
                       ; 
                       ; void main(void)
                       ; {
                       ;     /* VT100 clear screen */ 
                       ;     char clear[]= "\x1b\x5B\x32\x4A\x04"; 
 0002                 L4:
 0002 3B                rti
                       ;  IX -> 0,x
 0003                 _PAV_isr::
 0003                   .dbfunc PAV_isr
 0003                   .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
 0003                 L5:
 0003 3B                rti
                       ;  IX -> 0,x
 0004                 _TOC3_isr::
 0004                   .dbfunc TOC3_isr
 0004                   .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();
 0004                 L6:
 0004 3B                rti
                       ;  IX -> 0,x
 0005                 _TIC3_isr::
 0005                   .dbfunc TIC3_isr
 0005                   .dbline 101
                       ;         
                       ;     }/*End While*/
                       ;     
                       ; }/*End Main*/
                       ; 
                       ; 
                       ; /**************************** End of Main *******************************/
                       ; 
                       ; 
                       ; 
                       ; /************************** Function Defintions *************************/
                       ; 
 0005                 L7:
 0005 3B                rti
                       ;  IX -> 0,x
 0006                 _TIC2_isr::
 0006                   .dbfunc TIC2_isr
 0006                   .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
 0006                 L8:
 0006 3B                rti
                       ;  IX -> 0,x
 0007                 _TIC1_isr::
 0007                   .dbfunc TIC1_isr
 0007                   .dbline 113
                       ;     SET_BIT(TMSK1, 0x40);   //Enable OC2 mask
                       ;     //INTR_ON();
                       ;     
                       ;     printf("End of Init pulse\n\n");
                       ; }
                       ; 
 0007                 L9:
 0007 3B                rti
                       ;  IX -> 0,x
 0008                 _IRQ_isr::
 0008                   .dbfunc IRQ_isr
 0008                   .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);
 0008                 L10:
 0008 3B                rti
                       ;  IX -> 0,x
 0009                 _XIRQ_isr::
 0009                   .dbfunc XIRQ_isr
 0009                   .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
 0009                 L11:
 0009 3B                rti
                       ;  IX -> 0,x
 000A                 _SWI_isr::
 000A                   .dbfunc SWI_isr
 000A                   .dbline 137
                       ;         SET_BIT(TCTL1, 0X40);
                       ;         TOC2 += period;         //Add period
                       ;     }
                       ;     
                       ;     else        //This is for the general case
                       ;     {
 000A                 L12:
 000A 3B                rti
                       ;  IX -> 0,x
 000B                 _ILLOP_isr::
 000B                   .dbfunc ILLOP_isr
 000B                   .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
                       ;         }
 000B                 L13:
 000B 3B                rti
                       ;  IX -> 0,x
 000C                 _COP_isr::
 000C                   .dbfunc COP_isr
 000C                   .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);
                       ;         }
 000C                 L14:
 000C 3B                rti
                       ;  IX -> 0,x
 000D                 _CLMON_isr::
 000D                   .dbfunc CLMON_isr
 000D                   .dbline 155
                       ;     }
                       ;     
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40) //Clear the interrupt flag
                       ; }   //This is the end of the interrupt routine
                       ; 
 000D                 L15:
 000D 3B                rti
                         .area data
 0000                 _drew::
 0000                   .blkw 1
                         .area idata
 0000 0000              .word _interrupt_vectors
                         .area data
 0002                 _error::
 0002                   .blkb 2
                         .area idata
 0002 0000              .word 0
                         .area data
 0004                 _desired::
 0004                   .blkb 2
                         .area idata
 0004 0096              .word 150
                         .area data
 0006                 _count::
 0006                   .blkb 4
                         .area idata
 0006 00000000          .word 0,0
                         .area text
 000E                 L17:
 000E 1B5B324A0400      .byte 27,91,50,'J,4,0
 0014                 L18:
 0014 1B5B313B314800    .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
 001B                 _main::
 001B BD0000            jsr __enterb
 001E 94                .byte 0x94
 001F                   .dbfile velocity.c
 001F                   .dbfunc main
 001F                   .dbline 53
 001F EC00              ldd 0,x
 0021 C3000E            addd #14
 0024 18CE000E          ldy #L17
 0028 3C                pshx
 0029 8F                xgdx
 002A CC0006            ldd #6
 002D BD0000            jsr __asgnblk
 0030 38                pulx
 0031                   .dbline 56
 0031 EC00              ldd 0,x
 0033 C30007            addd #7
 0036 18CE0014          ldy #L18
 003A 3C                pshx
 003B 8F                xgdx
 003C CC0007            ldd #7
 003F BD0000            jsr __asgnblk
 0042 38                pulx
 0043                   .dbline 58
 0043 18CE1026          ldy #0x1026
 0047 181C0080          bset 0,y,#128
 004B                   .dbline 59
 004B 18CE1026          ldy #0x1026
 004F 181D0003          bclr 0,y,#0x3
 0053                   .dbline 60
 0053 18CE1024          ldy #0x1024
 0057 181C0040          bset 0,y,#64
 005B                   .dbline 62
 005B BD00E4            jsr _init_pulse
 005E                   .dbline 63
 005E BD0000            jsr _init_analog
 0061                   .dbline 64
 0061 BD0000            jsr _init_serial
 0064                   .dbline 65
 0064 CC02A0            ldd #L19
 0067 BD0000            jsr _printf
 006A                   .dbline 69
 006A CC027F            ldd #L20
 006D BD0000            jsr _printf
 0070                   .dbline 71
 0070 CC025C            ldd #L21
 0073 BD0000            jsr _printf
 0076                   .dbline 72
 0076 BD0000            jsr _read_int
 0079 ED02              std 2,x
 007B CC03E8            ldd #1000
 007E 1AEE02            ldy 2,x
 0081 BD0000            jsr __muli
 0084 BD0000            jsr __d2lreg
 0087 18CE0002          ldy #_period
 008B BD0000            jsr __lreg2y
 008E                   .dbline 73
 008E CC0236            ldd #L22
 0091 BD0000            jsr _printf
 0094                   .dbline 74
 0094 BD0000            jsr _read_int
 0097 ED04              std 4,x
 0099 CC03E8            ldd #1000
 009C 1AEE04            ldy 4,x
 009F BD0000            jsr __muli
 00A2 BD0000            jsr __d2lreg
 00A5 18CE0006          ldy #_duty_cycle
 00A9 BD0000            jsr __lreg2y
 00AC 0E                        cli
                       
 00AD                   .dbline 76
 00AD 202B              bra L24
 00AF                 L23:
 00AF                   .dbline 80
 00AF CC0001            ldd #1
 00B2 BD0000            jsr _analog
 00B5 1A830005          cpd #5
 00B9 2E0A              bgt L26
 00BB                   .dbline 82
 00BB 18CE1000          ldy #0x1000
 00BF 181C0020          bset 0,y,#32
 00C3                   .dbline 83
 00C3 2014              bra L27
 00C5                 L26:
 00C5                   .dbline 84
 00C5 CC0001            ldd #1
 00C8 BD0000            jsr _analog
 00CB 1A8300FA          cpd #250
 00CF 2D08              blt L28
 00D1                   .dbline 86
 00D1 18CE1000          ldy #0x1000
 00D5 181D0020          bclr 0,y,#0x20
 00D9                   .dbline 87
 00D9                 L28:
 00D9                 L27:
 00D9 0F                        sei
                       
 00DA                   .dbline 91
 00DA                 L24:
 00DA                   .dbline 78
 00DA 20D3              bra L23
 00DC                 L16:
 00DC 8F                xgdx
 00DD C30014            addd #20
 00E0 8F                xgdx
 00E1 35                txs
 00E2 38                pulx
 00E3 39                rts
                       ;  IX -> 0,x
 00E4                 _init_pulse::
 00E4 0F                        sei
                       
 00E5                   .dbfunc init_pulse
 00E5                   .dbline 105
 00E5 18CE1020          ldy #0x1020
 00E9 181C0080          bset 0,y,#128
 00ED                   .dbline 106
 00ED 18CE1020          ldy #0x1020
 00F1 181D0040          bclr 0,y,#0x40
 00F5                   .dbline 107
 00F5 CC0000            ldd #0
 00F8 FD1018            std 0x1018
 00FB                   .dbline 108
 00FB 18CE1022          ldy #0x1022
 00FF 181C0040          bset 0,y,#64
 0103                   .dbline 111
 0103 CC0222            ldd #L31
 0106 BD0000            jsr _printf
 0109                   .dbline 112
 0109                 L30:
 0109 39                rts
                       ;  lreg1 -> -4,x
                       ;  lreg2 -> -8,x
                       ;  IX -> 0,x
 010A                 _TOC2_isr::
 010A BD0000            jsr __enterb
 010D 82                .byte 0x82
 010E                   .dbfunc TOC2_isr
 010E                   .dbline 121
 010E 18CE0006          ldy #_duty_cycle
 0112 BD0000            jsr __ly2reg
 0115 18CE021E          ldy #L35
 0119 BD0000            jsr __ly2reg2
 011C BD0000            jsr __lcmp
 011F 2E29              bgt L33
 0121                   .dbline 124
 0121 18CE1020          ldy #0x1020
 0125 181C0080          bset 0,y,#128
 0129                   .dbline 125
 0129 18CE1020          ldy #0x1020
 012D 181D0040          bclr 0,y,#0x40
 0131                   .dbline 126
 0131 18CE0002          ldy #_period
 0135 BD0000            jsr __ly2reg2
                         ; vol
 0138 FC1018            ldd 0x1018
 013B BD0000            jsr __ud2lreg
 013E BD0000            jsr __ladd
 0141 BD0000            jsr __lreg2d
 0144 FD1018            std 0x1018
 0147                   .dbline 127
 0147 7E01EB            jmp L34
 014A                 L33:
 014A                   .dbline 129
 014A 18CE0002          ldy #_period
 014E BD0000            jsr __ly2reg
 0151 18CE0006          ldy #_duty_cycle
 0155 BD0000            jsr __ly2reg2
 0158 BD0000            jsr __lsub
 015B 18CE021E          ldy #L35
 015F BD0000            jsr __ly2reg2
 0162 BD0000            jsr __lcmp
 0165 2E28              bgt L36
 0167                   .dbline 131
 0167 18CE1020          ldy #0x1020
 016B 181D0080          bclr 0,y,#0x80
 016F                   .dbline 132
 016F 18CE1020          ldy #0x1020
 0173 181C0040          bset 0,y,#64
 0177                   .dbline 133
 0177 18CE0002          ldy #_period
 017B BD0000            jsr __ly2reg2
                         ; vol
 017E FC1018            ldd 0x1018
 0181 BD0000            jsr __ud2lreg
 0184 BD0000            jsr __ladd
 0187 BD0000            jsr __lreg2d
 018A FD1018            std 0x1018
 018D                   .dbline 134
 018D 205C              bra L37
 018F                 L36:
 018F                   .dbline 138
 018F 18CE1020          ldy #0x1020
 0193 181F004028        brclr 0,y,#64,L38
 0198                   .dbline 140
 0198 18CE1020          ldy #0x1020
 019C 181D0040          bclr 0,y,#0x40
 01A0                   .dbline 141
 01A0 18CE1020          ldy #0x1020
 01A4 181C0080          bset 0,y,#128
 01A8                   .dbline 142
 01A8 18CE0006          ldy #_duty_cycle
 01AC BD0000            jsr __ly2reg2
                         ; vol
 01AF FC1018            ldd 0x1018
 01B2 BD0000            jsr __ud2lreg
 01B5 BD0000            jsr __ladd
 01B8 BD0000            jsr __lreg2d
 01BB FD1018            std 0x1018
 01BE                   .dbline 143
 01BE 202B              bra L39
 01C0                 L38:
 01C0                   .dbline 147
 01C0 18CE1020          ldy #0x1020
 01C4 181C00C0          bset 0,y,#192
 01C8                   .dbline 148
 01C8 18CE0002          ldy #_period
 01CC BD0000            jsr __ly2reg
 01CF 18CE0006          ldy #_duty_cycle
 01D3 BD0000            jsr __ly2reg2
 01D6 BD0000            jsr __lsub
 01D9 BD0000            jsr __lregmov
                         ; vol
 01DC FC1018            ldd 0x1018
 01DF BD0000            jsr __ud2lreg
 01E2 BD0000            jsr __ladd
 01E5 BD0000            jsr __lreg2d
 01E8 FD1018            std 0x1018
 01EB                   .dbline 149
 01EB                 L39:
 01EB                   .dbline 150
 01EB                 L37:
 01EB                 L34:
 01EB                   .dbline 153
 01EB 18CE1023          ldy #0x1023
 01EF 181D00BF          bclr 0,y,#0xbf
 01F3                   .dbline 154
 01F3                 L32:
 01F3 08                inx
 01F4 08                inx
 01F5 35                txs
 01F6 38                pulx
 01F7 3B                rti
                       ;  IX -> 0,x
 01F8                 _RTI_isr::
 01F8                   .dbfunc RTI_isr
 01F8                   .dbline 158
                       ; void RTI_isr(void)
                       ; {
                       ;     printf("%d\n", valve_sensor);   
 01F8 CC0001            ldd #1
 01FB BD0000            jsr _analog
 01FE 37                pshb
 01FF 36                psha
 0200 CC021A            ldd #L41
 0203 BD0000            jsr _printf
 0206 1838              puly
 0208                   .dbline 159
                       ;     CLEAR_FLAG(TFLG2, 0x40);
 0208 18CE1025          ldy #0x1025
 020C 181D00BF          bclr 0,y,#0xbf
 0210                   .dbline 160
                       ; }
 0210                 L40:
 0210 3B                rti
                       ;  IX -> 0,x
 0211                 _TOF_isr::
 0211                   .dbfunc TOF_isr
 0211                   .dbline 164
                       ; 
                       ; void TOF_isr(void)
                       ; {
                       ;     CLEAR_FLAG(TFLG1, 0x80);
 0211 18CE1023          ldy #0x1023
 0215 181D007F          bclr 0,y,#0x7f
 0219                   .dbline 165
                       ; }
 0219                 L42:
 0219 3B                rti
                         .area bss
 0000                 _gain::
 0000                   .blkb 2
 0002                 _period::
 0002                   .blkb 4
 0006                 _duty_cycle::
 0006                   .blkb 4
 000A                 _timertjp::
 000A                   .blkb 2
 000C                 _days::
 000C                   .blkb 2
 000E                 _hours::
 000E                   .blkb 2
 0010                 _minutes::
 0010                   .blkb 2
 0012                 _seconds::
 0012                   .blkb 2
 0014                 _msec::
 0014                   .blkb 2
                         .area text
 021A                 L41:
 021A 25640A00          .byte 37,'d,10,0
 021E                 L35:
 021E 00000064          .word 0,100
 0222                 L31:
 0222 456E64206F6620496E69742070756C73  .byte 'E,'n,'d,32,'o,'f,32,'I,'n,'i,'t,32,'p,'u,'l,'s
 0232 650A0A00          .byte 'e,10,10,0
 0236                 L22:
 0236 0A456E7465722064757479206379636C  .byte 10,'E,'n,'t,'e,'r,32,'d,'u,'t,'y,32,'c,'y,'c,'l
 0246 6520696E20656C636F636B73202F2031  .byte 'e,32,'i,'n,32,'e,'l,'c,'o,'c,'k,'s,32,47,32,49
 0256 3030302E0A00      .byte 48,48,48,46,10,0
 025C                 L21:
 025C 0A456E74657220706572696F6420696E  .byte 10,'E,'n,'t,'e,'r,32,'p,'e,'r,'i,'o,'d,32,'i,'n
 026C 206520636C6F636B73202F2031303030  .byte 32,'e,32,'c,'l,'o,'c,'k,'s,32,47,32,49,48,48,48
 027C 2E0A00            .byte 46,10,0
 027F                 L20:
 027F 504E45554D415449432056454C4F4349  .byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'V,'E,'L,'O,'C,'I
 028F 5459205445535450524F4752414D0A0A  .byte 'T,'Y,32,'T,'E,'S,'T,'P,'R,'O,'G,'R,'A,'M,10,10
 029F 00                .byte 0
 02A0                 L19:
 02A0 095469746C653A090976616C76652E63  .byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
 02B0 0A0950726F6772616D6D65723A095363  .byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
 02C0 6F7474204E6F72746D616E0A09446174  .byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
 02D0 653A09094D617263682C20323030300A  .byte 'e,58,9,9,'M,'a,'r,'c,'h,44,32,50,48,48,48,10
 02E0 0956657273696F6E0909310A0A00  .byte 9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10,0
