There are 20 messages in this thread.
You are currently looking at messages 0 to 10.
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.
On Tue, 17 Nov 2009 14:06:07 +0100, "Go Rf" <R...@Rf.org> 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. Why not just use some microsecond counter and use some of the lower order bits as delay, if receivers detect a collision situation. Even with mains powered systems, a typical microprocessor crystal will soon drift so much that collisions do not occur frequently after a mains failure. Paul
On Tue, 17 Nov 2009 15:22:28 +0200, Paul Keinanen <k...@sci.fi> wrote: >On Tue, 17 Nov 2009 14:06:07 +0100, "Go Rf" <R...@Rf.org> 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. > >Why not just use some microsecond counter and use some of the lower >order bits as delay, if receivers detect a collision situation. > >Even with mains powered systems, a typical microprocessor crystal will >soon drift so much that collisions do not occur frequently after a >mains failure. I would like to add that the microprocessor system crystal drift is so bad that in one system with identical processor cards distributed over a large area, the drift was so bad after a reset signal on the common serial line (break) the system became useless after a few seconds due to the crystal drift at various boards. We had to use the 50 Hz mains (with very bad short time accuracy) as our common timing reference. Paul
Go Rf wrote: > 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. The boards use different addresses I assume. Should a delay calculated from (part of) the board's address not suffice? -- Wil
"Wil Taphoorn" <w...@nogo.wtms.nl> wrote in message news:W...@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.
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
Go Rf wrote: > "Wil Taphoorn" <w...@nogo.wtms.nl> wrote in message > news:W...@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 :-)
Go Rf wrote: > "Wil Taphoorn" <w...@nogo.wtms.nl> wrote in message > news:W...@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.
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
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