Shop OBEX P1 Docs P2 Docs Learn Events
Can the counters A/B be setup to create a PWM-signal at a lower frequency than — Parallax Forums

Can the counters A/B be setup to create a PWM-signal at a lower frequency than

StefanL38StefanL38 Posts: 2,292
edited 2010-01-03 18:32 in Propeller 1
Hello Counter-freaks,

as far as I understood the counters of the propeller there is an NCO-mode creating a "PWM"-signal with duty 50%
and there is a dutymode with witch I can create any dutys but only on a system-frequency.

Can two counters be combined to create a PWM-signal duty adjustable from 0% to 100% at lower frequencies say 10kHz?

Any advice is appreciated

best regards

Stefan

Comments

  • SamMishalSamMishal Posts: 468
    edited 2010-01-03 03:11
    Stefan,

    Counters are explained really well with all the various modes and PWM and Duty mode etc. in the
    ·Propeller Education Kit Manual in chapter 7 (pp 119 to 168).

    The NCO mode can be used to create PWM of ANY DUTY at ANY frequency but it requires more
    attention and in SPIN there is a lower limit to the frequency due to time consumed by the Spin code.

    The Duty mode is best run at FULL speed and is more like a DAC.

    Actually you can even combine the two modes to create a WAVE of any form and that is how you can
    play WAV files and also synthesize sound etc.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.RobotBASIC.com


    Post Edited (SamMishal) : 1/3/2010 3:16:31 AM GMT
  • AribaAriba Posts: 2,690
    edited 2010-01-03 03:20
    StefanL38 said...
    Hello Counter-freaks,

    as far as I understood the counters of the propeller there is an NCO-mode creating a "PWM"-signal with duty 50%
    and there is a dutymode with witch I can create any dutys but only on a system-frequency.

    Can two counters be combined to create a PWM-signal duty adjustable from 0% to 100% at lower frequencies say 10kHz?

    Any advice is appreciated

    best regards

    Stefan

    No, this is not possible.
    You need an assembly loop in a cog to restart the counters periodically for a PWM.

    Andy
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-01-03 08:54
    Thanks for the responses Sam and Ariba.

    @Sam: maybe I have to write more to specifiy in which way I want the PWM to work
    Is it possible to do it in a set it and forget style with NO additional pasm-loop to create a 10kHz PWM with duty from 0% to 100%?

    If both counters are in a logical mode and the two counters trigger each other cross over two IO-pins?

    Did anybody think about it in this direction? So it would be for the cost of a second IO-pin but without the cost of a cog

    best regards

    Stefan
  • kuronekokuroneko Posts: 3,623
    edited 2010-01-03 09:02
    StefanL38 said...
    If both counters are in a logical mode and the two counters trigger each other cross over two IO-pins?
    Note that counters in logic mode don't have outputs. So I don't think that's particularly useful to you.
  • SamMishalSamMishal Posts: 468
    edited 2010-01-03 09:32
    StefanL38 said...
    Is it possible to do it in a set it and forget style with NO additional pasm-loop to create a 10kHz PWM with duty from 0% to 100%?
    No.... it is not possible to FORGET IT....you have to keep RESETTING the PHSA/B to the required value (negative something)
    so as to avoid the overflow of the PHSA/B when the FrqA/B is added to it again and agin after it has already gone low.

    So you do have to keep resetting the PhsA/B at the end of the PERIOD to make it go back high again for the next pulse at
    the right time.

    However the Duty mode is a set-and-forget operation. All you have to do is Set the FrqA/B and forget it. It will output the
    right voltage for ever until you change the FrqA/B.
    If both counters are in a logical mode and the two counters trigger each other cross over two IO-pins?
    I am not sure I understand this. The counters in both the Duty and PWM/NCO modes are OUTPUT modes and cannot RECEIVE
    any signals they are just putting out high at appropriate instances.

    In the Duty mode the high lasts only One clock tick and you get the right average voltage·by making as many consecutive highs
    as needed.

    With the PWM the high lasts so long as the PhsA/B register is negative (ie bit 31 is high) which you make sure you initialize with a
    a number to make as many ticks staying high as you need for the DUTY time and then it goes low and you have to count
    as many low ticks as needed to complete the PERIOD and then you set the PhsA/B again to the original number which will repeat
    the whole signal which generates the PWM at the required frequency (ie Period) with the right Duty (ie high time).


    Logical mode operations of the counters DO NOT·OUTPUT anything on the pins. They RECEIVE on the pins·then update the
    PhsA/B by adding FrqA/B if the right logic on the two pins occurs.....but then that is an INTERNAL count and you can use the
    PhsA/B register for certain things like counting or triggering conditions....BUT....it is INTERNAL....there is no PWM or Duty
    generated on any pins.

    So I think this is not what you meant???


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.RobotBASIC.com
    ·
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-01-03 10:24
    Yes. Thank you all for the detailed explanations.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-01-03 18:32
    You can get 50% to 100% with superposition of CTRA and CTRB. Remember that the output pin is the logical OR of the two counter outputs. Set them in NCO mode to affect the same output pin, and run them at the same frequency but with offset phase. If they are at same phase, same "zero line", then you get 50%. If they are offset by 1/2 cycle, PHSA = PHSB+$8000_0000, then the pin will be high 100%.

    If you add an XOR gate at the output, then a second prop pin can select invert or not-invert, in effect extending the range to 0 to 100%.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.