Hi, > I have a project that I have been working on for the better part of forever > trying to find the "Elegant" solution. > > Basic problem is rerouting a set of TTL signals into a different > configuration. > > Example > > Source Dest > A B > B A > C F > D E > E D > F C > > > With there being 8 different routings possible. And 32 (possibly only 16) > lines being routed at a time. If you want to route 8 input lines to 8 output lines so that each input line goes to one and only one output line, then there are 8*7*6*5*4*3*2*1 = 8! = 40320 possible routings. If gather from your statement that you only want to support 8 possible routings. > > What I am wondering is if a PIC would be a good candidate for this task. > > At startup of the pic (or on reset) it would have to find out which of the 8 > routing maps it was currently using (from a 3 bit mode select which is then > no longer used) and load the relevant routing code. If you only want to support 8 possible routings, then you could use lookup tables. The simplest would be to use a 256 byte lookup tabe for eac routing map. This would consume 2K of program memory just for the lookup tables. An alternative is to use a set of two lookup tables of 16 entries each for each mapping. Use the lower 4 bits of the input as an index into the first table and save the value returned. Then use the upper 4 bits of the input as an index into the second table. OR the value returned from this table with the value returned by the first table and you have your routed signal. Lets take the routing in your example. You only show 6 signal, so I will extend it to 8 signal by adding G and H which goes straight through. ;Assume the input is in the variable Byte_In ;Output will be placed in variable Byte_Out movf Byte_In, W andlw 0FH ;Isolate lower 4 bits call ReadTable1 movwf Temp ;Save it for now swapf Byte_In, W ;Get upper 4 bits into lower 4 bits andlw 0FH ;Isolate lower 4 bits call ReadTable2 iorwf Temp, W movwf Byte_Out ; Table 1 will implement the following mapping: ; A B ; B A ; C --> 0 ; D 0 ; D ; C ; 0 ; 0 ReadTable1: addwf PCL, F ;Do computed jump retlw 00000000b ;0 retlw 00000010b ;1 retlw 00000001b ;2 retlw 00000011b ;3 retlw 00100000b ;4 reltw 00100010b ;5 retlw 00100001b ;6 retlw 00100011b ;7 retlw 00010000b ;8 retlw 00010010b ;9 retlw 00010001b ;10 retlw 00010011b ;11 retlw 00110000b ;12 retlw 00110010b ;13 retlw 00110001b ;14 retlw 00110011b ;15 ; Table2 will implement the following mapping ; E 0 ; F 0 ; G --> F ; H E ; 0 ; 0 ; G ; H ; ReadTable2: addwf PCL, F retlw 00000000b ;0 retlw 00001000b ;1 retlw 00000100b ;2 retlw 00001100b ;3 retlw 01000000b ;4 retlw 01001000b ;5 retlw 01000100b ;6 retlw 01001100b ;7 retlw 10000000b ;8 retlw 10001000b ;9 retlw 10000100b ;10 retlw 10001100b ;11 retlw 11000000b ;12 retlw 11001000b ;13 retlw 11000100b ;14 retlw 11001100b ;15 For 8 mappings of 8 signals, you would need 8*16*2 = 256 bytes of lookup table space. This is easily achievable using a PIC. Also, in the same way you make use of 4 tables of 4 entries by breaking up the input bute in 2 bit chunks. Or you could use 8 tables of 2 entries (at that stage you would simply use btfss/c). The more tables you use, the less space you will need, but the longer it will take to compute the mapping. Hope this helps. Niki