--- Quote Start ---
Hi,
Thankyou
inputting a frequency and duty cycle value , using counters concepts pwm generation is successful . as u said, to overcome the limitations of counters I am trying to learn accumulator techniques.
But target or problem in my code is that... I need to generate a set of frequencies and their pwm from system clock .
Like eg... 50mhz my system clock
range of frequency 5mhz-30mhz with stepsize 5mhz.... ie, 5,10,15,20,25,30 like that. so I would like to add a loop to select the current frequency and then rest of program will be same.
Thankyou
--- Quote End ---
with the simple counter technique you can only generate frequencies that differ in the ratio result of clk/freq and your resolution step is inherently limited to that.
In the accumulator approach you can get much finer resolution (on average) since it is based on phase accumulation.
In fact you don't need frequency step as input in any case.
also I notice that the duty cycle ratio approach posted by mhouse1 doesn't make sense to me for example if duty cycle is 50% then he multiplies that by period say 50*10 then divides it by 2^8/2 ? where is the 100 then as 50 is ratio to 100. May be he assumes some rescaling at the 8 bit input (duty).
Thus in both cases(counter or accum) you have two divisions to be dealt with(clk/freq and conversion of duty ratio).
The accumulator bypasses the first division i.e. it implements it inherently but you need to precompute tuning word
in both cases, the duty ratio is better converted from /100 ratio to /128 ratio