|
|
View previous topic :: View next topic |
Author |
Message |
Pete Smith Guest
|
Noise generator using random numbers |
Posted: Tue Dec 10, 2002 4:56 pm |
|
|
Hi all.
I'm having a play with PWM decoding, using timer_1 and _2, as per the CCSC example file.
Before I can do this, I need to emulate white noise, and to randomly embed a PWM data stream. The data stream is easy (4th generation of code cracked it, to make sure that 34 bits could be sent out, with the same no of cycles per bit).
In order to test the receive code, this noise is important.
What I basically did was #define RAND_MAX 128, and then setting up a
mark= rand();
space = rand();
output_high(PIN_C0);
delay_us(mark);
output_low(PIN_C0);
delay_us(space);
and repeat this.
However, this doesn't give anything approaching white noise, more like a square wave with jitter!
If I use delay_ms(), then I get white noise, just 1000 times slower.
If I printf() mark & space, they seem to be random.
Is using delay_us() just as random as the delay_ms(), and because it's coming in quicker, I can't see the narrow & wide ones, just the average?
Am I missing something? Would I be better off using PCM Programmers rand() routine?
This is just a quick question BTW, because it's 22:55 local time, I'm tired, it's bugging me, and it'll have to wait until tomorrow before I can see exactly what the hell's going on.
Thanks,
Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9957 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Noise generator using random numbers |
Posted: Tue Dec 10, 2002 5:16 pm |
|
|
:=Am I missing something? Would I be better off using PCM Programmers rand() routine?
:=
------------------------------------------------------------
I assume you're using the rand() function that CCS provides
in stdlib.h (in vs. 3.xxx).
The one that I posted (it's in the FAQ) was never tested in
terms of producing white noise. It was just intended to
produce a non-repeating "random" stream of data, for use
in an EEPROM memory test. Its main virtue is that it's short
and takes very little ROM. You should probably do a web
search to find one that would produce white noise.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9958 |
|
|
Pete Smith Guest
|
Re: Noise generator using random numbers |
Posted: Thu Dec 12, 2002 6:48 am |
|
|
:=
:=:=Am I missing something? Would I be better off using PCM Programmers rand() routine?
:=:=
:=------------------------------------------------------------
:=I assume you're using the rand() function that CCS provides
:=in stdlib.h (in vs. 3.xxx).
:=
:=The one that I posted (it's in the FAQ) was never tested in
:=terms of producing white noise. It was just intended to
:=produce a non-repeating "random" stream of data, for use
:=in an EEPROM memory test. Its main virtue is that it's short
:=and takes very little ROM.
I finally tracked down the problem.
The built in rand() function is actually _really_ slow. The time it takes to produce a random number was in the order of 2-5x the random period I was trying to produce.
When dealing in msec, the calculation time was negligible compared to the delay.
I've now put your routine into my code, and it's fast enough to give me pretty random noise, to try and confuse my PWM decoding!
Thanks,
Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9999 |
|
|
Jean-Louis VERN Guest
|
Re: Noise generator using random numbers |
Posted: Sun Dec 15, 2002 6:18 pm |
|
|
:=Hi all.
:=
:=I'm having a play with PWM decoding, using timer_1 and _2, as per the CCSC example file.
:=
:=Before I can do this, I need to emulate white noise, and to randomly embed a PWM data stream. The data stream is easy (4th generation of code cracked it, to make sure that 34 bits could be sent out, with the same no of cycles per bit).
:=
:=In order to test the receive code, this noise is important.
:=
:=What I basically did was #define RAND_MAX 128, and then setting up a
:=
:=mark= rand();
:=space = rand();
:=output_high(PIN_C0);
:=delay_us(mark);
:=output_low(PIN_C0);
:=delay_us(space);
:=
:=and repeat this.
:=
:=However, this doesn't give anything approaching white noise, more like a square wave with jitter!
:=
:=If I use delay_ms(), then I get white noise, just 1000 times slower.
:=
:=If I printf() mark & space, they seem to be random.
:=
:=Is using delay_us() just as random as the delay_ms(), and because it's coming in quicker, I can't see the narrow & wide ones, just the average?
:=
:=Am I missing something? Would I be better off using PCM Programmers rand() routine?
:=
:=This is just a quick question BTW, because it's 22:55 local time, I'm tired, it's bugging me, and it'll have to wait until tomorrow before I can see exactly what the hell's going on.
:=
:=Thanks,
:=
:=Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10058 |
|
|
Jean-Louis VERN Guest
|
Re: Noise generator using random numbers |
Posted: Sun Dec 15, 2002 6:20 pm |
|
|
You can use something like that (with timing equalization...)
short int sequence( void )
{
static int32 shift = 1L;
// Pseudo random generator using polynome
// x^32 + x^7 + x^5 + x^3 + x^2 + x^1 + 1
// cf. Numerical recepes in C Second Edition pg 299
if( bit_test( shift, 31 )){
shift ^= 0x57L;
shift <<= 1;
bit_set( shift, 0 );
} else {
shift <<= 1;
}
return bit_test( shift, 0 );
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10059 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|