Shop OBEX P1 Docs P2 Docs Learn Events
ctra and b — Parallax Forums

ctra and b

Circuitbuilder9Circuitbuilder9 Posts: 85
edited 2012-03-01 16:32 in Propeller 1
Hey guys, newbie again.
I was looking at the documentation for ctra and ctrb and i am still confused albeit the tedious reading of the registers, especially PWM. Could someone simulate to me what exactly happens to frqa and phsa during a PWM? How do you program that to get a servo moving? Please be specific in an explanation, i really want to understand how the process works.

Comments

  • JonnyMacJonnyMac Posts: 9,102
    edited 2012-02-29 18:47
    Have you studied the AppNote on counters?
    -- http://www.parallaxsemiconductor.com/sites/default/files/appnotes/AN001-P8X32ACounters-v2.0_2.pdf

    After you've done that my servo controller object, which uses a counter to generate the servo pulses, may be worth studying:
    -- http://obex.parallax.com/objects/445/
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-29 19:29
    Circiutbuilder9,

    Part of the confusion stems from the fact that "PWM" is the wrong term for any of the counter modes. A single counter is not capable of PWM output, as most people understand it. What it can output is a very high-frequency DUTY mode, whose percentage of high outputs is proportional to the value in frqx. Filtered, this output is suitable and very effective for rough-and-ready DACs. True PWM output, of the kind you'd use for controlling a servo or driving a DC motor, for example, has to be constantly mediated by code, such as the object that Jon linked to. (To be fair, there is also a trick you can play with two counters to get unmediated PWM output, but I don't have the link handy.)

    -Phil
  • idbruceidbruce Posts: 6,197
    edited 2012-02-29 19:46
    Circuitbuilder9

    I currently have a new thread running, which contains a zip file entitled StepperDriveErz. StepperDriveErz has several methods that utilize counters. Perhaps you may want to take a look at it because it is documented fairly well.

    Here is a link: http://forums.parallax.com/showthread.php?138282-StepperDriveErz

    Bruce
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-29 20:20
    Found it. Check out the links in this thread: http://forums.parallax.com/showthread.php?133797

    -Phil
  • tonyp12tonyp12 Posts: 1,951
    edited 2012-02-29 21:22
    The counter mode called Duty mode is not Pulse-width modulation but Pulse-density modulation.

    As a 25% duty would be (with a 5mhz crystal and 16pll)
    12.5ns On and 37.5ns Off.

    You can not stretch out those times, so it's not a "width" you can adjust.
    And with servos and most mosfets, these 12.5ns bursts are too fast.

    So do it in software and use waitcnt instead.
  • Circuitbuilder9Circuitbuilder9 Posts: 85
    edited 2012-03-01 14:30
    thanks, guys. And also, yes, Jon, I have read the documentation Appnote. I am embarrassed to say that i don't understand a few concepts; freshmen at high school here. I have to simulate things in my mind to understand.
    So, to clarify things a bit, i can drive the servos in DUTY mode on ctra/b? If so, how would i go about doing that? Is it simpler than using NCO/PWM mode?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-01 14:34
    So, to clarify things a bit, i can drive the servos in DUTY mode on ctra/b?
    No, you cannot. As was stated above, you need real PWM output to do that.

    -Phil
  • JonnyMacJonnyMac Posts: 9,102
    edited 2012-03-01 15:43
    Don't worry -- most of us have had to re-read that document a few times for concepts to sink in!

    If you look at my servo object (which I described in a Nuts & Volts column last year) it uses the counter to create the high-resolution pulse to the servo, and that code sits inside a synchronized loop (which uses waitcnt) to keep the timing between leading edges of servo pulses fixed at 2.5ms which causes the entire frame of eight servo outputs to run every 20ms. This technique for creating true PWM where you can vary the duty cycle independent of the frequency is discussed in the AppNote, though the example shown is in PASM. Thankfully, waitcnt works in Spin, too, which is what allowed me to write my advanced servo driver in Spin.
    thanks, guys. And also, yes, Jon, I have read the documentation Appnote. I am embarrassed to say that i don't understand a few concepts; freshmen at high school here. I have to simulate things in my mind to understand.
    So, to clarify things a bit, i can drive the servos in DUTY mode on ctra/b? If so, how would i go about doing that? Is it simpler than using NCO/PWM mode?
  • jmgjmg Posts: 15,173
    edited 2012-03-01 16:32
    thanks, guys. And also, yes, Jon, I have read the documentation Appnote. I am embarrassed to say that i don't understand a few concepts; freshmen at high school here. I have to simulate things in my mind to understand.

    It does not help that it is not well written, and that the structure is unusual and only supports some things normal counters do...

    This has to be an obvious target for a simulator - the control registers are not complex ?
    We wrote a PC stimulus/logger, and there we used a .RAW file format, which is a fairly simple SPICE file.

    You do get excellent Zoom, and it loads into something like LT Spice, so all the Display work is done.

    Using that, approach even a command line pgm could read a Config set, and then generate a results file.
    With spice, you can also visually show a counter as a sawtooth, as well as how long a WAITxx takes.
  • idbruce posted:
    I currently have a new thread running, which contains a zip file entitled StepperDriveErz. StepperDriveErz has several methods that utilize counters. Perhaps you may want to take a look at it because it is documented fairly well.

    Here is the link i found (03/05/2019) to the post.
    https://forums.parallax.com/discussion/123946/eagle-drd-file-parsing-engine

    The file "StepperDriveErz.zip" is in the third post down.
Sign In or Register to comment.