Varying the duty cycle of an 20 khz digital square wave

Hello Friends,

For my solar charge controller i want to generate a 20khz square wave signal and i need to vary the ON/OFF timing of that signal. As i searched some people said to use timer . I want to know how to use the timer to generate the 20khz signal and vary the duty cycle . if u have any sketch or useful link about my issue please reply.

Thanks in advance

As usual with just about any technical inquiry about Arduino, you should take a look at Nick Gammon's forum for his tutorial on the use of timers.

Thanks PeterH +1'd

The link was so useful :)