• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

およそ20年前に、68HC05 の開発の練習に書いた車のブレイクライト・方向指示器コントローラです。


Commit MetaInfo

Revision59f3ed335f43973a07314214acc90f05997e2847 (tree)
Time2013-07-08 22:08:18
AuthorJoel Matthew Rees <reiisi@user...>
CommiterJoel Matthew Rees

Log Message

iCleaning up the flasher code,
discussion of potential problems using this in a real car.

Change Summary

  • delete: TURNSIG.AS6 => TURNSIG.ASM

Incremental Difference

--- a/TURNSIG.AS6
+++ b/TURNSIG.ASM
@@ -52,7 +52,25 @@
5252 * applications), and details of lamp driver circuits are mostly set
5353 * aside. The logic has been tested with the M68HC705KICS simulator
5454 * program, but has not been tested in a physical mock up or real
55-* vehicle.
55+* vehicle. (I ran out of time for this project.)
56+
57+******* Potential problems: ******************************************
58+
59+* I have not dealt with the problems that occur when the turn signals
60+* are turned on while the return sensors are within range of their
61+* actuator fields. Two more bits of port B would have allowed complete
62+* separation of the two functions. A little extra code might allow
63+* suppressing the turn signal inputs while both return switches are
64+* active, to reduce the operator frustration factor.
65+
66+* I have also mostly ignored the problems presented by shorted switches.
67+* Having the turn signal functions on port B is handy, because a week
68+* turn signal spring will not keep the circuit from staying in the STOP
69+* instruction. Another 50 bytes of ROM might have allowed tracking time
70+* of no change for every sensor, which could allow shutting out a
71+* sensor that has been active more than n minutes.
72+
73+**********************************************************************
5674
5775 * One of the intents of this design was to replace mechanical
5876 * parts (that tend to flow in hot climates and become brittle in cold)
@@ -273,6 +291,8 @@ NGN_SW equ B2 ; engine (ENG and EMG could be confusing)
273291 NGN_SW_ equ B2_
274292 DRVDRV equ B1
275293 DRVDRV_ equ B1_
294+EMG_BTF equ DRVDRV ; where to fold EMG_BT
295+EMG_BTF_ equ DRVDRV_
276296 CAN_BT equ B0
277297 CAN_BT_ equ B0_
278298 * PORTB
@@ -280,7 +300,7 @@ LFT_BT equ B1 ; a handy data dependency! DO NOT CHANGE
280300 LFT_BT_ equ B1_
281301 RGT_BT equ B0 ; another handy data dependency!
282302 RGT_BT_ equ B0_
283-* EMG_BT equ IRQ inverted
303+* IRQ input (inverted) is the real EMG_BT
284304
285305
286306 * logical input definitions for debounce and states
@@ -303,17 +323,26 @@ F_CAN_ equ {CAN_BT_ + 2}
303323 F_OPC equ $40 ; opposite direction cancel record
304324 F_MNC equ $80 ; manual cancel record
305325
326+* The turn signal table and many of the turn signal routines
327+* depend on F_LFT and F_RGT and LFT_BT and RGT_BT being in bits one and
328+* zero (but not particular which is which!). If these are changed,
329+* there will be a domino effect on the rest of the code.
330+
306331 SUBHEADER 'Resource Definitions'
307332 PAGE
308333
309334
310335 XTAL equ 1 ; crystal frequency, in MHz
311-RTIPOW equ 1 ; bits 1 & 0 for timer hardware
336+RTIPOW equ 0
337+* 1 ; bits 1 & 0 for timer hardware
312338 RTIRATE equ {2 < RTIPOW} ; 2 ^ RTIPOW
313-TIMOUT equ {9155*XTAL/RTIRATE+1} ; 5 minutes (if XTAL equ is correct)
339+TIMOUT equ 1
340+* {9155*XTAL/RTIRATE+1} ; 5 minutes (if XTAL equ is correct)
314341 * only one flash rate, 2/3 duty cycle
315-FLASH0 equ {32*XTAL/RTIRATE/4} ; about 1/4 second off time
316-FLASH1 equ {32*XTAL/RTIRATE/2} ; about 1/2 second on time
342+FLASH0 equ 1
343+* {32*XTAL/RTIRATE/4} ; about 1/4 second off time
344+FLASH1 equ 1
345+* {32*XTAL/RTIRATE/2} ; about 1/2 second on time
317346
318347 org MOR
319348 * Software Pulldown is used.
@@ -337,6 +366,9 @@ FLASH rmb 1 ; flash timer
337366 FLDARK rmb 1 ; flash light or dark state, 11111111 == dark
338367 FLMASK rmb 1 ; flash mask to communicate between BRK, EMG, and TRN
339368 TMPTRN rmb 1 ; temporary for keep turn signal interpretation
369+LASTST rmb 1 ; previous state record to separate timer from decode
370+ rmb 4
371+DBGCT rmb 4 ; count how many times TIMSRV has executed
340372
341373
342374 * ROM definitions follow:
@@ -430,12 +462,17 @@ TIMSRV bset TOFR_,TSCR
430462 lda DEBO
431463 sta DEBO+1
432464
465+* record previous STATE
466+ lda STATES
467+ sta LASTST
468+
433469 * read the static inputs, converting physical to logical
434470 lda PORTA
435471 and #{BRK_SW | NGN_SW | CAN_BT} ; clears DRV_DRV
436472 bih TMIEMG ; invert EMG and fold it in
437- ora #F_EMG
438-TMIEMG lsla ; remap
473+ ora #EMG_BTF ; keep temporally very close to first read
474+TMIEMG equ *
475+ lsla ; remap
439476 lsla
440477 sta DEBO
441478 lda PORTB ; PB2-7 always read 0
@@ -460,14 +497,17 @@ $CYCLE_ADDER_ON
460497 eor #{LFT_BT | RGT_BT} ; strobe other side
461498 sta PORTB ; set output state first
462499 sta DDRB ; handy (data dependent) output state, huh?
463- brset F_CAN_,PORTA,TMTBIT6 ; F_CAN into carry
500+ brset CAN_BT_,PORTA,TMTBIT6 ; CAN_BT_ into carry
464501 TMTBIT6 rora ; carry into bit 7
465502 clr DDRB ; kill strobe: manual cancel?
466- brset F_CAN_,PORTA,TMTBIT7 ; F_CAN into carry again
503+ brset CAN_BT_,PORTA,TMTBIT7 ; CAN_BT_ into carry again
467504 TMTBIT7 rora ; carry into bit 7 again
468505 and #{F_OPC | F_MNC}
469506 ora DEBO
470- sta DEBO
507+ bit #F_OPC ; ignore turn signals if opposition cancel
508+ beq TMTNTN
509+ and #{$FF ^ TURNSIG}
510+TMTNTN sta DEBO
471511 stx PORTB ; restore turn signal inputs
472512 stx DDRB
473513 TM0TURN equ *
@@ -527,11 +567,13 @@ TMF1CAN equ *
527567 TMF0BRK equ *
528568
529569 * toggle STATES F_EMG if TOGGLE F_EMG
570+* act on TOGGLE to avoid multiple reads of EMG button
530571 brclr F_EMG_,TOGGLE,TMF0EMG
531572 lda STATES
532573 eor #F_EMG
533574 sta STATES ; STATES not yet valid!
534-TMF0EMG bra TMSTRN ; skip over the turn signal states table
575+TMF0EMG equ *
576+ bra TMSTRN ; skip over the turn signal states table
535577 * leaves A indeterminate
536578
537579 swi ; since we have a few unused ROM locations
@@ -540,6 +582,7 @@ TMF0EMG bra TMSTRN ; skip over the turn signal states table
540582 swi
541583 swi
542584
585+* this table is very data dependent
543586 TURNSTATE equ * ; depends on turn signals being rightmost
544587 * S' S I
545588 fcb %00 ; 00 00
@@ -566,7 +609,7 @@ TURNSTATE equ * ; depends on turn signals being rightmost
566609 * Darn!
567610 * After careful consideration, I decided this table does not benefit
568611 * from a more symbolic construction. As it stands, it does not matter
569-* whether F_LFT or F_RGT is b0, only that both reside in B0 and B1.
612+* whether F_LFT or F_RGT is b0, only that they do reside in B0 and B1.
570613
571614 swi ; since we have a few unused ROM locations
572615 swi
@@ -594,7 +637,7 @@ TMSTRN lda STATES
594637 * leaves A == STATES
595638
596639 * cancel STATES turn signal if TOGGLE F_CAN is not filtered out
597-* Act here on TOGGLE to avoid multiple reads of single actuator pass!
640+* Act on TOGGLE to avoid multiple reads of single actuator pass!
598641 * A == STATES on entry
599642 brclr F_CAN_,TOGGLE,TMCAN0
600643 and #{$FF ^ TURNSIG}
@@ -604,11 +647,18 @@ TMCAN0 equ * ; turn signals are valid
604647
605648 * Now we should have no more than one turn signal on.
606649 * set up steering wheel return sense state or clear it
650+* then latch turn signal input to keep it from reverting
607651 * A == STATES on entry
608652 and #TURNSIG
609653 sta PORTB ; another handy value dependency!
610654 sta DDRB ; gate it out, if there
611-* A is trashed
655+* I feel there is a better way, but I'm out of time
656+ sta TMPTRN ; feed response back
657+ lda ISTATE
658+ and #{$FF ^ TURNSIG}
659+ ora TMPTRN
660+ sta ISTATE
661+* leaves A == ISTATE
612662
613663 * if not timed out, STATES F_NGN should not yet be clear!
614664 lda NGN_TIM+1
@@ -623,9 +673,8 @@ TMFNGN0 equ *
623673 SUBHEADER 'Timer Service Code -- Engine Time Out and Flasher Timers'
624674 PAGE
625675
626-TMCLOCK
627676 * reset engine time-out if F_NGN, F_EMG, or F_BRK TOGGLEs
628- lda TOGGLE
677+TMCLOCK lda TOGGLE
629678 and #{F_NGN | F_EMG | F_BRK}
630679 beq TMORST
631680 lda #{TIMOUT & $FF } ; reset value low byte
@@ -634,10 +683,28 @@ TMCLOCK
634683 sta NGN_TIM
635684 TMORST equ *
636685
686+* if flashers TOGGLE off, reset the flashers
687+* if they TOGGLE on, clear the mask only if none on before
688+ lda #{F_EMG | TURNSIG}
689+ bit TOGGLE
690+ beq TMSCLK
691+ bit STATES ; flasher active?
692+ bne TMMFLH
693+ lda #$FF ; reset flash timer
694+ sta FLDARK
695+ lda #FLASH1
696+ sta FLASH
697+ bra TMSCLK
698+
699+TMMFLH bit LASTST ; flashers already running?
700+ bne TMMFLH0 ; might be better to shine on every change?
701+ clr FLDARK
702+TMMFLH0 equ *
703+
637704 * Although the Real Time Interrupt is masked, the software clocks
638705 * clock on the RTI flag. See RTIPOW for the RTI flag rate
639706
640- brclr RTIF_,TSCR,TIMDUN
707+TMSCLK brclr RTIF_,TSCR,TIMDUN
641708 bset RTIFR_,TSCR
642709
643710 * Engine time-out counter only runs when the ISTATE F_NGN bit is
@@ -664,28 +731,32 @@ TMNGNR0 equ * ; Only now is STATES valid!
664731
665732 TMFLASH lda #{F_EMG | TURNSIG}
666733 bit STATES ; flasher active?
667- bne TMFLH1
668- lda #$FF ; reset flash timer
669- sta FLDARK
670- lda #FLASH1
671- sta FLASH
672- bra TMNFLH
673-
674-TMFLH1 dec FLASH
675- bne TMNFLH
734+ beq TMFLH0
735+ dec FLASH
736+ bne TMFLH0
676737 lda #FLASH1
677738 com FLDARK
678739 bpl TMFLTM ; result dark (1s) or light (0s)
679740 lda #FLASH0
680741 TMFLTM sta FLASH
681-TMNFLH equ *
742+TMFLH0 equ *
682743
683744 * It might be amusing to install a turn signal time out so that if
684745 * the turn signals remain flashing for more than ten minutes, they turn
685746 * themselves off. The entire mechanism should fit here. As mentioned
686747 * above, consider safety first!
687748
688-TIMDUN rti
749+TIMDUN
750+ inc DBGCT+3 ; count number of timer interrupts serviced
751+ bne TIMDUX ; put here strictly for debugging sessions
752+ inc DBGCT+2 ; so I can have an idea of virtual time
753+ bne TIMDUX
754+ inc DBGCT+1
755+ bne TIMDUX
756+ inc DBGCT
757+TIMDUX
758+ bset IRQR_,ISCR ; POTA and IRQ activity may set IRQF
759+ rti
689760 $CYCLE_ADDER_OFF
690761
691762 swi ; more unused ROM
@@ -706,9 +777,15 @@ SWISRV
706777 ldx #$5C ; unique
707778 stx COPR
708779 rsp ; now falls through to RSTSRV
780+ bset IRQR_,ISCR ; it just gets us started
709781
710782 * general inits
711-RSTSRV lda #DRVLMPS
783+RSTSRV
784+* disable external interrupts
785+ bclr IRQE_,ISCR ; disable external interrupts
786+ bset IRQR_,ISCR ; clear the external interrupt flag
787+* get ports stared right
788+ lda #DRVLMPS
712789 sta PORTA ; initial output values
713790 lda #{DRVLMPS | DRVDRV}
714791 sta DDRA ; set up directions
@@ -717,18 +794,8 @@ RSTSRV lda #DRVLMPS
717794 clr DDRB ; B initially input
718795 clr PDRB ; with pull downs set
719796 * make sure EPROM programming stuff is out of the way
720- clr EPROG ; ICS05K complains, skip by hand
797+* clr EPROG ; ICS05K complains, skip by hand
721798 clr PESCR
722-* disable external interrupts
723- bclr IRQE_,ISCR
724- bset IRQR_,ISCR ; clear the flag
725-* set up hardware timer
726- ldx #$6A ; unique use of X
727- stx COPR ; b0 clear, about to change timer rate
728- lda #{TOIE | RTIPOW} ; only timer overflow interrupts
729- sta TSCR ; RTIPOW has the timer rate
730- ora #{TOFR|RTIFR} ; clear the flags
731- sta TSCR
732799 * set up specific variables
733800 lda #F_NGN ; pretend the engine is on, to get us started
734801 sta DEBO ; start debounce chain clear
@@ -743,6 +810,19 @@ RSTSRV lda #DRVLMPS
743810 sta FLDARK ; initial flash state is dark
744811 lda #FLASH1
745812 sta FLASH ; initial flash time is on/light state
813+* clear the virtual debugging time counter
814+ clr DBGCT
815+ clr DBGCT+1
816+ clr DBGCT+2
817+ clr DBGCT+3
818+* set up hardware timer
819+ ldx #$6A ; unique use of X
820+ stx COPR ; b0 clear, about to change timer rate
821+ lda #{RTIPOW} ; set rate
822+ sta TSCR
823+ ora #{TOFR | RTIFR} ; clear pending interrupts
824+ sta TSCR
825+ bset TOIE_,TSCR ; first section overflow interrupt only
746826
747827 * Falls through to DOSTATES
748828
@@ -830,18 +910,18 @@ STT0FLH equ *
830910
831911 * go to power conserving state
832912 * first shut down all lamps
833- lda #DRVLMPS ; DRVDRV also off!
834-* should be lda #{DRVLMPS & ~DRVDRV} for maximum clarity
835- sta PORTA
913+ lda #DRVLMPS ; DRVDRV, CAN_BT also off!
914+* should be lda #{DRVLMPS & ~DRVDRV & ~CAN_BT} for clarity
915+ sta PORTA ; don't feed CAN_BT to pull downs
836916 * now make sure power down state is valid!
837- lda #{DRVLMPS | DRVDRV}
838- sta DDRA ; set up directions
917+ lda #{DRVLMPS | DRVDRV | CAN_BT}
918+ sta DDRA ; interrupts only from NGN_SW, BRK_SW, EMG_BT
839919 sta PDRA ; pull downs only on inputs
840920 clr PORTB ; initial outputs (do port B just in case)
841921 clr DDRB ; B initially input
842922 clr PDRB ; with pull downs set
843923 * make sure EPROM programming stuff is out of the way
844- clr EPROG ; ICS complains, skip by hand
924+* clr EPROG ; ICS complains, skip by hand
845925 clr PESCR
846926 * enable external interrupts
847927 bset IRQE_,ISCR ; DO NOT clear the flag (don't miss anything)
@@ -850,12 +930,6 @@ STT0FLH equ *
850930 swi ; more unused ROM
851931 swi
852932 swi
853- swi
854- swi
855- swi
856- swi
857- swi
858- swi
859933
860934 SUBHEADER 'Interrupt Vectors'
861935 PAGE