***************************************************** * * * eoh_l_t.s ( EOH TRANSMIT Load Version ) * * * * xxx_y_z.s * * * * xxx = eoh - engineering open house version * * tlc - TLC Robot Competition version * * y = l - LOAD version...via serial port * * b - BOARD version...via EEPROMS * * z = t - TRANSMITTER * * r - RECEIVER * * * * -Author : Mariusz Zaczek (zaczek@uiuc.edu) * * -Date : 01/11/2001 * * * ***************************************************** opt nolist ***************************************************** * * * This code is used for the TRANSMITTER side of * * robot control system. * * * * The primary purpose will be to read all inputs,* * make a data packet, and then send data via the * * SCI to the RF transmitter circuit. * * * * The inputs read include: * * left & right joys, toggle switches/buttons * * * ***************************************************** *** Port usage: * ***************************************************** * * * IMPORTANT NOTE: * * See page 4 of: "An Introduction to the MC6832" * * PULL DATA PINS 8 AND 9 LOW using the 74hct244n * * tri-state octal buffer. Do not use the DS or * * R/W pins as shown in the circuit of the manual.* * We want to use the DS pin as part of the input * * buttons but if the circuit is used as is then * * the pin can't be used for buttons inputs. So, * * instead we can just connect the RESET pin to * * the enable of the 74hct244n and then put low * * the two necessary pins of the buffer which * * will then pull low the DATAx pins. * * DATA8 = PORTE I/O when pulled low * * DATA9 = PORTF I/O when pulled low * * * * Port E (input) - 8 toggle switches/buttons * * M68332 PIN * * ------------------------------------------- * * 0 DSACK0 (49) START BUTTON * * - Simple 3-pin button with 74ls279 * * 1 DSACK1 (50) Main arm up * * 2 AVEC (51) Main arm down * * - Simple 3-pin button with 74ls279 * * for both the UP and DOWN motion * * - Using LMD18200 with PWM & Direction * * 3 RMC (52) Unscrew lightbulb * * - Simple 3-pin button with 74ls279 * * for both the UP and DOWN motion * * - Using LMD18200 with PWM only * * Direction is set in one direction * * 4 DS (53) **** NOT USED **** * * 5 AS (54) Release lightbulb * * 6 SIZ0 (55) Retract Release * * - Simple 3-pin button with 74ls279 * * for both the UNSCREW and BACK motion * * - Using LMD18200 with PWM & Direction * * 7 SIZ1 (56) Pneumatic Ram ON/OFF * * * * Port F (input) - read A/D converter * * M68332 PIN ADC0808 PIN * * ------------------------------------------- * * 0 MODCLK (28) 2^-8 (17) * * 1 IRQ1 (41) 2^-7 (14) * * 2 IRQ2 (42) 2^-6 (15) * * 3 IRQ3 (43) 2^-5 ( 8) * * 4 IRQ4 (44) 2^-4 (18) * * 5 IRQ5 (45) 2^-3 (19) * * 6 IRQ6 (46) 2^-2 (20) * * 7 IRQ7 (47) 2^-1 (21) * * * * Port QS (output) - controls A/D converter * * M68332 PIN ADC0808 PIN * * ------------------------------------------- * * 0 MISO (48) ADD A (25) * * 1 MOSI (47) ADD B (24) * * 2 SCK (50) ADD C (23) * * 3 PCS0 (49) ALE (22) * * 4 PCS1 (52) START (6) * * 5 PCS2 (51) OUT EN. (9) * * 6 PCS3 (54) Status LED * * 7 *** NOT USED *** * * * ***************************************************** *** Register usage: * ***************************************************** * D0 - all purpose * * D1 - 8 on/off toggle inputs * * D2 - Left Potentiometer * * D3 - Right Potentiometer * * D4 - * * D5 - Misc...used by delay counters * * D6 - Checksum * * D7 - * * * ***************************************************** *** Data Packet Skeleton * ***************************************************** * * * * * .... * * * * * * * * * ***************************************************** *** Program Execution * ***************************************************** * * * - Initialize the system * * - Set PORT E & F to be INPUT ports * * - Initialze the SCI to be a transmitter * * - Program starts when first button is pressed * * - Turn ON the status LED * * - Port QS is initialized * * - Main Loop * * - Code reads PORT E I/O inputs (i.e. buttons * * and switches * * - Enable the ADC0808 converter and read the two* * potentiometers for the left and right motors.* * - End Main Loop * * * ***************************************************** * * EQUATES * * Letter equates LETTER_A equ %01000001 * HEX $41 * max and min values for the LEFT joystick pot. max_L equ $e8 * 222/256 +5 VDC min_L equ $24 * 46 " " * max and min values for the RIGHT joystick pot. max_R equ $e1 * 215/256 +5 VDC min_R equ $1d * 39 " " * Include the main equate file include equ332.asm * Start LOAD program at memory location 9000 org $9000 * * Start * * - This is where it all begins ... * Start jsr InitSys * Initialize System move.w #$2700,SR jsr PortEInit * Init Port E (Input) jsr PortFInit * Init Port F (Input) jsr SCIInit * Init SCI for transmitter jsr EnableTrans * Enable SCI to transmit after button press * Initialize Port QS as Output ... 7pins only * NOTE: This initialization must come after the * TE bit in SCCR1 is set otherwise there * is a conflict with the TxD. Thus it * comes after the SCI initialization * routine and after the SCI is finally * enabled to TRANSMIT. jsr PortQSInit * Turn on the Status LED to show that the code is running. * This LED is controlled via pin 6 of PORT QS bset #6,PORTQS * * Main_Loop * * - Main program body. * Main_Loop jsr CaptureData * Get data from pots and i/o jsr CalculateData * Determine PWM values... jsr CalculateChecksum * Calculate Checksum jsr SendGarbage * Send 1 byte of garbage jsr SendHeader * Send header byte twice jsr SendData * Send data ... 4 bytes + Checksum bra Main_Loop * Loop * * InitSys * * - Initializes system... * InitSys clr.b (SYPCR).L move.b #$7F,(SYNCR).L rts * End ( InitSys ) * * CaptureData * * - Reads Port E and Port F for data... * ...stores in registers, D1,D2,D3 * CaptureData clr.l D1 * Clear regs. so as to set the TDRE clr.l D2 * bits to 0 (clear TDRE) clr.l D3 move.b PORTE0,D1 * Capture 8 on/off inputs * Start sequence for reading potentiometers using PORTQS * Only pins 0-5 (bits) of PORTQS are valid for this * case. Bit 6 is used for the status LED. Do not * read/write bit 7, reserved for TXD. * bits 2,1,0 will be for pot select (000, 001) * bit 3 will be for ALE * bit 4 will be for START * bit 5 will be for Output Enable jsr Delay1u * Delay needed for A/D converter jsr Delay1u jsr Delay1u jsr Delay1u * * Left Potentiometer - (000) * Pot_1 * - Clear Port QS (0-5), set to Pot #1 #%xx000000 bclr #0,PORTQS bclr #1,PORTQS bclr #2,PORTQS bclr #3,PORTQS bclr #4,PORTQS bclr #5,PORTQS jsr Delay1u * - Set the ALE bit (bit 3) #%xx001000 bset #3,PORTQS jsr Delay1u jsr Delay1u * - Set the START bit (bit 4) #%xx011000 bset #4,PORTQS jsr Delay1u jsr Delay1u * - Clear the ALE bit (bit 3) #%xx010000 bclr #3,PORTQS jsr Delay1u jsr Delay1u * - Clear the START bit (bit 4) #%xx000000 bclr #4,PORTQS jsr Delay125u * - Enable Output (bit 5) #%xx100000 bset #5,PORTQS jsr Delay1u jsr Delay1u * - Send output to the D2 Register move.b PORTF0,D2 jsr Delay1u jsr Delay1u jsr Delay1u jsr Delay1u * * Right Potentiometer -(001) * Pot_2 * - Clear Port QS (0-5), set to Pot #2 #%xx000001 bset #0,PORTQS bclr #1,PORTQS bclr #2,PORTQS bclr #3,PORTQS bclr #4,PORTQS bclr #5,PORTQS jsr Delay1u * - Set the ALE bit (bit 3) #%xx001001 bset #3,PORTQS jsr Delay1u jsr Delay1u * - Set the START bit (bit 4) #%xx011001 bset #4,PORTQS jsr Delay1u jsr Delay1u * - Clear the ALE bit (bit 3) #%xx010001 bclr #3,PORTQS jsr Delay1u jsr Delay1u * - Clear the START bit (bit 4) #%xx000001 bclr #4,PORTQS jsr Delay125u * - Enable Output (bit 5) #%xx100001 bset #5,PORTQS jsr Delay1u jsr Delay1u * - Send output to the D3 Register move.b PORTF0,D3 CaptureDataEnd rts * End ( CaptureData ) * * CalculateChecksum * * - Used for error checking...checksum byte sent along * with data to receiver. * CalculateChecksum clr.l D6 * Clear D6 register eor.b D1,D6 * XOR with the toggle register, D1 eor.b D2,D6 * XOR with LEFT pot, D2 eor.b D3,D6 * XOR with RIGHT pot, D3 rts * End ( CalculateChecksum ) * * SendGarbage * * - send garbage data to have something transmit * SendGarbage move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendGarbage move.w #%01010101,(SCDR).L rts * End ( SendGarbage ) * * SendHeader * * - Sends the header byte of data (letter A) * - Header contains the following bytes: * A A * SendHeader SendHeaderOne move.w (SCSR).L,D0 andi.w #$0100,D0 * Check if able to send next byte beq SendHeaderOne move.w #LETTER_A,(SCDR).L * if so then send "A" letter SendHeaderTwo move.w (SCSR).L,D0 andi.w #$0100,D0 * Check if able to send next byte beq SendHeaderTwo move.w #LETTER_A,(SCDR).L * if so then send "A" letter rts * End ( SendHeader ) * * SendData * * - Sends 4 different bytes of data, which include: * <8 toggle> * SendData * * 8 on/off buttons * SendFirst move.w (SCSR).L,D0 andi.w #$0100,D0 * Check if able to send next byte beq SendFirst move.w D1,(SCDR).L * if so then send I/O pins * * Left Joystick Pot * SendSecond move.w (SCSR).L,D0 andi.w #$0100,D0 * Check if able to send next byte beq SendSecond move.w D2,(SCDR).L * if so then send LEFT potentiometer * * Right Joystick Pot * SendThird move.w (SCSR).L,D0 andi.w #$0100,D0 * Check if able to send next byte beq SendThird move.w D3,(SCDR).L * if so then send RIGHT potentiometer * * Send Checksum * SendChecksum move.w (SCSR).L,D0 andi.w #$0100,D0 * Check if able to send next byte beq SendChecksum move.w D6,(SCDR).L * if so then send CHECKSUM SendEnd rts * End ( SendData ) * * PortEInit * * - Initializes all pins of Port E to input pins. * PortEInit move.b #$00,PORTE0 * Clear the data register move.b #$00,PEPAR * Configure Port E as I/O move.b #$00,DDRE * Configure Port E as input rts * End ( PortEInit ) * * PortFInit * * - Intializes all pins of Port F to input pins. * PortFInit move.b #$00,PORTF0 * Clear the data register move.b #$00,PFPAR * Configure Port F as I/O move.b #$00,DDRF * Configure Port F as input rts * End ( PortFInit ) * * PortQSInit * * - Initialize Port QS to output (only 1st 7 pins available) * PortQSInit move.b #$00,PORTQS * Clear data register move.b #$80,PQSPAR * 0-6 I/O, bit 7 TxD move.b #$ff,DDRQS * Set all pins as Digital Output rts * End ( PortQSInit ) * * SCIInit * * - Setup the SCI to have baud rate of 9600 * SCIInit move.w #$0037,(SCCR0).L * Set the SCI baud rate to 9600 move.w #$0000,(SCCR1).L * Clear SCCR1 ... enable later rts * End ( SCIInit ) * * EnableTrans * * - Enable the transmitter of SCI...reads PORT E to determine if button * number 1 is pressed...is YES then SCI transmitter is enabled. * EnableTrans * jmp Transmit move.b PORTE0,D0 * If button is pressed then continue on.. andi.w #$0001,D0 beq EnableTrans * else, keep looping back until pressed. Transmit move.w #$0008,(SCCR1).L * enable the transmitter rts * End ( EnableTrans ) * * CalculateData * * - Determine Pot position and scale to 0-255 * - This is done by reading the voltage of the * potentiometer connected to the ADC0808 * converter. This chip converts the analog * voltage to a digital signal and outputs it * on its 8 output pins. These pins are read * by PORTF0 and stoFRred in the appropriate * registers. * - The registers must be scaled relative to the * max and min voltage values of the potentio- * meters being used. The min value is mapped to * 0%=0 and the max value is mapped to 100%=255 * This is done by: * NUMERATOR * 255 * --------------- * DENOMINATOR * * (pot voltage) - (min voltage) * ----------------------------- * 255 * (max voltage) - (min voltage) * CalculateData Motor1 clr.l D5 * Clear reg 5 move.w #max_L,D5 * Set D5 to max LEFT value sub.w #min_L,D5 * Calculate range between max & min, DENOMINATOR sub.w #min_L,D2 * Subtract min value from D2 to get NUMERATOR mulu.w #$ff,D2 * Multiply numerator by 255 divu.w D5,D2 * Divide NUMERATOR by DENOMINATOR Motor2 clr.l D5 * Clear reg 5 move.w #max_R,D5 * Set D5 to max RIGHT value sub.w #min_R,D5 * Calculate range between max & min, DENOMINATOR sub.w #min_R,D3 * Subtract min value from D3 to get NUMERATOR mulu.w #$ff,D3 * Multiply numerator by 255 divu.w D5,D3 * Divide NUMERATOR by DENOMINATOR CalculateDataEnd rts * End ( CalculateData ) * * Delay 125 microseconds * Delay125u clr.l D5 Delay125uMid cmp.l #5000,D5 bge Delay125uEnd nop add.l #1,D5 jmp Delay125uMid Delay125uEnd rts * * Delay 1 microseconds * Delay1u clr.l D5 Delay1uMid cmp.l #400,D5 bge Delay1uEnd nop add.l #1,D5 jmp Delay1uMid Delay1uEnd rts