This is somewhat related to Exponential ramp for PWM but closer in spirit to someone else's question, Variable PWM for a PIC18F4550? .

I'm thinking about making a linear, "set-and-forget" PWM signal on the PIC16F1773 that is able to run during sleep and does not require intervention to update the duty cycle. I'm currently weighing two options.

The first uses two PWM modules whose period is set by a small beat frequency, fed to the Complementary Waveform Generator (COG) in "steered PWM mode". In this mode, I can fairly easily define rising and falling edge output events based on the source PWMs, to have a constant period and variable duty cycle.

The second requires one fewer module - only two PWMs are needed, where one is a parent, one is a child, and the parent's offset events reset the PWM counter of the child. The literature calls this "Continuous run [child] mode with sync start and timer reset". Unfortunately, if my interpretation is correct, this mode would not allow for an unsupervised variable duty cycle without also varying the period - effectively the high-time would be constant and the low-time would see linear reduction to zero.

Given that this is driving a LED at ~150Hz, nanosecond-level timing accuracy isn't all that crucial. This system is also not sensitive to very many power considerations, since it's fed by a beefy SMPS with no battery in the picture.

The only major trade-offs I see are:

  • The COG solution draws the additional power of one more module, but given that the frequency of the PWM-only solution ramps up, the increased frequency of CMOS transitions makes power comparison non-trivial
  • If I had a sensitive analogue section (which I don't), the variable-frequency approach could make spectral pollution more difficult to control
  • The variable-frequency approach does not support starting at zero duty cycle, because there must be some constant, non-zero high time

I think the last point is the only one applicable to my situation, which pushes me toward the COG solution. Have I missed any other considerations?

  • \$\begingroup\$ The main issue I read in this question is that you are explaining a process with no context. In other words, what are you trying to achieve? What do you need to happen rather than what you think should happen. Frankly, after reading twice, I have no idea what you want or need. \$\endgroup\$
    – Andy aka
    Nov 22 '20 at 23:34
  • \$\begingroup\$ @Andyaka Drive an LED via PWM ramp from a PIC16F1773 that is asleep. \$\endgroup\$
    – Reinderien
    Nov 23 '20 at 1:17
  • \$\begingroup\$ So you want the LED brightness to vary while the MCU is sleeping? \$\endgroup\$ Nov 23 '20 at 4:24
  • \$\begingroup\$ @bruceabbott yes, exactly \$\endgroup\$
    – Reinderien
    Nov 23 '20 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.