Re-writing code using counters
average joe
Posts: 795
Hey guys, I've been trying to re-write some code using the counters to control clock lines. I have been able to 2 out of 3 portions re-written but having trouble with the last one. The original code is as follows:
For reference I'm posting the code I have been able to translate.
pasmhubtoram call #get_values ' get hubaddr,ramaddr,len and set control pins call #set161 or outa,maskP16P20 ' set control pins high mov latchvalue,#%11111101 ' group 2, displays all off call #set373 ' send out to the latch hubtoram_loop and outa,maskP16P31 '%11111111_11111111_00000000_00000000 clear for output rdword data_16,hubaddr ' get the word from hub or outa,data_16 ' send out the byte to P0-P15 andn outa,maskP17 ' set mem write low add hubaddr,#2 ' increment by 2 bytes = 1 word. Put this here for small delay while writes or outa,maskP17 ' mem write high andn outa,maskP20 ' clock 161 low or outa,maskP20 ' clock 161 high djnz len,#hubtoram_loop ' loop this many times or outa,maskP20 ' stop clock jmp #done ' tristate pins and listen for commandsThis transfers data from hub to external sram. It works but the main loop takes 3 hub slots and I suspect using the counters is the key to get it down to 2. Here's my last effort:
'----------------------------------------------------------------- ' setups needed for burst write Thanks to Jazzed (Steve Denson) '----------------------------------------------------------------- wr_phsa long $0800_0000 ' phsa offset for adjusting clock start wr_frqa long $0800_0000 wr_ctra long 4<<26 | 20 ' NCO mode on P20 fastpasmhubtoram call #get_values ' get hubaddr,ramaddr,len and set control pins sub len, #1 sub ramaddr,#1 call #set161 or outa,maskP16P20 ' set control pins high mov latchvalue,#%11111101 ' group 2, displays all off call #set373 ' send out to the latch 'insert burst read here or outa,maskP20 ' get clock line? mov phsa, wr_phsa ' init counters phsa mov frqa, wr_frqa ' setup NCO freq andn outa,maskP20 ' start counters rdword data_16,hubaddr ' sync up only mov ctra, wr_ctra ' enable address counter clk fasthubtoram_loop and outa,maskP16P31 '%11111111_11111111_00000000_00000000 clear for output A0 A8 B0 B8 rdword data_16,hubaddr ' get the word from hub C0 C8 D0 D8 E0 E8 F0 F8 or outa,data_16 ' send out the byte to P0-P15 00 08 10 18 andn outa,maskP17 ' set mem write low 20 28 30 38 add hubaddr,#2 ' increment by 2 bytes = 1 word. Put this here for small delay while writes 40 48 50 58 or outa,maskP17 ' mem write high 60 68 70 78 djnz len,#fasthubtoram_loop ' loop this many times 80 88 90 98 ' A0 A8 B0 B8 or outa,maskP20 ' stop clock ' mov ctra, #0 ' stop counter jmp #done ' tristate pins and listen for commands
For reference I'm posting the code I have been able to translate.
pasmramtohub call #get_values ' get hubaddr,ramaddr,len and set control pins call #set161 or outa,maskP16P20 ' set control pins high mov latchvalue,#%11111101 ' group 2, displays all off call #set373 ' send out to the latch and dira,maskP16P31 '%11111111_11111111_00000000_00000000 inputs andn outa,maskP16 ' memory /rd low ramtohub_loop mov data_16,ina ' get the data wrword data_16,hubaddr ' move data to hub andn outa,maskP20 ' clock 161 low or outa,maskP20 ' clock 161 high add hubaddr,#2 ' increment the hub address djnz len,#ramtohub_loop or outa,maskP16 ' memory /rd high jmp #done ' ' tristate pins and listen for commandsBecomes
'----------------------------------------------------------------------- ' setups needed for burst read from ram Thanks to Jazzed (Steve Denson) '----------------------------------------------------------------------- rd_frqa long $1000_0000 rd_ctra long 4<<26 | 20 ' NCO mode on P20 rd_ctrb long $A<<26| 20 ' Edge Accumulate mode on P20 fastpasmramtohub call #get_values ' get hubaddr,ramaddr,len and set control pins call #set161 or outa,maskP16P20 ' set control pins high mov latchvalue,#%11111101 ' group 2, displays all off call #set373 ' send out to the latch and dira,maskP16P31 ' %11111111_11111111_00000000_00000000 inputs andn outa,maskP16 ' memory /rd low mov phsa, #0 ' init counters phsa mov frqa, rd_frqa ' setup NCO freq mov phsb, hubaddr ' save hub ptr to phsb mov frqb, #2 ' setup EDGE freq 'ctra setup for burst read or outa,maskP20 ' get clock line? andn outa,maskP20 ' start counters mov ctrb, rd_ctrb ' set ctr be mode rdword data_16,phsb ' sync up only mov ctra, rd_ctra ' enable address counter clk fastramtohub_loop ' 10MB/s read loop uses phsb for hub pointer mov data_16,ina ' get first data 1 2 3 4 wrword data_16,phsb ' move data to hub 5 6 7 8 9 A B C djnz len,#fastramtohub_loop ' D E F 0 or outa,maskP20 ' stop clock mov ctra, #0 ' stop counter mov ctrb, #0 ' stop counter or outa,maskP16 ' memory /rd high jmp #doneAnd
pasmramtodisplay call #get_values ' get hubaddr,ramaddr,len (only uses len) and set control pins call #set161 or outa,maskP16P20 ' set control pins high mov latchvalue, dirb call #set373 andn outa,maskP19 ' CS low and dira,maskP16P31 ' %11111111_11111111_00000000_00000000 so prop pins 0-15 HiZ andn outa,maskP16 ' ram /rd low ramtodisplay_loop andn outa,maskP18 ' ILI write low or outa,maskP18 ' ILI write high andn outa,maskP20 ' clock 161 low or outa,maskP20 ' clock 161 high djnz len,#ramtodisplay_loop or outa,maskP16 ' mem /rd high or outa,maskP19 ' CS high jmp #donebecomes
'-------------------------------------------------------------------------- ' setups needed for burst write to display Thanks to Jazzed (Steve Denson) '-------------------------------------------------------------------------- ds_ctra long 4<<26 | 20 ' NCO mode on P20 ds_frq long $2000_0000 ' phsb accumulates twice per edge ds_ctrb long 4<<26 | 18 ' NCO mode on P18 fastpasmramtodisplay call #get_values ' get hubaddr,ramaddr,len (only uses len) and set control pins sub len, #2 add ramaddr, #1 call #set161 or outa,maskP16P20 ' set control pins high mov latchvalue, dirb call #set373 and dira,maskP16P31 ' %11111111_11111111_00000000_00000000 so prop pins 0-15 HiZ andn outa,maskP19 ' CS low andn outa,maskP16 ' ram /rd low 'ctra setup for burst read mov phsa, #0 ' init counters phsa P20 mov phsb, #0 ' init to phsb P18 mov frqa, ds_frq ' setup NCO freq P20 mov frqb, ds_frq ' setup NCO freq P18 andn outa,maskP20 ' start counters P20 andn outa,maskP18 ' start counters P18 ' P20 Count P18 Write mov ctrb, ds_ctrb ' enable display clk P18 mov ctra, ds_ctra ' enable address counter clk P20 0 2 4 6 8 fastramtodisplay_loop nop ' 2 4 6 8 10 12 14 0 2 4 6 8 djnz len,#fastramtodisplay_loop ' 10 12 14 0 2 4 6 8 ' 2 4 6 8 10 12 14 0 or outa,maskP18 ' stop clock mov ctrb, #0 ' stop counter 10 12 14 0 mov ctra, #0 ' stop counter 2 4 6 8 10 12 14 0 or outa,maskP20 ' stop clock 2 4 6 8 or outa,maskP19 ' CS high or outa,maskP16 ' mem /rd high jmp #doneI think I'm doing things right, hopefully someone can help!
Comments