Hey Arfin. I finally got a servo working on my Microstamp11.
I'm going to post the code here for you, but you should read the following notes if you plan to port the code to your micro. Your 68HC11 is very likely to be an E model or other, and not a D. Therefore the code won't work without some small changes.
The MS11 runs a 68HC11D0 (no internal program memory) and gives up two of its ports as address/data bus for 32K of EEPROM in expanded mode. It has only Ports A and D available to the user.
MS11 program memory starts at $8000. Yours is probably $b600.
MS11 is clocked at 9.8304MHz. Yours is probably 8MHz.
The MS11 register block is mapped at $00 to $3f. Yours is probably mapped at $1000 to $103f.
MS11 RAM is mapped from $40 to $ff. 192 bytes. Can't remember if other HC11's have the same or more. The location is almost certainly different though.
This was Tom Dickens code, but I have heavily modified it to suit. I'm only using OC2 (PA6) to control one servo. Put an LED with current limiting resistor on PD4 - anode to PD4. It will light when the servo is rotated CCW and turn off when servo is rotated CW. It just goes back and forth forever. Does nothing useful at present.
My servo may be different than yours. Listen to it carefully when it's at the ends of its travel. If it's stalling at either end you'll have to modify the numbers I'm stuffing into TOC2 in main:. Mine stops a bit before the end stops at each end.
If you want the include file just ask. You'd have to modify it to suit your register block mapping (no biggy).
Here's a couple pics. The MS11 and breadboard are mounted on an old robot base:
**broken link removed**
**broken link removed**
Code:
#include register.inc
ORG $8000
start: ldaa #4 ;disable COP in CONFIG register
staa CONFIG
lds #$00ff ;stack pointer = top of ram
ldaa #$ff ;PORTD all outs
staa DDRD
ldaa #$00 ;init interrupts
staa OC1M ;Out compares off
staa TCTL2 ;In captures off
staa TMSK1 ;Timer interrupts
ldaa #$FF
staa TFLG1 ;Clear interrupts
ldaa #$F0
staa TCTL1 ;T2 T3, set to 1
ldaa #$60
staa CFORC ;Force T2 T3 to 1
ldaa #$50
staa TCTL1 ;T2 T3 set toggle
ldaa #$80
staa TMSK2 ;Timer o-flow int
staa TFLG2 ;Clear interrupt
cli ;Enable interrupts
main: ldx #$14ff ;servo full CCW
stx TOC2 ;Set Timer 2
bset PORTD,4 ;LED on
ldy #$00ff ;delay
bsr delay
ldx #$0580 ;servo full CW
stx TOC2
bclr PORTD,4 ;LED off
ldy #$00ff ;delay again
bsr delay
bra main
delay: ldx #$0fff ;inner delay loop
delay2: dex
bne delay2
dey
bne delay
rts
isr: ldaa #$00
staa TCTL2 ;In captures off
ldaa #$F0
staa TCTL1 ;T2 T3, set to 1
ldaa #$60
staa CFORC ;Force T2 T3 to 1
ldaa #$50
staa TCTL1 ;T2 T3 set toggle
ldaa #$80
staa TFLG2 ;Clear interrupt flag
rti
* Interrupt and reset vectors.
org $FFD6
SCI_VECT fdb start ;ffd6
SPI_VECT fdb start ;ffd8
PAI_VECT fdb start ;ffda
PAO_VECT fdb start ;ffdc
TOF_VECT fdb isr ;ffde
TOC5_VECT fdb start ;ffe0
TOC4_VECT fdb start ;ffe2
TOC3_VECT fdb start ;ffe4
TOC2_VECT fdb isr ;ffe6
TOC1_VECT fdb start ;ffe8
TIC3_VECT fdb start ;ffea
TIC2_VECT fdb start ;ffec
TIC1_VECT fdb start ;ffee
RTI_VECT fdb start ;fff0
IRQ_VECT fdb start ;fff2
XIRQ_VECT fdb start ;fff4
SWI_VECT fdb start ;fff6
TRAP_VECT fdb start ;fff8
COP_FAIL_VECT fdb start ;fffa
COP_CMF_VECT fdb start ;fffc
RESET_VECT fdb start ;fffe