@janjoh, the low level timer/pwm control stuff is begging for a library which I really want to get to when I clear my plate. You may want to look at the SoftPWM library in the IDE. If you just want to manage two pins then you can reduce the max number of channels and play with the 66us (15KHz) timer interval to get your desired frequencies. One note of caution - don’t go below 10us for the timer interrupt intervals.
@jan, I believe it could but not necessarily as-is. I would look at the _isr_softcount variable in the ISR. It sets the PWM frequency to 15KHz (66us interrupts) / 255 = 60Hz. So, it is possible to lower the count to increase the frequency to 5KHz (count to 3 instead of 255). To get 50-5000hz, you could set the base timer period to 80us. That coupled with a _isr_softcount set for 250 would give you 50Hz. A count of 2 would give you a 6250Hz.
For better accuracy, you can make _isr_softcount a uint16_t instead of uint8_t to give you more granularity on the count. With that and a timer period of 40us (25KHz), a count of 500 would give you 50Hz and a count of 5 would give you 5000Hz.
As it stands, there is no way to change the frequency but it would be easy to add a function to do that with. Test the above to see if the results are as expected and I can the the function after that.