From: ChrisQ on 17 Nov 2009 09:12 Go Rf wrote: > Hello all > > > > I need a function, when called returns a pseudo random number between X and > Y. > > > > I have many boards that periodically broadcasts their board addresses on an > RF link. All boards use the same RF-channel frequency, so data collisions is > going to happen. So I need to randomly delay between those broadcasts to be > able to avoid collisions with other boards broadcasts. > > > > I want to make a pseudo random delay (X ms - Y ms) before sending the > package again. > > You could have a look at the Aloha radio network or ethernet spec, to see how it's been done before... Regards, Chris
From: ChrisQ on 17 Nov 2009 09:21 Go Rf wrote: > "Wil Taphoorn" <wil(a)nogo.wtms.nl> wrote in message > news:WTMSB29E82BE(a)wtms.nl... > >> The boards use different addresses I assume. Should a delay calculated >> from (part of) the board's address not suffice? > > The boards use a 32-bit address that is unique. So I should be able to use > it. If I for example take 8-bits from theboard address to specify a delay. > And the next time I take the next 8 bits. > > For example > > delay = bit(7 to 0) of address > delay = bit(8 to 1) of address > delay = bit(9 to 2) of address > ... > delay = bit(31 to 24) of address > > and then start again at: > > delay = bit(7 to 0) of address > > But some combinations of addresses works better than others. And it gets bad > if i enumerate all boards starting at address 1 and the 2, 3, 4, 5 etc. > That assumes that all the address bits are distributed fairly evenly, which may be unlikely. A better way might be to use a hash of the address and use this to create a backoff table in memory. Dunno, I would still have a look at Aloha first, which solved exactly that problem and was the forerunner of ethernet... Regards, Chris (Who should be getting on with some work today :-)
From: Mel on 17 Nov 2009 09:23 Go Rf wrote: > "Wil Taphoorn" <wil(a)nogo.wtms.nl> wrote in message > news:WTMSB29E82BE(a)wtms.nl... > >> The boards use different addresses I assume. Should a delay calculated >> from (part of) the board's address not suffice? > > The boards use a 32-bit address that is unique. So I should be able to use > it. If I for example take 8-bits from theboard address to specify a delay. > And the next time I take the next 8 bits. If you have unique seed values you could use a Linear Feedback Shift Register to shake them up and get series of different pseudo-random values. With the right constant you can get good fairly patternless results. The Wikipedia article at http://en.wikipedia.org/wiki/LFSR has some sample code. Mel.
From: Vladimir Vassilevsky on 17 Nov 2009 09:33 Go Rf wrote: > Hello all > I need a function, when called returns a pseudo random number between X and > Y. Oh, dear. > I have many boards that periodically broadcasts their board addresses on an > RF link. All boards use the same RF-channel frequency, so data collisions is > going to happen. So I need to randomly delay between those broadcasts to be > able to avoid collisions with other boards broadcasts. > I want to make a pseudo random delay (X ms - Y ms) before sending the > package again. Abandon this task. It is not for the sorrow programmers like you. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
From: Tim Wescott on 17 Nov 2009 10:02 On Tue, 17 Nov 2009 14:06:07 +0100, Go Rf wrote: > Hello all > > > > I need a function, when called returns a pseudo random number between X > and Y. > > > > I have many boards that periodically broadcasts their board addresses on > an RF link. All boards use the same RF-channel frequency, so data > collisions is going to happen. So I need to randomly delay between those > broadcasts to be able to avoid collisions with other boards broadcasts. > > > > I want to make a pseudo random delay (X ms - Y ms) before sending the > package again. Did you do a web search for "random number generator"? For your purposes a linear shift register ought to work, particularly if you seed it with your board address. There's a nifty way to go through a linear shift register N bits at a time; it requires a table of register states 2^N words long and as wide as your register but the code is short -- depending on your program storage space you could use that and get a really big change from one number to the next. Otherwise just iterating the thing once and taking the bottom bits would probably be random enough. -- www.wescottdesign.com
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: OpenOCD+GDB (stepi. Unable to single step) Next: Compact Flash IDE PIO Write Size Issues |