12bit PWM at 20 Khz, IC clock osc limitation

Hello,
I need to run my pwm at minimum 20khz. (I use it for audio purposes)
It works fine on 8 bit nano, (20khz*256 values < 16Mhz clock)

I want to try it on 12bit pwm Ics. Therefore, I need 81.920 Mhz clock (20Khz * 4096 values), this is huge.

TLC5940 & TLC5947 are running at only 30 Mhz.
End of story?
Thanks

I am puzzled over what your problem you seem to perceive that you have.

I regularly use PWM at much higher frequencies without having to change the processor clock. All you have to do is to change the prescaler register driving the PWM.

void setPWMtimer(){
// Set timer1 for 8-bit fast PWM output to use as our analogue output
 TCCR1B = _BV(CS10); // Set prescaler to full 16MHz
 TCCR1A |= _BV(COM1A1); // Pin low when TCNT1=OCR1A
 TCCR1A |= _BV(WGM10); // Use 8-bit fast PWM mode
 TCCR1B |= _BV(WGM12); 
 OCR1AL = 0x80; // start PWM going at half maximum 
}

You may run into trouble of handling the small pulse differences of 12 bit resolution in hardware. Counting pulses is exact, but it does not require a specific duty cycle. Measuring the exact pulse width is much more complicated, and conversion into voltage by a low pass filter will result in ripple. How do you want to process your PWM signal?

@Grumpy_Mike
Yes it works fine for 8 bit, but 12 bit requires higher IC speed clock, doesn't it ?

@DrDiettrich
I'm lighting on and off LED at very slow rate (several seconds), using a low pass filer at PWM output.
It works fine under 5s, but you can notice scaling at slower ignition rates. I was wondering if 12 bit could smooth things out.

Using what circuit, filter? LED are current driven, not voltage nor pulse width.

@DrDiettrich Using PWM out on the nano with RC filter.

Values?

100ohm and 10UF

Try another R before the LED.

Ok I will.
BTW, are there any 12 bit PWM boards running at ~100Mhz ? May I use an external clock ?

NO.

I think you are misunderstanding something here about how PWM is implemented in the hardware of a processor.

An 8 bit PWM requires 8 bit registers to control it. Using 12 bits simply require 12 bit registers, which do not exist. However timer 2 (I think) is capable of using two registers together to make a 16 bit register, and that allows you to do 16 bit PWM on a Uno. Of course you can use only 12 bits of that 16 bit register to work with if you so chose to do so.

Try a net search for 16 bit PWM on an Arduino.

1 Like

What you are running into is that the your eye is working on a logarithmic scale where as the LED is giving a linear output. What you need is a gamma correction on the values you apply to the light.
see:-

Sure 12 bits will give you more levels to go at but by itself it will leave you with the same problem.

@wadafukou is right. If Fast PWM TOP is set to 4095 then it takes 4096 clock ticks for 1 pulse. A pulse frequency of 20 kHz then requires a 81,920 kHz clock (82MHz).

Thanks. I've already added a gamma correction. I will run some 12 bits tests , to see if the difference in noticeable.

You can use a cheap "bluepill" STM32 board. With its 72 MHz core you can able set 20 KHz PWM with 0-3600 range

Thanks. 0-3600, nice found. I don't need to downclock the board as I initialy thought.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.