HC908JK1 HC908JK3 JL3 JL8
Assembler
flashing light left
All leds are illuminated, because the looptime is only 14 microseconds
******* Orgler electronic  ********
* flashing light left *************
PORTB   EQU $0001
DDRB    EQU $0005
CONFIG1 EQU $001F

          org    $F000
START     mov   #$01,CONFIG1    ; disable COP
          mov   #$FF,DDRB       ; Set all outputs

LOOP      mov   #$01,PORTB
          mov   #$02,PORTB
          mov   #$04,PORTB
          mov   #$08,PORTB
          mov   #$10,PORTB
          mov   #$20,PORTB
          mov   #$40,PORTB
          mov   #$80,PORTB
          jmp   LOOP

          org $FFFE
          dw  START                   ; Reset Vector

* the periode is 14,17 µsec; Quarz 9,8304 Mhz
flashing light left with delays
******* Orgler electronic  ********
* flashing light left *************
PORTB  EQU $0001
DDRB   EQU $0005
CONFIG1 EQU $001F

          org    $F000
START     mov   #$01,CONFIG1    ; disable COP
          mov   #$FF,DDRB       ; Set all outputs

LOOP      mov   #$01,PORTB

          ldhx  #$0     
nextx1    aix   #1
          cphx  #30000T
          bne   nextx1

          mov   #$02,PORTB

          ldhx  #$0
nextx2    aix   #1
          cphx  #30000T
          bne   nextx2

          mov   #$04,PORTB

          ldhx  #$0
nextx3    aix   #1
          cphx  #30000T
          bne   nextx3

          mov   #$08,PORTB

          ldhx  #$0
nextx4    aix   #1
          cphx  #30000T
          bne   nextx4

          mov   #$10,PORTB

          ldhx  #$0
nextx5    aix   #1
          cphx  #30000T
          bne   nextx5

          mov   #$20,PORTB

          ldhx  #$0
nextx6    aix   #1
          cphx  #30000T
          bne   nextx6

          mov   #$40,PORTB

          ldhx  #$0
nextx7    aix   #1
          cphx  #30000T
          bne   nextx7

           mov   #$80,PORTB

          ldhx  #$0
nextx8    aix   #1
          cphx  #30000T
          bne   nextx8

          jmp   LOOP

          org $FFFE
          dw  START                   ; Reset Vector
flashing light left with delays
******* Orgler electronic  ********
* flashing light left *************
PORTB  EQU $0001
DDRB   EQU $0005
CONFIG1 EQU $001F

          org    $F000
START     mov   #$01,CONFIG1    ; disable COP
	  rsp			; reset stack pointer 
          mov   #$FF,DDRB       ; Set all outputs

LOOP	  mov   #$01,PORTB
	  jsr	Delay	
          
          mov   #$02,PORTB
	  jsr	Delay	
          
          mov   #$04,PORTB
	  jsr	Delay	
          
          mov   #$08,PORTB
	  jsr	Delay	
          
          mov   #$10,PORTB
	  jsr	Delay	
          
          mov   #$20,PORTB
	  jsr	Delay		
          
          mov   #$40,PORTB
	  jsr	Delay	
          
          mov   #$80,PORTB
	  jsr	Delay	

          jmp   LOOP


Delay	  ldhx  #$0				     ; Subroutine
nextx     aix   #1
          cphx  #30000T
          bne   nextx
          rts
	   

          org $FFFE
          dw  START                   ; Reset Vector
flashing light left with delays
******* Orgler electronic  ************************
* flashing light left shift operation *************
PORTB    EQU $0001
DDRB     EQU $0005
CONFIG1  EQU $001F

          org   $F000
START     mov   #$01,CONFIG1    ; disable COP
          mov   #$FF,DDRB       ; Set all outputs
                
INIT      mov   #$01,PORTB

LOOP
          ldhx  #$0             ;delaytime
next_x    aix   #1
          cphx  #$8FFF
          bne   next_x

          lsl   PORTB
          beq   INIT
          BRA   LOOP

          ORG  $FFFE
          dw   START                   ; Reset Vector
flashing light left with delays
******* Orgler electronic  ******************************
* flashing light left shift and delay as subroutine *****
PORTB    EQU $0001
DDRB     EQU $0005
CONFIG1  EQU $001F

          org   $F000
START     mov   #$01,CONFIG1    ; disable COP
          mov   #$FF,DDRB       ; Set all outputs
                
INIT      mov   #$01,PORTB

LOOP	  jsr	DELAY
          lsl   PORTB
          beq   INIT
          BRA   LOOP

DELAY	  ldhx  #$0             ;subroutine
next_x    aix   #1
          cphx  #30000T
          bne   next_x
          rts


          ORG  $FFFE
          dw   START                   ; Reset Vector
flashing light left and right
the variable "direction" controls left or right

******* Orgler electronic  ****************************
* flashing light left and right   *************
PORTB    EQU $0001
DDRB     EQU $0005
CONFIG1  EQU $001F

		org   $0080
direction ds  1

		org     $F000
START           mov     #$01,CONFIG1     ; disable COP
                mov     #$FF,DDRB
                mov     #$01,PORTB
                mov     #$0,direction

LOOP
		ldhx    #60000T
next_delay      aix     #-1			; decrement H:X
                cphx    #0
                bne     next_delay

                tst     direction
                bne     GO_RIGHT
                lsl     PORTB
                bne     SHIFT_OKAY
                mov     #$80,PORTB              ; init right
                mov     #1,direction
                bra     SHIFT_OKAY

GO_RIGHT        lsr     PORTB
                bne     SHIFT_OKAY
                mov     #$01,PORTB              ; init left
                mov     #0,direction

SHIFT_OKAY
                JMP     LOOP


		ORG  $FFFE
		dw   START                   ; Reset Vector
2 Looptime
PORTD   EQU $0003
DDRD    EQU $0007
CONFIG1 EQU $001F
TSC     EQU $0020    
TSC0    EQU $0025

          org    $F000
START     mov   #$01,CONFIG1    ; disable COP
          mov   #$FF,DDRD       ; Set all outputs
          mov   #$30,TSC        ; Timer STOP and RESET
          mov   #$14,TSC0       ; set TIMER action 
          mov   #0,TSC          ; start the TIMER
                
                
LOOP      lda   PORTD
          eor   #$FF
          sta   PORTD              
          bra   LOOP            
          

          org $FFFE
          dw  START                   ; Reset Vector

;PORTD BIT [PIN 19] output frequency 18,8 Hz
;PORTD BIT [PIN ] output frequency 112 KHz
Loop time is set to 10 msec
PORTD   EQU $0003
DDRD    EQU $0007
CONFIG1 EQU $001F
TSC     EQU $0020    
TSC0    EQU $0025
TCH0H   EQU $0026    
TCH0L   EQU $0027

          org    $F000
START     mov   #$01,CONFIG1    ; disable COP
          mov   #$30,TSC        ; Timer STOP and RESET
          mov   #$14,TSC0       ; set TIMER action: toggle on output compare
          mov   #0,TSC          ; start the TIMER
                
LOOP      lda   TSC0
          bpl   LOOP            ; wait until BIT7 is set       
          and   #$7F
          sta   TSC0            ; clear the CH0F flag
          lda   TCH0H
          add   #$60
          sta   TCH0H           ; add $6000 
          mov   #0,TCH0L        ; write to low byte 
 
          bra   LOOP            

          org $FFFE
          dw  START                   ; Reset Vector

;PORTD BIT [PIN 19] output frequency 50 Hz
Looptime LED blinking 0,5sec
PORTD   EQU $0003
DDRD    EQU $0007
CONFIG1 EQU $001F
TSC     EQU $0020    
TSC0    EQU $0025
TCH0H   EQU $0026    
TCH0L   EQU $0027

                org   $0080           ; RAM address
count1          ds    1                

                org    $F000
START           mov   #$01,CONFIG1    ; disable COP
                mov   #$04,DDRD
                mov   #$30,TSC        ; Timer STOP and RESET
                mov   #$14,TSC0       ; set TIMER action: toggle on output compare
                mov   #0,TSC          ; start the TIMER
                
LOOP            lda   TSC0
                bpl   LOOP            ; wait until BIT7 is set       
                and   #$7F
                sta   TSC0            ; clear the CH0F flag
                lda   TCH0H
                add   #$60
                sta   TCH0H           ; add $6000 
                mov   #0,TCH0L        ; write to low byte 
;               =================
                lda   count1
                inca      
                cmp   #50T            ; T = decimal
                blo   SAVE_COUNT1
                lda   PORTD
                eor   #$04
                sta   PORTD           ; toggle       
                clra                
SAVE_COUNT1     sta     count1     
;               ================= 
                bra   LOOP            

                org $FFFE
                dw  START                   ; Reset Vector

;PORTD BIT [PIN 19] output frequency 50 Hz
;PORTD BIT [PIN 17] output frequency  1 Hz
MEASURING RPM of a wheel
Measuring the RPM of a wheel using a proximity sensor
To count the rotation in an amount of time (e.g. one second)
can be a method, but this is not very exact.
It is better to measure the period of the signal
and then to calculate the frequency or the RPM.
The time between two rising or falling edges multiplied
by the time for one clock is the period of the signal. 
One possibility is to program an interrupt if an edge occurs,
but it is more sophisticated to program a periodic interrupt
and polling the flag for the edge.

In this way we can also measure a very long period.

Our RPM.ASM program has also another very important feature.
This controller has no SCI, but with the periodic interrupt
of 104µsec there is an emulated SCI with a baud rate of 2400.
It uses the same pin (PB0) for uploading the program in the controller,
so you can use the same hardware tool to upload the S19-file.

The Win program WINLX.EXE opens the file “rampage.inc” to have
all information about the content of RAM, sends two bytes to the
controller and expects them with other 64 bytes back.  

With this program and the emulated SCI in the controller
you can continuously observe the content of RAM
and of all the registers or ports.

In this first example we measure only the time between two edges.
The input square wave is connected with PIN 18 (PD5) Timer channel 1
Crystal 9,8304 MHz /2 = Busfreq     1/freq -> 406,901 nsec
Prescaler value 4:    1 clock = 1,6276µsec (406,9 x 4)
 
Example of input frequency : 100 Hz periode 10msec or 10.000 µsec
10.000 / 1,6276 = 6.144

With the WINLX.EXE we can see the value in the 16 Bit 
variable DIFF1_TIC hex 1802 or decimal 6146.


download assembler source files
download the WINLX.EXE program
PWM generation
*** Orgler electronic  PWM generation*****
RAMStart       EQU  $0080

PORTD   EQU $0003
DDRD    EQU $0007
CONFIG1 EQU $001F    ; System configuration register
TSC     EQU $0020      ; Timer
TCNTH   EQU $0021
TCNTL   EQU $0022
TMODH   EQU $0023
TMODL   EQU $0024
TSC0    EQU $0025
TCH0H   EQU $0026
TCH0L   EQU $0027
TSC1    EQU $0028
TCH1H   EQU $0029
TCH1L   EQU $002A

               org RamStart
LedCounter      ds  2        

                 org $F000
*********************************************************************
START             rsp
                  mov     #$01,CONFIG1
*----------------------------------------------------------------
                  mov    #%10000000,PORTD
                  lda    #%11000000
                  sta    DDRD
*--------------------------------------------
                
                  mov    #$32,TSC      ; Timer A - Cleared + Stopped.
                  ldhx   #$0100
                  sthx   TMODH       

                  ldhx  #$0040        ;duty cycle of 25%
                  sthx   TCH0H

                  mov   #$1A,TSC0
;  CH0F CH0IE MS0B MS0A ELS0B ELS0A TOV0 CH0MAX
;   0     0    1     1    0     1     0     0   $34 toggle
;   0     0    0     1    1     0     1     0   $1A clear
;   0     0    0     1    1     1     1     0   $1E set
; if TOV==1 toggle on Timer Overflow TOV                   

                  mov   #$02,TSC   ; Start the timer -> prescaler 4
**********************************************************************
**********************************************************************
LOOP            
*               ---------- blink led PTD6(PIN10)  and PTD7 (PIN 9) ----
                 ldhx   LedCounter
                 aix    #-1
                 cphx   #0       
                 bne    SaveLedCounter 
                 lda    PORTD
                 eor    #%11000000
                 sta    PORTD
*                ---
                 ldhx   #$4000
SaveLedCounter   sthx   LedCounter
*               ----------------------
                 jmp     LOOP
**************************************************************
        
                org $FFFE
        dw  START        ; Reset Vector
TRIAC control 50Hz 230Volt
The hardware must provide a zerocross circuit,PD5 PIN18
output drives a photo coupler PD4 PIN 19
RAMStart       EQU  $0080
RomStart       EQU  $F000       ;Valid for all JL3, JK3, JK1

$Include 'jl3regs.inc'          ; for the 68HC908JK3 JK1 JL3

OFF_VALUE  EQU 23500T

                ORG RAMStart       
TIMEBASE    ds   1
iCount      ds   1
iDelta      ds   1
ONTIME      ds   2


              org RomStart

**************************************************************
* START - This is the point where code starts executing  *
*             after a RESET.                                 *
**************************************************************
START:  mov #$01,CONFIG1          ;COPD=1 (cop disabled)
        rsp
        mov  #%00000000,PORTD     ; Led to control
        mov  #%01010000,DDRD      ; Led output and PD4 Triac Signal

        mov    #$FF,iCount  ; minus=>decrement plus=increment
        mov    #5,iDelta
        ldhx   #OFF_VALUE
        sthx   ONTIME       ;

;-------------------------
        mov   #$30,TSC     ; Timer A - Cleared + Stopped.
        mov   #$48,TSC1    ; INPUT CAPTURE, Interrupt (INT_ZEROCROSS)
                           ; capture on falling edge
        mov   #$0,TSC      ; Start the timer  
        bclr  7,TSC1
        cli                 ; Allow interrupts to happen
;------------------------------------

*************************************************************
LOOP:   brclr  7,TIMEBASE,LOOP
        bclr   7,TIMEBASE

        lda     iCount
        bmi     DECREMENT

        lda     ONTIME+1
        add     iDelta
        sta     ONTIME+1
        lda     ONTIME
        adc     #0
        sta     ONTIME
        ldhx    ONTIME
        cphx    #OFF_VALUE
        blo     INC_OKAY
        mov     #$FF,iCount
INC_OKAY:
        BRA     RAMP_OKAY

DECREMENT:
         lda     ONTIME+1
         sub     iDelta
         sta     ONTIME+1
         lda     ONTIME
         sbc     #0
         sta     ONTIME
         ldhx    ONTIME
         cphx    #1500T
         bhi     RAMP_OKAY
         mov     #1,iCount
RAMP_OKAY:
         jmp     LOOP
**************************************************************




********* Interrupt-Function *********************************
INT_ZEROCROSS:
        pshh

        mov   #$30,TSC        ; Timer A - Cleared + Stopped.
        mov   #$10,TSC0       ; pin under port control
                              ; initialize timer output level low
*       ------------
        bclr  7,TSC1          ; reset interrupt flag
*       -------------
        ldhx  ONTIME          ; set time to start the ON-IMPULS
        sthx  TCH0H

        mov   #$14,TSC0        ;Timer Ch1 Output compare,toggle, no interrupt
                               ; output on PD4 PIN19
        mov   #0,TSC           ; start the timer now

        lda    PORTD
        eor    #$40
        sta    PORTD           ; Led output to control zerocross
        
        mov    #$FF,TIMEBASE   ; set for looptime 10 msec

        pulh
        rti
**************************************************************

        
            ORG $FFF4
        dw  INT_ZEROCROSS  ; TIM1 Channel 1 Vector  PD5 PIN 18 
       
            ORG $FFFE
        dw  START          ; Reset Vector

Schematic with MC68HC08JK3 or MC68HC08JK1
the examples are tested with this board