Changing timer frequency


I have been using Arduino UNO along with Sparkfun PWM shield which has a TLC-5940 IC for my project. I want to generate 10kHz or more frequency from the PWM shield, but I can't generate more than 3kHz. Is there any way I could generate more than 10kHz frequency? Any help would be much appreciated. Thanks in advance!

I can't generate more than 3kHz.

How are you doing this? From what I see the default pwm frequency should be around 976 Hz.

Are you using the Spark Fun Library GitHub - sparkfun/SparkFun_TLC5940_Arduino_Library: Library for the TLC5940

If so, go into the library files and find tlc_config.h in the src subfolder.

Then change the TLC_PWM_PERIOD in the line here

    \note The default of 8192 means the PWM frequency is 976.5625Hz */
#define TLC_PWM_PERIOD    8192

There is a helpful explanation of the built-in PWM capability here:

Changing the Frequency involves using a different approach (or altering the built-in values associated with analogWrite).

More control is available by setting the registers for the counters associated with PWM. To alter the PWM frequency, you need to set the pre-scaler for the timer you are using. PWM can use Timer/counter 2 a 16 bit timer and Timer/counter 1 an 8 bit timer or Timer/counter 0 also 8 bit. A pre-scaler setting divides the clock frequency (16MHz for UNO) by certain preset number, so the maximum PWM frequency is limited by the clock frequency. An external clock can be used, but it can only be as fast as half the internal clock frequency (as described by Mr Nyquist's sampling theory). That's a starting point. There are heaps of web resources to help you determine what registers, pins, settings etc will get you the result you need. I think you will also find the AVR datasheet for the microcontroller useful - it is very detailed and helpful about registers and settings.

Have fun finding and implementing PWM your way. Once you've played with it, you'll find you can do almost whatever you want to within the limitations of the device!