Date: Thu, 18 Nov 1999 09:32:02 -0800 From: Gary Livick Subject: Re:Servo on PA3 To: "Fred G. Martin" Fred--- I am using the dual servo sans expansion board servo software from your site on a Super T-Comp computer (HC11 A1 modified to run in special test mode) running Rug Warrior p-code. It works fine except it was necessary to switch the code for the PA5 pin over to PA3 because of port contention on the T-Comp. This should run on the Handy Board just fine, although I haven't tried it yet. It will even work with the buzzer in place if the user can but up with a little weirdness. Here is the code if you want to use it on the site: ************************************************************************* * * * SERVO_A3.ASM * * * * uses: Port A bit 3 as servo control signal * * TOC5 interrupt used to generate positive-side (pulse width) and * * negative-side (pulse interval) of control waveform * * * * defines: * * IC global "servo_a3_pulse" -- servo pulselength in 500 ns. units * * IC function "servo_a3_init(int enable)" -- call with 1 to enable * * 0 to disable * * * * Fred Martin * * fredm@media.mit.edu * * 12 September 1996 * * modified from a5 to a3 * * by Gary Livick * * glivick@pacbell.net * * 17 November 1999 ************************************************************************* BASE EQU $1000 ; register base PORTA EQU $1000 ; Port A data register CFORC EQU $100B ; Timer Compare Force Register TCNT EQU $100E ; Timer Count Register TOC5 EQU $101E ; Timer Output Compare register 5 TCTL1 EQU $1020 ; Timer Control register 1 TMSK1 EQU $1022 ; main Timer interrupt Mask register 1 TFLG1 EQU $1023 ; main Timer interrupt Flag register 1 PACTL EQU $1026 ; Pulse Accumulator Control register TOC5INT EQU $E0 ; Timer Output Compare 5 vector SERVO_BIT EQU $08 ; PA3 bit SERVO_PORT EQU PORTA ; servo output port PULSE_DEFAULT EQU 2560 ; initial value when servo is turned on ORG MAIN_START * C variables variable_servo_a3_pulse FDB 0 * internal variables servo_a3_pulse FCB 0 ; if 0, generate gap subroutine_initialize_module: ldx #$bf00 * install toc3 interrupt routine ldd #servo_a3_int std TOC5INT,X ldd #PULSE_DEFAULT std variable_servo_a3_pulse ; initialize servo period clrb ; run "servo_disable" and * ; fall through ************************************************************************* subroutine_servo_a3_init: ldx #BASE tstb beq servo_disable servo_enable * begin with positive-going pulse ldd TCNT,X addd variable_servo_a3_pulse std TOC5,X ; set end of positive pulse bset TCTL1,X $03 ; on match, TOC5 goes high bset CFORC,X SERVO_BIT ; force a match bclr TCTL1,X $01 ; on match, TOC5 goes low bset TFLG1,X SERVO_BIT ; clear interrupt flag bset TMSK1,X SERVO_BIT ; enable TOC5 interrupt clr servo_a3_pulse ; tell int routine to make gap rts servo_disable bclr TMSK1,X SERVO_BIT ; disable TOC3 interrupt rts ************************************************************************* servo_a3_int ldx #BASE bclr TFLG1,X $FF-SERVO_BIT ; clear interrupt flag * if interrupt occured and bit is true, set up for falling edge tst servo_a3_pulse bne setup_pulse setup_gap ldd TOC5,X ; get falling edge time addd #40000 ; 20 ms later subd variable_servo_a3_pulse ; less length of pulse std TOC5,X ldaa #1 staa servo_a3_pulse ; next time make pulse rti setup_pulse ldd TOC5,X addd variable_servo_a3_pulse std TOC5,X ; set end of positive pulse bset TCTL1,X $03 ; on match, TOC5 goes high bset CFORC,X SERVO_BIT ; force a match bclr TCTL1,X $01 ; on match, TOC5 goes low clr servo_a3_pulse ; tell int routine to make gap rti ************************************************************************* Best regards, Gary Livick