Neil wrote: > On 5/13/2012 11:13 PM, Harold Hallikainen wrote: > > > From your description, it sounds like you're using an adc to measure = the > > output voltage and then setting the output bit high or low as appropria= te. > > This is similar to delta modulation. Is this what you're doing? > > > > I think the random number approach did not use an ADC. Instead, the > > desired output is compared to random numbers and the pin set high if th= e > > desired output is above the random number and low if it's below. If the > > random number were not random, but were, instead, a steadily increasing > > number, you'd get standard PWM. But, you would have to increment the > > number at fixed intervals to get the required duty cycle. As I read thi= s > > random number method, you can call run it at irregular intervals and th= e > > output will still be correct due to the use of the random numbers. > > > > It's a really interesting idea. > > > > Harold > > Yes, that's pretty much what I'm doing... I think I'm missing part of a > discussion somewhere where that random number technique was explained as > the technique I used, and after thinking and thinking I could not figure > out the purpose for random numbers. I'll have to find that other > discussion with the technique I used. > > Curious though -- what's being used to *compare* the random number to > the desired output? I wrote the original random number ATOD post a few years ago. I used the random number ATOD trick to create a PWM on a few projects including the tone generator for a DTMF dialler.. To understand the random ATOD start by reviewing how a normal timer based PWM works. The output voltage is equal to the time on divided by time off multiplied by voltage swing between 1 and 0 logical levels plus logic 0 off= set. A random number ATOD also creates a an output ratio of 1's and 0's. The ratio of output 1's to the total bits The output voltage is equal to the ra= tio of 1's to the total 1's and 0's multiplied by the voltage swing between 1 = and 0 logical levels plus logic 0 offset. They will produce the same output voltage. To create a Random number PWM. 1) Decide the range of the random number RandRange typically 2^8 or 2^16 . 2) The output voltage when output is logical 1 is Vout1 and output voltage = when output is logical 0 is Vout0; 3) Desired Output voltage is Vout somewhere between Vout0 and Vout1 4) Calculate a random threshold number. The ratio of RandomThreshold / Ran= domRange is equal to the desired output Vout / (Vout1 - Vout0) 5) RandomThreshold =3D (Vout - Vout0) / (Vout1 -Vout0) * RandRange . 6) Generate a random number as often as possible and compare it to the Rand= omThreshold. If the RandomThreshold is higher or equal to the random number= output a 1 else output a 0 Thats it. I typically used a 8 bit random number for fast moving data like the DTMF a= nd 16 bit random numbers for slow moving data. The resolution is very similar to a timed PWM. Advantages of random PWM, the noise is easier to filter because it has high= er frequency components than the timed PWM. Disadvantages to the random PWM. It is computationally more intensive than = a timed PWM. Regards, Walter.. -- Walter Banks Byte Craft Limited http://www.bytecraft.com --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .