From what I can find on the forums, it's possible to use a different frequency for the PWM of the analogWrite() function, but I can't find any indication of how to do so. It's not at all necessary for anything I'm doing, but I would like to know how, just to have a better understanding of the way AVR assembly works. It's a Mega2560 if that's important.
If you truly want to understand the topic then all the details are in the datasheet but it is quite density. I would read the newbie's guide first (see below), then read the timers section in the datasheet.
ATmega2560 Datasheet
Newbie's Guide to AVR Timers by Dean Camera
http://deans-avr-tutorials.googlecode.com/svn/trunk/Timers/Output/Timers.pdf
So basically, in fast PWM mode, I would need to set the prescale factor to something less than the default one used by the Arduino. How exactly would I do that?
xolroc:
So basically, in fast PWM mode, I would need to set the prescale factor to something less than the default one used by the Arduino. How exactly would I do that?
Don't know if you are planning on adjusting PWM frequency in the same sketch you were planning on using my Entropy library, but if you are, you need to test performance with the specific PWM settings you use. There have been reports of the jitter technique not working well under conditions different from the default Arduino timer configurations.
If you do run such tests, please send me information on the configuration used and the test results, so I can post them to the libraries Wiki page!
Walt
xolroc:
So basically, in fast PWM mode, I would need to set the prescale factor to something less than the default one used by the Arduino. How exactly would I do that?
See pages 160 and 161 of the datasheet. You need to change one of the TCCRxB registers (where 'x' is the Timer number).
But what code would be used to change those registers? Obviously I need some assembly, but I don't know AVR assembly, so that doesn't help.
Obviously I need some assembly,
Why?
Access to the registers is available through C.
OBVIOUSLY I know next to nothing about the inner workings of the Arduino IDE then.
How would I access the registers through C then?
xolroc:
OBVIOUSLY I know next to nothing about the inner workings of the Arduino IDE then.How would I access the registers through C then?
For example, the following C++ statement sets the TCCR1B register to 1.
TCCR1B = 1;
xolroc:
OBVIOUSLY I know next to nothing about the inner workings of the Arduino IDE then.How would I access the registers through C then?
It would be worthwhile to read the appropriate section of the datasheet for the device your using. Most of the relevant sections have code examples in both assembly and c. The c versions can usually be used as is in the Arduino environment.