chiark / gitweb /
clock speed varies
authorian <ian>
Sat, 26 Nov 2005 13:33:28 +0000 (13:33 +0000)
committerian <ian>
Sat, 26 Nov 2005 13:33:28 +0000 (13:33 +0000)
21 files changed:
cebpic/Makefile
cebpic/i2c-test.asm
cebpic/led-flash.asm
cebpic/nmra-stream.asm
cebpic/panic.asm
cebpic/reply-serial.asm
cebpic/routines-led.asm
cebpic/send-serial.asm
detpic/Makefile
detpic/common.inc
detpic/final.inc
detpic/i2clib.asm
detpic/misc.asm [new file with mode: 0644]
detpic/misc.fin [new file with mode: 0644]
detpic/nmra-stream.asm
detpic/panic.asm
detpic/test-sofar.asm
iwjpictest/clockvaries.inc
iwjpictest/flasher.asm
iwjpictest/harness.asm
pic.make

index 6f418fc51c7a95841079a9471c08ee315a01c91d..0002a2abb52c4ee6dae353a85d9d8e24585fedfd 100644 (file)
@@ -3,8 +3,11 @@ CEBPIC=                ./
 PICNOS=                0 1 3
 
 PROGRAMS=      led-flash send-serial panic reply-serial        \
-               nmra-stream nmra-stream,slow tblrd_test         \
-               i2c-test i2c-test,slow
+               nmra-stream nmra-stream,slow
+
+# These programs haven't been updated to cope with
+# master and slave pics having different clock speeds:
+#              i2c-test i2c-test,slow tblrd_test
 
 ROUTINES=      routines-led
 LIBS=          routines.lib                            
index 8099e97467bba718ca5352f093c850df1b7f04aa..ee756ab39e55bbb26f5c62e22a0be4edc1dedea4 100644 (file)
@@ -26,8 +26,8 @@
 ; boilerplate:
 
         include         /usr/share/gputils/header/p18f458.inc
-        include         ../iwjpictest/clockvaries.inc
        radix           dec
+        include         ../iwjpictest/clockvaries.inc
 
        extern  led_green
        extern  led_red
index 0a79e35757e556c165f5e025badadf91e8ae5a91..c6d3863b7d77356b64c64c42253d203c13e2f438 100644 (file)
@@ -1,6 +1,9 @@
 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
 
         include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
+
+clock equ mclock
        include         ../iwjpictest/clockvaries.inc
 
        code
@@ -8,9 +11,7 @@ start
 ; pin initial config
        bcf     TRISE,4,0       ; turn off PSPMODE (Data Sheet p100/101)
 ; timer initial config
-       bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode     
-       bcf     T0CON,5,0       ; timer0 use internal clock
-       bsc_morse_t0con_012     ; use prescaler? and configure it
+       morse_t0setup mclock, (1<<TMR0ON), -1, -1
 ; actually do stuff
        call    green
        call    waiting
index 0f6b266fdee587b5c9f30cde3a2470db22e3e973..e56fe9ff8fa5d459ee7aae3f74bbbd62dc1997f5 100644 (file)
@@ -14,6 +14,9 @@
 
 
         include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
+
+clock equ mclock
        include         ../iwjpictest/clockvaries.inc
 
 
index 9e1ac2cc08bb62d83c2adb087717ea813587fb5b..9eff1f112278e09234579dc25978d7effd68511a 100644 (file)
@@ -9,6 +9,8 @@
 ; 10 10 10 00 | 1110 1110 | 1110 00 10 | 10 10
 
        include common.inc
+
+clock equ mclock
        include ../iwjpictest/clockvaries.inc
 
        extern  led_green
@@ -201,9 +203,7 @@ informative_panic
 
 
 ; re-initialise timer0 config
-        bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode
-        bcf     T0CON,5,0       ; timer0 use internal clock
-       bsc_morse_t0con_012     ; use prescaler? and configure it
+       morse_t0setup mclock, (1<<TMR0ON), -1, -1
 
        clrf    BLANK,0
 panic_loop
index 037ef823c2e61a87bc9965aafc922bfb8a7920f8..58cc7a9ba1bab796f4ae7bc4b2398bbb91bf5fa1 100644 (file)
@@ -1,6 +1,9 @@
 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
 
         include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
+
+clock equ mclock
        include         ../iwjpictest/clockvaries.inc
 
        extern  led_green
@@ -49,10 +52,7 @@ initialise_serial
 
 
 ; timer0 initial config
-        bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode
-        bcf     T0CON,5,0       ; timer0 use internal clock
-       bcf     INTCON,5,0      ; clear TMR0IE => mask interrupt
-       bsc_morse_t0con_012     ; use prescaler? and configure it
+       morse_t0setup mclock, (1<<TMR0ON), -1, -1
 
 main
        call    led_green
index c405e05ebdf3c72a6349eb5ae48e6bc5a079e99d..895b89af63be3204f415dcba82fd020046e9b2e6 100644 (file)
@@ -2,6 +2,7 @@
 ; routines-led
 ; subroutines for controlling the per-pic LED (pin 21, DS100)
 
+clock equ -1
        include         common.inc
 
        global  led_green
index 1d1b148dae799e791513a6022669d427f78ab87a..177c5dbe88d5de2c139ba9a1cfd77f2ded42b5ac 100644 (file)
@@ -1,6 +1,9 @@
 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
 
         include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
+
+clock equ mclock
        include         ../iwjpictest/clockvaries.inc
 
        code
index 04d3e90f71349b2c668e858218fbe33867450f77..48d4716c49efca94b9b5488d2452f0cdf2ae8d15 100644 (file)
@@ -3,13 +3,14 @@ CEBPIC=               ../cebpic/
 PICNOS=                0 1 2
 
 PROGRAMS=              test-sofar
-OBJS_test-sofar=       vectors.o panic.o routines-led.o i2clib.o
+OBJS_test-sofar=       vectors.o panic.o routines-led.o i2clib.o misc.o
 XCODEN_test-sofar=     morse
 XCODE1_test-sofar=     blank2 blank6
 
 INCLUDES=      common.inc              \
                final.inc               \
                i2clib.inc              \
+               misc.fin                \
                panic.fin               \
                panic.inc               \
                routines-led.fin        \
index 473d420b47f7aca56ed3eb42db10f79563f463aa..1796daf43141156017a319f7f0752f3c5d159bff 100644 (file)
@@ -9,6 +9,7 @@
        include         panic.inc
        include         morse+auto.inc
        include         ../iwjpictest/insn-aliases.inc
+clock equ -1
        include         ../iwjpictest/clockvaries.inc
 
 ;****************************************************************************
index 95a22601923669ce2ddc398a5eab37b71b93e3fa..93d4721bb69f0918d5421c371177896bae0c3cf0 100644 (file)
@@ -4,5 +4,6 @@
  include i2clib.inc
  include panic.fin
  include routines-led.fin
+ include misc.fin
 
        end
index 10a6f5998cf1efd4495bd4c8fb262c520a4adbcb..b1d4e890ebde69a7f36e14d3865e93d344be2a8e 100644 (file)
@@ -6,6 +6,8 @@
  include /usr/share/gputils/header/p18f458.inc
  radix dec
  include ../iwjpictest/insn-aliases.inc
+
+clock equ 0
  include ../iwjpictest/clockvaries.inc
  include panic.inc
  include morse+auto.inc
diff --git a/detpic/misc.asm b/detpic/misc.asm
new file mode 100644 (file)
index 0000000..510ea48
--- /dev/null
@@ -0,0 +1,25 @@
+;======================================================================
+; GENERALLY USEFUL ROUTINES
+
+ include /usr/share/gputils/header/p18f458.inc
+ include ../iwjpictest/insn-aliases.inc
+ radix dec
+ code
+
+read_pic_no
+;      W               undefined               pic number from ID loc 0
+;      status Z        undefined               1 iff master PIC
+       ; read pic no from ID locations
+       mov_lw  0x20
+       mov_wf  TBLPTRU
+       clr_f   TBLPTRH
+       clr_f   TBLPTRL
+
+       tblrd   *+
+       dw      0xffff ; silicon errata: B4 issue 4
+       mov_fw  TABLAT
+
+       return
+
+ include misc.fin
+ end
diff --git a/detpic/misc.fin b/detpic/misc.fin
new file mode 100644 (file)
index 0000000..1047d00
--- /dev/null
@@ -0,0 +1 @@
+ extern read_pic_no
index 0f6b266fdee587b5c9f30cde3a2470db22e3e973..e56fe9ff8fa5d459ee7aae3f74bbbd62dc1997f5 100644 (file)
@@ -14,6 +14,9 @@
 
 
         include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
+
+clock equ mclock
        include         ../iwjpictest/clockvaries.inc
 
 
index c7f6e2f53c23f6192526b6c047916148c43765ad..35ea36e8fb15f00b1fd1ad206ab2a94ffd9cea16 100644 (file)
@@ -23,6 +23,8 @@ panic_address res     1       ; condensed form of message start addr.
 panic_morse    res     1       ; # bytes of morse msg in panic readout
 panic_regs     res     1       ; # registers in panic readout
 
+t0l_count      res     1
+t0h_count      res     1
 
 ;****************************************************************************
 
@@ -45,8 +47,14 @@ panic_routine
        clr_f    STKPTR         ; avoids stack overruns
 
 ; re-initialise timer0 config
-       mov_lw  (1<<TMR0ON) | morse_t0scale ; Enable, 16-bit, timer, prescaler
-       mov_wf  T0CON
+       call    read_pic_no
+       bra_z   panic_setup_if_master
+panic_setup_if_slave
+       morse_t0setup sclock, (1<<TMR0ON), t0l_count, t0h_count
+       bra     panic_setup_endif_masterslave
+panic_setup_if_master
+       morse_t0setup mclock, (1<<TMR0ON), t0l_count, t0h_count
+panic_setup_endif_masterslave
 
 ; get # bytes of morse msg, # registers in panic readout, message start addr.
 ; back from condensed message start addr. stored in panic_address
@@ -239,10 +247,10 @@ waiting
 
         bc_f           INTCON,2        ; clear timer0 interrupt bit (p109)
 ; Interrupt happens on overflow.  So start at 65535-morse_t0cycles:
-       mov_lw  (65535-morse_t0cycles) / 256
+       mov_fw  t0h_count
        mov_wf  TMR0H           ; p107 set high byte of timer0 (buffered,
                                 ; only actually set when write to tmr0l occurs)
-       mov_lw  (65535-morse_t0cycles) & 0xff
+       mov_fw  t0l_count
         mov_wf         TMR0L           ; set timer0 low byte - timer now set
 waiting_loop
         bt_f_if0 INTCON,TMR0IF         
index 5894eaf09af33e432a94fc61a69efbc925a2baa2..5430cd59491572cfd2d6a47b6ab4ca24f6b53c02 100644 (file)
@@ -84,16 +84,7 @@ vector_reset
        clr_f   INTCON
        bs_f    RCON, IPEN      ; interrupt priorities
 
-       ; read pic no from ID locations
-       mov_lw  0x20
-       mov_wf  TBLPTRU
-       clr_f   TBLPTRH
-       clr_f   TBLPTRL
-
-       tblrd   *
-       dw      0xffff ; silicon errata: B4 issue 4
-
-       mov_fw  TABLAT
+       call    read_pic_no
        mov_wf  picno
        bra_z   master
        goto    slave
@@ -137,15 +128,11 @@ master
        mov_wf  INTCON
 
 m_infinite
-       call    delay
+       call    m_delay
        call    led_black
-       call    delay
-       call    delay
-       call    delay
-       call    delay
-       call    delay
-       call    delay
-       call    delay
+       call    m_delay4
+       call    m_delay2
+       call    m_delay
        call    led_green
        bra     m_infinite
 
@@ -246,9 +233,9 @@ slave
        mov_wf  t
 
 s_shownum_loop
-       call    delay
+       call    s_delay
        call    led_red
-       call    delay
+       call    s_delay
        call    led_black
 
        dec_f_ifnz t
@@ -319,7 +306,15 @@ s_buffer_reset
 
 ;======================================================================
 
- define_busywait_delay ; from iwjpictest/clockvaries.inc
+m_delay4 rcall m_delay2
+m_delay2 rcall m_delay
+m_delay
+ implement_busywait_delay mclock
+ return
+
+s_delay
+ implement_busywait_delay sclock
+ return
 
 ;======================================================================
 ; SERIAL LIBRARY
index 91b42c4e7d8f466ccb35edc3e27426e5cfceecfd..007eaa8f347074387624299ce2c8d933741ab504 100644 (file)
@@ -39,40 +39,51 @@ i2c_sspadd equ (mclock/(50*4)) - 1 ; 50kbit/s
 ; ... uh, this isn't going to work at 1MHz because that's only 12.5
 ; insns per NMRA division
 
+
 ;----------------------------------------------------------------------
 ; for morse at 18wpm according to the PARIS standard
 ; (ie a unit time of 66ms) using timer0 (DS p108)
 
- if mclock==20000 ; Fosc=20MHz, Fcy=5MHz ie 200ns
-morse_t0scale equ 0011b ; 1:8 => 1.6us
-morse_t0cycles equ 41250 ; * 1.6us = 66ms
+morse_t0setup macro clock, t0con_other, lcount, hcount
+ local t0scale
+ local t0cycles
+ if clock==20000 ; Fosc=20MHz, Fcy=5MHz ie 200ns
+t0scale equ 0011b ; 1:8 => 1.6us
+t0cycles equ 41250 ; * 1.6us = 66ms
  endif
- if mclock==1000 ; Fosc=1MHz ie 1us, Fcy=4us
-morse_t0scale equ 1000b ; do not use prescaler
-morse_t0cycles equ 16500 ; * 4us = 66ms
+ if clock==2000 ; Fosc=2MHz ie 500ns, Fcy=2us
+t0scale equ 1000b ; do not use prescaler
+t0cycles equ 33000 ; * 2us = 66ms
+ endif
+ if clock==1000 ; Fosc=1MHz ie 1us, Fcy=4us
+t0scale equ 1000b ; do not use prescaler
+t0cycles equ 16500 ; * 4us = 66ms
+ endif
+       movlw   t0con_other | t0scale
+       movwf   T0CON
+ if hcount>=0
+       movlw   (65535-t0cycles) / 256
+       movwf   hcount
+ endif
+ if lcount>=0
+       movlw   (65535-t0cycles) & 0xff
+       movwf   hcount
  endif
-
-bsc_morse_t0con_012 macro
-       movf    T0CON,0,0
-       andlw   0xf0
-       iorlw   morse_t0scale
-       movwf   T0CON,0
        endm
 
 ;----------------------------------------------------------------------
 ; busy-wait delay loop, originally from flasher.asm
 
- if mclock==20000 ; each cycle 0.2us
+ if clock==20000 ; each cycle 0.2us
 delay_fastloop         equ     1       ; each medium loop = ~40ms
 delay_slowexp          equ     2       ; 2^2 * 40ms = 160ms
  endif
- if mclock==1000 ; each cycle 4us
+ if clock==1000 ; each cycle 4us
 delay_fastloop         equ     0       ; each medium loop = ~3ms
 delay_slowexp          equ     6       ; 2^6 * 3ms = 192ms
  endif
 
-define_busywait_delay macro
-delay
+implement_busywait_delay macro tclock
 
 ; we always leave each loop when its counter has reached 0, so on
 ; entry we assume it's already 0.  For the loops which want to
@@ -80,18 +91,32 @@ delay
 
        ; set a bit which says how fast the led
        ; should flash and count down from 2^(that bit)
-       bsf             delay_countslow, delay_slowexp, 0
+ if tclock >= 3915
+  local fast=1
+  local medium_cycles=198000
+ else
+  local fast=0
+  local medium_cycles=768
+ endif
+                       ; now 1/(medium_period in ms)
+                       ; = tclock / (medium_cycles*4)
+       movlw           50 * tclock / medium_cycles ; 200ms
+       movwf           delay_countslow, 0
+
+ local delayslow_loop
+ local delaymedium_loop
 delayslow_loop
 
 delaymedium_loop
 
- if delay_fastloop
+ if fast
+ local delayfast_loop
 delayfast_loop
        decfsz          delay_countfast, 1, 0   ; 1 cycle
        goto            delayfast_loop          ; 2 cycles (skipped or not)
 ; exited delayfast_loop                                ; total: 3 * 256 = 768 cycles
  endif
-                                               
+
 
        decfsz          delay_countmedium, 1, 0 ; 1 cycle
        goto            delaymedium_loop        ; 2 cycles (skipped or not)
@@ -102,6 +127,11 @@ delayfast_loop
        goto            delayslow_loop
 ; exited delayslow_loop
 
+       endm
+
+define_busywait_delay macro
+delay
+       implement_busywait_delay clock
        return
 
        endm
index 85e915baadd36ec62f15b4f0ac5d33fc9a40e176..0b86aa6a61154d033aebb80a282b2dd86ff7d451 100644 (file)
@@ -13,6 +13,7 @@ delay_countfast               equ             0x00
 delay_countmedium      equ             0x01
 delay_countslow                equ             0x02
 
+clock equ mclock
  include clockvaries.inc
        code
 
index eb25d2b65a1a46cb05bdf60a269f6ef5d4b51601..e7744d0b6ef29639ebbcd44a94e79425ea2465a9 100644 (file)
 ;
 ; `printset' means print if `printset' flag is set, otherwise just evaluate
 
-       nolist
        include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
+
+clock equ mclock
        include         insn-aliases.inc
        include         clockvaries.inc
 ;      list
-       radix           dec
 
 ;------------------------------------------------------------
 ; variable declarations and RAM memory map
index 6b8c7b65aae09f5ab7ff21f04701abcaef270490..6546cedf9cf4f57601acb894e24aac07851c8c9c 100644 (file)
--- a/pic.make
+++ b/pic.make
@@ -14,8 +14,8 @@
 #   FOO-entire0.hex    FOO.o           idlocs0.o       config.o
 #   perpicNUMBER.hex                   idlocsNUMBER.o  config.o
 
-ASFLAGS=       -Dmclock=20000 -Dsclock=20000
-#ASFLAGS=      -Dmclock=1000 -Dsclock=1000
+#ASFLAGS=      -Dmclock=20000 -Dsclock=20000
+ASFLAGS=       -Dmclock=20000 -Dsclock=2000
 
 LINK=          gplink -m -o $@ $^
 ASSEMBLE=      gpasm -p 18f458 $(ASFLAGS)