I'm talking about software, because I want to be able to control the period of the PWM for specific, exact timings. Ultimately my program will cycle through 10 different settings, staying on each one for around 10 seconds.
I don't have frequencies, per se, that I need, but here are the 10 periods I need, in milliseconds:
90, 45, 30, 22.5, 18, 15, 12.86, 11.25, 10, 9
I am familiar with creating software PWM, but until now, I have had no reason to have a specific period. My PWM routines have been:
set pin high
check if duty cycle reached, if so, set pin low
This one, as you say, will simply be:
set pin high
delay (1/2 period)
set pin low
delay (1/2 period)
My question is, how do I set my period to output the exact timing I want? I know I'm going to have to scale my timer for interrupts, but I'm not sure exactly how I can do this. Forgive me, but I'm quite a novice with programming microcontrollers, so I've got a lot to learn, which is why I'm here.
- - - Updated - - -
OK, I'm trying to work through this, and I need to know if I'm on the right track. Please check my math and set me right if I'm not calculating correctly.
With an 8mhz clock, each clock tick takes 0.000125ms, correct?
So if I want a period of 90ms, with a 50% duty cycle, I'm looking to have the interrupts give me a trigger for the flip-flop at 360000ms intervals? This would mean a 16 bit timer set to 0xEA60 (60000) would need a prescaler of 6? Am I on the right track here? Also, am I correct in assuming that because I'm resetting the timer manually within my subroutine, I'm going to need to be very careful to subtract from my timer reset the offset for the instruction cycles that preceed the reset (so that I don't end up with the effective interrupt being 60012, 60016, etc)? Am I making sense?