Nikolai Golovchenko wrote: > > Wow! I missed this feature at first. Just tweak the output when > you have time, and who cares about PWM or saw-tooth waves! :) > > Nikolai Yes it appealed to me also. The ability to return to the pwm routine at any time and refresh it and still get a fair pwm analogue output. I suggested a sawtooth wave for a number of reasons. The problems with true random numbers is they are totally unpredictable. When I worked as a games programmer *everything* uses random numbers, chance of player being injured, chance of getting the goodies, etc. No games programmers use real randomness. You *absolutely will* get long strings of good or bad numbers based only on luck. Generating good psuedo-random numbers is a an art, but the basis of that art is ensuring for an EQUAL biasing of all samples. In other words, if you take 100 samples, about 10 should be under 10%. About 10 should be from 10% to 20%, etc etc. This is vitally important in the real world. With a pwm dependant on the random number, it is quite possible that in 1000 samples (1 second?) that all the random samples will be low. This gives a ridiculously long RC time constant to try and filter it, and chance of scary errors when a lot of "bad" samples happen. Which is a matter of pure luck! There will be times when 1000 sequential samples happen with NONE of them over 25% value. This would be a pwm disaster. And it WILL happen. Games programmers use a more "sawtooth" random approach, where EVERY possible sample must occur in a short time period, so in one second EVERY possible value occurs a lot of times. Taking a random (psuedo random) sample somewhere in there will provide a much more usable random value than a pure random number. This occured to me straight away when the random pwm idea was mentioned. You really don't want proper randomness or you introduce problems, hence the discussions here over the last couple of days. Using a high frequency sawtooth style wave sampled at irregular frequency or the appropriate aliasing frequency will give a more predictable and much more reliable result than a true random waveform which sould be high or low for an unlimited number of cycles based upon luck. If the sawtooth frequency is significantly higher than the sampling frequency, the result will be very random with excellent weighting. If the sawtooth is generated in hardware even better. For a timing-insensitive pwm I really think this would be a better method. Yes, you have to deal with aliasing, but is that a bigger problem than the alternatives?? I don't think so... :o) -Roman PS. The preferred way to generate good psuedo random numbers is to generate numbers between 0 and 255 (for eaxample) and place in a 256 unit lookup table where there is only ONE of each number, but the postions are random. Then you can read 256 random numbers in sequence and have perfect weighting. As a games programmer I coded many psuedo-random generators and testers, and this is a good place to start. Maybe a search of games programming sites would reveal some useful info. People think they are dopey kids but they are just as good at what they do as any aerospace programmer. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.