Shop OBEX P1 Docs P2 Docs Learn Events
Adjustable Frequency/Duty with counters from Spin? — Parallax Forums

Adjustable Frequency/Duty with counters from Spin?

T ChapT Chap Posts: 4,223
edited 2007-03-14 00:20 in Propeller 1
Is there a trick to get the counters to allow for ANY set frequency(period) with adjustable Duty from 0 - 100 modified from Spin? I've been in the AN001 for several hours and can't find a solution. I'd like to be able to set the counters anywhere from 1Hz to it's max rate, with any duty.

The PWM object appears to use %00100, beyond that I can't tell what is going on in the assembly routine. I am after control of the timeHigh and Period control from Spin, using a counter for PWM instead of giving up a cog.

Post Edited (originator) : 3/13/2007 12:03:41 PM GMT

Comments

  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-03-13 13:18
    To do proper PWM requires a cog to oversee it, the counters can't just do it.

    There is still an advantage over doing it in pure assembly/spin I think because the processor has more time to do other things if you want.

    Graham
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-13 17:04
    Duty cycle in Spin is only possible if you have very low frequency output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • rokickirokicki Posts: 1,000
    edited 2007-03-13 18:12
    If a duty cycle of only 50%+ works, you can use two overlapping counters to do this at any frequency, unsupervised.

    If you need a duty cycle of 50%-, you can use *three* counters (two at 50%+, and one to invert that result). Can
    anyone figure out how to get a duty cycle of less than 50% (and obviously more than 1/freq) for an arbitrary frequency
    using only two counters?
  • T ChapT Chap Posts: 4,223
    edited 2007-03-13 18:23
    I have been looking at various scenerios of multiple counters, a few pins, plus the counter logic functions to do it in some convoluted way. No luck yet. All I want Spin to do is update the counter registers as needed. Ramping Duty up and down is part of the requirement 0 - 100 over Time and 100 - 0 over Time. If it can't be done, then at least I tried an learned a whole lot about the counters. The process to find the method has really turned on a lightbulb regarding the counters and their potential.

    Request for future Prop [noparse]:)[/noparse]

    1. Conditional PHSx reset using Pins or counter states(no software) (i.e. Apin & Bpin = PHSx := 0)
    2. Conditional PHSx rollback/rollahead(val) Apin & Bpin = PHSx := -1000

    Post Edited (originator) : 3/14/2007 2:20:53 AM GMT
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2007-03-13 18:32
    Really nice idea, rokicki.
    If you have 50%+, then a simple inverter at the output will give the 50%-. The inversion could be made via an XOR gate, conditional on another output pin.

    For those who are not familiar with the counter pin logic, if you have two counters affect the same pin, the pin will be high if either of the counters set it high, and low only if both counters want low. Therefore by adjusting presetting the relative phase of two counters running at the same frequency, the output can be made high for any % greater than 50%. Freerunning without program intervention.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • T ChapT Chap Posts: 4,223
    edited 2007-03-14 00:12
    If the cog where a counter was initialized is busy, can other cogs update the counters registers externally by some means, without the first cogs attention?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-14 00:20
    No

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.