Microcontroller, 68HC11A1, 68HC11, 68HC811, HC11...
Orgler electronic
"Applications with microcontroller HC11"



  1. PID-Control with 68HC11
  2. STEPPER CONTROL
  3. 68HC11 read encoder
  4. High accuracy RPM-measurement with 68HC11

The HC11 controls the stepper
return to 68HC11 top


STEPPER1.GIF

********* A SIMPLE STEPPER PROGRAMM ************
PORTB   EQU	$1004
TFLG1   EQU 	$1023
TOC3    EQU 	$101A

BIT5	EQU	00100000B

		ORG	$0

NR_STEPS	RMB	2
PTR_PATTERN     RMB	1

		 ORG $B600

                LDS	#200
		clr	PORTB
                clr	PTR_PATTERN
                ldd	#5000
                std     NR_STEPS
*********************************************************
LOOP            jsr	REALTIME       \
		jsr     STEPPER_GO       loop with 5 msec duration
                jmp	LOOP           / 
*---------------------------------------
REALTIME        LDAA 	#BIT5 		wait for Real Time
WAIT_REAL	BITA 	TFLG1
		BEQ     WAIT_REAL
	 	STAA	TFLG1  		reset TOC3
*		----------------------
		LDD	TOC3
		ADDD	#10000             5 msec
		STD	TOC3
                rts
************************************************************
STEPPER_GO_EXIT clr	PORTB
		rts
STEPPER_GO	ldx     NR_STEPS
                beq     STEPPER_GO_EXIT
                dex
                stx     NR_STEPS	NR_STEPS--
*		------------------
*		ldx	#HALF_STEP	locked
                ldx	#FULL_STEP	unlocked
                ldab    PTR_PATTERN
                abx
                ldaa	X
                staa	PORTB
                incb
                andb	#00000111B	count 0 to 7
                stab    PTR_PATTERN
		rts
**************** PATTERN **************************
HALF_STEP	FCB	00010000B
		FCB	00110000B
                FCB	00100000B
                FCB	01100000B
                FCB	01000000B
		FCB	11000000B
                FCB	10000000B
                FCB	10010000B

FULL_STEP       FCB	00010000B
		FCB	00100000B
                FCB	01000000B
                FCB	10000000B
                FCB	00010000B
		FCB	00100000B
                FCB	01000000B
                FCB	10000000B
*******************************************************


The HC11 read the encoder
return to 68HC11 top

ENCODER1.GIF

encoder.zip (ca. 2600 Bytes)
ZEROPAGE.INC
ENCODER.ASS
SERIAL.INC

The encoder is connected to PORTA PA0 and PA1
The board must be in BOOTSTRAB MODE (tested with Loggyboard)
********** listing from encoder.ass **************
$ZEROPAGE.INC

PORTA	EQU $1000
PORTD   EQU $1008
DDRD    EQU $1009
TOC3    EQU $101A
TFLG1   EQU $1023

SPCR    EQU $1028
BAUD    EQU $102B
SCCR1   EQU $102C
SCCR2   EQU $102D
SCSR    EQU $102E
SCDR    EQU $102F

BIT5    EQU 00100000B
BIT6    EQU 01000000B

		ORG 	$B600

		LDS	#200           Load Stackpointer
		JSR	RS_INIT        RS232 INIT
		LDD	#0
		STD	ENC_COUNT      set to zero
                clr	ERRORFLAG
		JSR	SET__MASK      init MASK ENC_PLUS and ENC_MINUS
***********************************************************************
LOOP            JSR	REALTIME	 loop time 0,5 msec
		JSR	ENCODER
*		------------------
		LDX	PTR_SERIAL
		JSR	X
*		------------------
		jmp	LOOP
*------------------------------------------
REALTIME	LDAA 	#BIT5 		wait for Real Time Interrupt
WAIT_REAL2	BITA 	TFLG1
		BEQ     WAIT_REAL2
	 	STAA	TFLG1
*		----------------------
SetToc3		LDD	TOC3
		ADDD	#1000           0,5 msec
		STD	TOC3
*		--------------------
		RTS
***************************************************
SET__MASK     	LDAA	PORTA
		ANDA	#00000011B
		STAA	ENC_LAST
                bra	SET_MASK2
********************************************
ENCODER         LDX	ENC_COUNT
		LDAA	PORTA
		ANDA	#00000011B      isolate input bits
		CMPA	ENC_LAST
		BEQ	ENCODER_EXIT	if equal then exit

		STAA	ENC_LAST        save value for next cycle
		CMPA	ENC_PLUS        Increment or decrement ?
		BEQ	ENCODERPLUS
                CMPA	ENC_MINUS
                BEQ     ENCODERMINUS
                LDAA	#1		if error 
                STAA	ERRORFLAG
ENCODER_EXIT    RTS

ENCODERMINUS    DEX
		BRA	SAVE_ENC_COUNT
ENCODERPLUS     INX
SAVE_ENC_COUNT	STX	ENC_COUNT

SET_MASK2	LDAA	ENC_LAST	The mask are only the next expected value
		BEQ	MASK_01
		CMPA	#00000011B
		BEQ	MASK_01

MASK_10         EORA	#00000010B
		STAA	ENC_PLUS
		LDAA	ENC_LAST
		EORA    #00000001B
		STAA	ENC_MINUS
                RTS

MASK_01		EORA	#00000001B
		STAA	ENC_PLUS
		LDAA	ENC_LAST
		EORA    #00000010B
		STAA	ENC_MINUS
                RTS
*****************************************************
$SERIAL.INC


PID Motor control
return to 68HC11 top

PID1.GIF




High accuracy RPM measurement
return to 68HC11 top

RPM.GIF