0
\$\begingroup\$

This is a fairly simple question. Is it possible to use additional circuitry, connected to an Arduino PWM pin, to shift it's phase? As far as I can tell, the Arduino PWM pins can be configured for frequency and duty cycle, but I do not believe that phase can be controlled...at least, not out of the box.

I had an Arduino kit, however I'm taking it back today (too expensive, with a ton of parts that I don't need). If I need to use something other than an Arduino to support phase shifted PWM, then I'm open to that.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ What type of frequency do you want to shift the phase of, and relative to what? An external circuit can be possible, but depending on the timing different techniques come into play. Is it possible you could accomplish a shift by commanding a single shorter or longer frame period in software? Note that the actual functional element of an "arduino" is a microcontroller costing a few dollars; the rest is convenient packaging, programming interface and accessories. \$\endgroup\$ Commented Aug 4, 2014 at 16:21
  • \$\begingroup\$ Also want to point out that as long as we are potentially talking about an external phase shift circuit this belongs here and not the Arduino site. \$\endgroup\$ Commented Aug 4, 2014 at 16:23
  • \$\begingroup\$ As others here have said, if you want more precise control of the timing functions on your microcontroller then you must step outside the arduino library and configure it yourself. Read the datasheet section about timer/counters. \$\endgroup\$
    – sherrellbc
    Commented Aug 4, 2014 at 17:25
  • \$\begingroup\$ How much phase shift do you need and how accurate does it have to be? \$\endgroup\$
    – EM Fields
    Commented Aug 4, 2014 at 19:18
  • \$\begingroup\$ I need 180 degrees...it does not have to be super accurate, as far as I understand. \$\endgroup\$
    – jrista
    Commented Aug 4, 2014 at 19:24

1 Answer 1

1
\$\begingroup\$

If we're talking about the ATmega328P, the MCU used in the Arduino Uno, then phase shifts in PWM are possible by manipulating the TCNTx registers as well as using one of the modes that provides a variable TOP for each of the timers (5 or 7 for timer 0 or 2, and 8, 9, 10, 11, 14, and 15 for timer 1). Be sure to change them only as described in the "Modes of Operation" subsections in the section for the relevant timer in the datasheet so as to prevent glitches in the timing from occurring.

\$\endgroup\$
5
  • \$\begingroup\$ Thanks, I hadn't looked at the datasheet before. If it's possible to shift the phase of the Arduino PWM, then that will work. I'm able to pick up the Arduino Uno R3 for about $19, so it isn't that expensive for the convenience of a handy package that can adapt arduino shields and all that. \$\endgroup\$
    – jrista
    Commented Aug 4, 2014 at 17:29
  • \$\begingroup\$ BTW, since this answers the question Arduino-style, I'm ok if you guys want to move this to the Arduino forum. I forgot about that one, but this probably belongs there. \$\endgroup\$
    – jrista
    Commented Aug 4, 2014 at 17:30
  • \$\begingroup\$ You can pick up an ATmega328P for about $3, so don't feel compelled to turn this into an Arduino question. Especially since you can't do all this with the Arduino libraries regardless. \$\endgroup\$ Commented Aug 4, 2014 at 17:31
  • \$\begingroup\$ Aye, I understand I can get the individual parts cheaper, but for the project I'm currently working on, I am planning on using either a WiFi or BlueTooth shield, in which case, having the Arduino is worth it. I'm not an electrical engineer, I just have a minor background in playing around with electronics as a kid, and I'm VERY rusty. Given some more time and practice, I'm sure I could do what I want to do with just the ATMega microcontroller and the specific parts I need, but for now, the convenience of the Arduino is solving problems I don't want to solve myself yet. \$\endgroup\$
    – jrista
    Commented Aug 4, 2014 at 18:02
  • \$\begingroup\$ It's up to you guys whether you want to keep this here or not. I just wanted to let you guys know I'm ok if you decide to move it. \$\endgroup\$
    – jrista
    Commented Aug 4, 2014 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.