From: ian Date: Sat, 26 Nov 2005 01:34:12 +0000 (+0000) Subject: giant diffs of clock speed change X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=c442a784c7c67529c7f9e1c08168a0ab2b4c9a62;p=trains.git giant diffs of clock speed change --- diff --git a/cebpic/Makefile b/cebpic/Makefile index 0a9ea5e..6f418fc 100644 --- a/cebpic/Makefile +++ b/cebpic/Makefile @@ -9,7 +9,7 @@ PROGRAMS= led-flash send-serial panic reply-serial \ ROUTINES= routines-led LIBS= routines.lib -INCLUDES= common.inc pindata.inc +INCLUDES= common.inc pindata.inc ../iwjpictest/clockvaries.inc include manypics.make diff --git a/cebpic/flow-control-test.asm b/cebpic/flow-control-test.asm index f07a12c..a22fc6c 100644 --- a/cebpic/flow-control-test.asm +++ b/cebpic/flow-control-test.asm @@ -3,6 +3,7 @@ ; 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 + include ../iwjpictest/clockvaries.inc code start @@ -10,15 +11,11 @@ start bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate bsf RCSTA,7,0 ; serial port enable (p182) + bsc_txsta_brgh ; set high or low baud rate -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - - bsf SPBRG,7,0 - bsf SPBRG,0,0 - +; set SPBRG to get correct baud rate + movlw_movwf_spbrg ; set pin 24 to low (transmission allowed from computer) diff --git a/cebpic/i2c-test-reply.asm b/cebpic/i2c-test-reply.asm index 2d20835..3e6e958 100644 --- a/cebpic/i2c-test-reply.asm +++ b/cebpic/i2c-test-reply.asm @@ -42,6 +42,7 @@ include common.inc include morse-auto.inc include ../iwjpictest/insn-aliases.inc + include ../iwjpictest/clockvaries.inc extern led_green extern led_red @@ -262,10 +263,7 @@ panic_routine ; re-initialise timer0 config bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode bcf T0CON,5,0 ; timer0 use internal clock - bcf T0CON,3,0 ; use prescaler - bcf T0CON,2,0 ; } - bsf T0CON,1,0 ; } prescale value 1:16 (13ms x 16) - bsf T0CON,0,0 ; } + bsc_morse_t0con_012 ; use prescaler? and configure it ; get # bytes of morse msg, # registers in panic readout, message start addr. ; back from condensed message start addr. stored in PANIC_ADDRESS @@ -567,17 +565,15 @@ serial_setup bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; set high or low baud rate ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) bcf RCSTA,6,0 ; 8-bit reception bsf RCSTA,4,0 ; enable continuous receive -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 +; set SPBRG to get correct baud rate + movlw_movwf_spbrg ; interrupt set-up for serial receive bcf IPR1,5,0 ; set to low-priority interrupt @@ -675,11 +671,8 @@ i2c_setup_if_master movwf SSPCON1,0 ; CKP unused, set to 0; master mode. ; set baud rate - movlw 100-1 - movwf SSPADD,0 ; set baud rate; clock=Fosc/(4*(SSPADD+1)) - ; Fosc=20MHz, currently want clock=50kHz - ; => SSPADD=99 - + movlw i2c_sspadd + movwf SSPADD,0 goto i2c_setup_endif_master_slave i2c_setup_if_slave diff --git a/cebpic/i2c-test.asm b/cebpic/i2c-test.asm index 0c7e62a..8099e97 100644 --- a/cebpic/i2c-test.asm +++ b/cebpic/i2c-test.asm @@ -26,6 +26,7 @@ ; boilerplate: include /usr/share/gputils/header/p18f458.inc + include ../iwjpictest/clockvaries.inc radix dec extern led_green @@ -316,17 +317,15 @@ serial_setup bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; set high or low baud rate ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) bcf RCSTA,6,0 ; 8-bit reception bsf RCSTA,4,0 ; enable continuous receive -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 +; set SPBRG to get correct baud rate + movlw_movwf_spbrg ; interrupt set-up for serial receive bcf IPR1,5,0 ; set to low-priority interrupt @@ -424,11 +423,8 @@ i2c_setup_if_master movwf SSPCON1,0 ; CKP unused, set to 0; master mode. ; set baud rate - movlw 100-1 - movwf SSPADD,0 ; set baud rate; clock=Fosc/(4*(SSPADD+1)) - ; Fosc=20MHz, currently want clock=50kHz - ; => SSPADD=99 - + movlw i2c_sspadd + movwf SSPADD,0 goto i2c_setup_endif_master_slave i2c_setup_if_slave @@ -517,10 +513,7 @@ informative_panic ; re-initialise timer0 config bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode bcf T0CON,5,0 ; timer0 use internal clock - bcf T0CON,3,0 ; use prescaler - bsf T0CON,2,0 ; } - bcf T0CON,1,0 ; } prescale value 1:32 (13ms x 32) - bcf T0CON,0,0 ; } + bsc_morse_t0con_012 ; use prescaler? and configure it ; diff --git a/cebpic/led-flash.asm b/cebpic/led-flash.asm index f7a977b..0a79e35 100644 --- a/cebpic/led-flash.asm +++ b/cebpic/led-flash.asm @@ -1,6 +1,7 @@ ; 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 + include ../iwjpictest/clockvaries.inc code start @@ -9,10 +10,7 @@ start ; timer initial config bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode bcf T0CON,5,0 ; timer0 use internal clock - bcf T0CON,3,0 ; use prescaler - bsf T0CON,2,0 ; } - bcf T0CON,1,0 ; } prescale value 1:32 (13ms x 32) - bcf T0CON,0,0 ; } + bsc_morse_t0con_012 ; use prescaler? and configure it ; actually do stuff call green call waiting diff --git a/cebpic/morsepanic.asm b/cebpic/morsepanic.asm index 2557bed..9f5a518 100644 --- a/cebpic/morsepanic.asm +++ b/cebpic/morsepanic.asm @@ -11,6 +11,7 @@ include common.inc include morse-auto.inc include ../iwjpictest/insn-aliases.inc + include ../iwjpictest/clockvaries.inc extern led_green extern led_red @@ -109,17 +110,15 @@ vector_reset bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; set high or low baud rate ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) bcf RCSTA,6,0 ; 8-bit reception bsf RCSTA,4,0 ; enable continuous receive -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 +; set SPBRG to get correct baud rate + movlw_movwf_spbrg ; interrupt set-up for serial receive bcf IPR1,5,0 ; set to low-priority interrupt @@ -158,10 +157,7 @@ panic_routine ; re-initialise timer0 config bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode bcf T0CON,5,0 ; timer0 use internal clock - bcf T0CON,3,0 ; use prescaler - bcf T0CON,2,0 ; } - bsf T0CON,1,0 ; } prescale value 1:16 (13ms x 16) - bsf T0CON,0,0 ; } + bsc_morse_t0con_012 ; use prescaler? and configure it ; get # bytes of morse msg, # registers in panic readout, message start addr. ; back from condensed message start addr. stored in PANIC_ADDRESS diff --git a/cebpic/nmra-stream.asm b/cebpic/nmra-stream.asm index 97c890b..0f6b266 100644 --- a/cebpic/nmra-stream.asm +++ b/cebpic/nmra-stream.asm @@ -14,6 +14,7 @@ include /usr/share/gputils/header/p18f458.inc + include ../iwjpictest/clockvaries.inc NMRACTRL equ 0x4 ; byte 4: state relevant to NMRA control @@ -100,7 +101,7 @@ initialise bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) @@ -109,8 +110,8 @@ initialise ; set SPBRG to get correct baud rate according to table top right p186 ; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 + movlw serial_spbrg + movwf SPBRG,0 debug 0x0A ; LF to terminak diff --git a/cebpic/panic.asm b/cebpic/panic.asm index 4d885ce..9e1ac2c 100644 --- a/cebpic/panic.asm +++ b/cebpic/panic.asm @@ -9,6 +9,7 @@ ; 10 10 10 00 | 1110 1110 | 1110 00 10 | 10 10 include common.inc + include ../iwjpictest/clockvaries.inc extern led_green extern led_red @@ -124,17 +125,15 @@ vector_reset bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; set high or low baud rate ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) bcf RCSTA,6,0 ; 8-bit reception bsf RCSTA,4,0 ; enable continuous receive -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 +; set SPBRG to get correct baud rate + movlw_movwf_spbrg ; interrupt set-up for serial receive bcf IPR1,5,0 ; set to low-priority interrupt @@ -204,10 +203,7 @@ informative_panic ; re-initialise timer0 config bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode bcf T0CON,5,0 ; timer0 use internal clock - bcf T0CON,3,0 ; use prescaler - bsf T0CON,2,0 ; } - bcf T0CON,1,0 ; } prescale value 1:32 (13ms x 32) - bcf T0CON,0,0 ; } + bsc_morse_t0con_012 ; use prescaler? and configure it clrf BLANK,0 panic_loop diff --git a/cebpic/reply-serial.asm b/cebpic/reply-serial.asm index fec173b..037ef82 100644 --- a/cebpic/reply-serial.asm +++ b/cebpic/reply-serial.asm @@ -1,6 +1,7 @@ ; 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 + include ../iwjpictest/clockvaries.inc extern led_green extern led_red @@ -28,17 +29,15 @@ initialise_serial bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; set high or low baud rate ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) bsf RCSTA,6,0 ; 8-bit reception bsf RCSTA,4,0 ; enable continuous receive -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 +; set SPBRG to get correct baud rate + movlw_movwf_spbrg ; interrupt set-up for serial receive bsf PIE1,5,0 ; enable USART receive interrupt (p85) @@ -53,11 +52,7 @@ initialise_serial bcf T0CON,6,0 ; p107 Timer0 -> 16bit mode bcf T0CON,5,0 ; timer0 use internal clock bcf INTCON,5,0 ; clear TMR0IE => mask interrupt - bcf T0CON,3,0 ; use prescaler - bcf T0CON,2,0 ; } - bsf T0CON,1,0 ; } prescale value 1:8 (13ms x 8) - bcf T0CON,0,0 ; } - + bsc_morse_t0con_012 ; use prescaler? and configure it main call led_green diff --git a/cebpic/send-serial.asm b/cebpic/send-serial.asm index d02314c..1d1b148 100644 --- a/cebpic/send-serial.asm +++ b/cebpic/send-serial.asm @@ -1,6 +1,7 @@ ; 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 + include ../iwjpictest/clockvaries.inc code start @@ -8,14 +9,11 @@ start bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; set high or low baud rate bsf RCSTA,7,0 ; serial port enable (p182) -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - - bsf SPBRG,7,0 - bsf SPBRG,0,0 +; set SPBRG to get correct baud rate + movlw_movwf_spbrg call initialiseascii diff --git a/cebpic/tblrd_test.asm b/cebpic/tblrd_test.asm index 13f1467..5f42430 100644 --- a/cebpic/tblrd_test.asm +++ b/cebpic/tblrd_test.asm @@ -9,6 +9,7 @@ include /usr/share/gputils/header/p18f458.inc + include ../iwjpictest/clockvaries.inc extern led_green extern led_red @@ -115,17 +116,15 @@ initialise bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; set high or low baud rate ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) bcf RCSTA,6,0 ; 8-bit reception bsf RCSTA,4,0 ; enable continuous receive -; set SPBRG to get correct baud rate according to table top right p186 -; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 +; set SPBRG to get correct baud rate + movlw_movwf_spbrg ; interrupt set-up for serial receive diff --git a/detpic/common.inc b/detpic/common.inc index f6388f8..473d420 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -9,6 +9,7 @@ include panic.inc include morse+auto.inc include ../iwjpictest/insn-aliases.inc + include ../iwjpictest/clockvaries.inc ;**************************************************************************** ; MACROS diff --git a/detpic/i2clib.asm b/detpic/i2clib.asm index f2af785..10a6f59 100644 --- a/detpic/i2clib.asm +++ b/detpic/i2clib.asm @@ -6,6 +6,7 @@ include /usr/share/gputils/header/p18f458.inc radix dec include ../iwjpictest/insn-aliases.inc + include ../iwjpictest/clockvaries.inc include panic.inc include morse+auto.inc @@ -90,8 +91,8 @@ slave2addr ;---------- i2cm_init - mov_lw 100-1 ; baud rate = Fosc/(4*(SSPADD+1)) - mov_wf SSPADD ; Fosc=20MHz, so SSPADD==99 means 50kbit/s + mov_lw i2c_sspadd + mov_wf SSPADD clr_f st mov_lw 0x08 ; !SSPEN, Master mode mov_wf SSPCON1 diff --git a/detpic/nmra-stream.asm b/detpic/nmra-stream.asm index 97c890b..0f6b266 100644 --- a/detpic/nmra-stream.asm +++ b/detpic/nmra-stream.asm @@ -14,6 +14,7 @@ include /usr/share/gputils/header/p18f458.inc + include ../iwjpictest/clockvaries.inc NMRACTRL equ 0x4 ; byte 4: state relevant to NMRA control @@ -100,7 +101,7 @@ initialise bcf TXSTA,6,0 ; p181, set 8-bit mode bsf TXSTA,5,0 ; transmit enable bcf TXSTA,4,0 ; asynchronous mode - bsf TXSTA,2,0 ; set high baud rate + bsc_txsta_brgh ; initial config - RCSTA register p182 bsf RCSTA,7,0 ; serial port enable (p182) @@ -109,8 +110,8 @@ initialise ; set SPBRG to get correct baud rate according to table top right p186 ; (Tosc = 20MHz, desired baud rate = 9600) - bsf SPBRG,7,0 - bsf SPBRG,0,0 + movlw serial_spbrg + movwf SPBRG,0 debug 0x0A ; LF to terminak diff --git a/detpic/panic.asm b/detpic/panic.asm index 6e9c62b..c7f6e2f 100644 --- a/detpic/panic.asm +++ b/detpic/panic.asm @@ -45,11 +45,8 @@ panic_routine clr_f STKPTR ; avoids stack overruns ; re-initialise timer0 config - mov_lw (1< PSout is 312.5kHz or 3.2us per period (DS p108) - ; We want to wait 66ms (morse at 18wpm according to the PARIS standard - ; is a unit time of 66ms), or 20,833 PSout cycles: -waiting_t0cycles equ 20833 ; see by `waiting', below + mov_lw (1< PSout is 312.5kHz or 3.2us per period +morse_t0cycles equ 20833 ; see by `waiting', below + endif + if mclock==1000 +;morse_t0scale equ 0011b ; 1:2 => PSout is 312.5kHz or 3.2us per period +;morse_t0cycles equ 0 + 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 +delay_fastloop equ 1 ; each medium loop = ~40ms +delay_slowexp equ 2 ; 2^2 * 40ms = 160ms + endif + if mclock==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 + +; 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 +; count all the way (256 iterations) that's good. + + ; set a bit which says how fast the led + ; should flash and count down from 2^(that bit) + bsf delay_countslow, delay_slowexp, 0 +delayslow_loop + +delaymedium_loop + + if delay_fastloop +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) +; exited delaymedium_loop ; total: ~198000 cycles + ; or ~768 cycles (no fast) + + decfsz delay_countslow, 1, 0 + goto delayslow_loop +; exited delayslow_loop + + return + + endm diff --git a/iwjpictest/copybits.asm b/iwjpictest/copybits.asm index be1ce03..ef01cf3 100644 --- a/iwjpictest/copybits.asm +++ b/iwjpictest/copybits.asm @@ -11,12 +11,19 @@ include /usr/share/gputils/header/p18f458.inc include onecopybit.inc + radix dec + ACCSFR equ 0x0f00 COUNTINNER equ 0x00 COUNTOUTER equ 0x02 + if mclock==20000 OUTEREXP equ 7 ; 2^7 * 2.6ms = 332ms + endif + if mclock==1000 +OUTEREXP equ 2 ; 2^2 * 52ms = 208ms + endif ; 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 diff --git a/iwjpictest/flasher.asm b/iwjpictest/flasher.asm index e7bac42..85e915b 100644 --- a/iwjpictest/flasher.asm +++ b/iwjpictest/flasher.asm @@ -7,17 +7,13 @@ ; * leaves all other pins set to their default states (usually Z). include /usr/share/gputils/header/p18f458.inc + radix dec -COUNTFAST equ 0x00 -COUNTMEDIUM equ 0x01 -COUNTSLOW equ 0x02 - -SLOWEXP equ 2 ; 2^2 * 40ms = 160ms - -; 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 -; count all the way (256 iterations) that's good. +delay_countfast equ 0x00 +delay_countmedium equ 0x01 +delay_countslow equ 0x02 + include clockvaries.inc code start @@ -60,31 +56,6 @@ black call delay goto delay -delay - ; set a bit which says how fast the led - ; should flash and count down from 2^(that bit) - bsf COUNTSLOW, SLOWEXP, 0 -delayslow_loop - -delaymedium_loop - -delayfast_loop - decfsz COUNTFAST, 1, 0 ; 1 cycle - goto delayfast_loop ; 2 cycles (skipped or not) -; exited delayfast_loop ; total: 3 * 256 = 768 cycles - - - decfsz COUNTMEDIUM, 1, 0 ; 1 cycle - goto delaymedium_loop ; 2 cycles (skipped or not) -; exited delaymedium_loop ; total: ~198000 cycles - - ; each cycle 0.2us - ; so each medium loop is ~40ms - - decfsz COUNTSLOW, 1, 0 - goto delayslow_loop -; exited delayslow_loop - - return + define_busywait_delay end diff --git a/iwjpictest/harness.asm b/iwjpictest/harness.asm index 09716c1..eb25d2b 100644 --- a/iwjpictest/harness.asm +++ b/iwjpictest/harness.asm @@ -50,6 +50,7 @@ nolist include /usr/share/gputils/header/p18f458.inc include insn-aliases.inc + include clockvaries.inc ; list radix dec @@ -419,9 +420,9 @@ led_green ;---------------------------------------- serial_setup ; W undefined undefined - mov_lw (1<