Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Sponsor

controlSUITE™ software
Comprehensive.
Intuitive.
Optimized.

Real-world software for real-time control. Details Here!

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | Comp.Arch.Embedded | pseudo random number between X and Y?

There are 20 messages in this thread.

You are currently looking at messages 0 to 10.

pseudo random number between X and Y? - Go Rf - 2009-11-17 08:06:00

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.









Re: pseudo random number between X and Y? - Paul Keinanen - 2009-11-17 08:22:00

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


Re: pseudo random number between X and Y? - Paul Keinanen - 2009-11-17 08:39:00

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
  

Re: pseudo random number between X and Y? - Wil Taphoorn - 2009-11-17 08:51:00

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

Re: pseudo random number between X and Y? - Go Rf - 2009-11-17 09:08:00

"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.




Re: pseudo random number between X and Y? - ChrisQ - 2009-11-17 09:12:00

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

Re: pseudo random number between X and Y? - ChrisQ - 2009-11-17 09:21:00

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 :-)


Re: pseudo random number between X and Y? - Mel - 2009-11-17 09:23:00

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.



Re: pseudo random number between X and Y? - Vladimir Vassilevsky - 2009-11-17 09:33:00


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

Re: pseudo random number between X and Y? - Tim Wescott - 2009-11-17 10:02:00

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

| 1 | 2 | next