At 04:23 AM 10/16/97 +0100, you wrote: >Im working on a network using PICS. > >All nodes on the network are identical, all joining onto a single bus - >ie each pic doesnt receive and the re-transmit the data. > >(each pic is also programmed identicaly - including ID bits) > >Can anyone think of a way to get each PIC to allocate itself a unique >number - node ID. ... but if there are 50 PIC modules then I want the >numbers 1 to 50 or 0 to 49 for the numbers no more no less. > >I think I have a way of doing this but Im not saying anything right now. > >Comms between modules are 1) TX/RX line 2) CLOCK 3) CTS > >sort of a cut down serial com protocol > >Ideas anyone? ... > >-- >Jonathan Baker > Here is an untested and not completely thought out idea: Lets say you use 16F84s and you have a random number generating routine that generates numbers between 0 and 49 and you set aside 7 bytes(56 bits) of EEPROM to use in the negotiating sequence. Each bit in this 7 bytes would represent a number from 0-49 (bit 0, bit 1...bit 49), the upper 6 bits would be ignored. Each pic would be programmed like this: 1.) Clear the 7 bytes of EEPROM and initialize random generator. 2.) Pick a random number N (from 0 to 49). Check to see if the corresponding bit in the 7 byte file is set. If it is set, pick another N, if not procede. 3.) Wait a random number of milliseconds (from say 10-200). While waiting, if you hear another PIC send a number, set its bit in the 7 byte file. If this is the same as your number N, not only set the bit, but also goto step 2 4.) transmit your number N 5.) If all the bits in the 7 byte file are set except one, select the number corresponding to that bit as your assigned station ID and end negotiating procedure. You might be able to change this routine so that it is more efficient if you use the CTS signal that you are providing, but it is late at night and I've got early classes tomorrow, so I can't think about that part of it now.:) I do think that as it stands, all of the PICs would have an assigned number in less than a few seconds. You could make this even shorter if you reduced the delay to increments of 100 microseconds instead of milliseconds. I was not sure what baud rate you were using. You will also have to provide an error detecting scheme so that a number that is sent is not misinterpreted. You might also(possibly instead of the error detetection) make it so that if all of the bits in any of the PICs' 7 byte files get set, that PIC will wait a random length of time and then send an error code which tells all the PICs to start over again (go to step 1). I guess that this is a "brute force" method, but since it is so simple, it should not take up too much of the resources of even a simple PIC, and this is the advantage that I see. Sean Sean Breheny,KA3YXM Electrical Engineering Student