Shop OBEX P1 Docs P2 Docs Learn Events
When counters are in Duty cycle mode... Solved - Fun solution attached! — Parallax Forums

When counters are in Duty cycle mode... Solved - Fun solution attached!

KyeKye Posts: 2,200
edited 2009-08-17 04:16 in Propeller 1
I'm just trying to wrap my head arround this.

I want to use the counters in duty cycle mode to output a frequency from 0 to 22050 HZ. However, the more I look at how they work. The more it comes to life that unless the carry bit is set in the current adding operation at each clock cycle the carry bit goes to zero. Which is expected.

But that also means that its very hard to make any low frequency output.... So,·Can the duty cycle mode be used for making low frequency outputs then?

I wanted to make a simple piece of code that let you change the frequency of an output and the duty cycle so that you could change the volume of an output and the tone of that output for lets say a speaker.

The goal is not to use a cog however and to only ust the counters... I could not find an example of this in the counter appnote. Only a duty cycle and synth example that each required a cog.

I belive I may be asking to much of a cog's counter's however...

Thanks for any help.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Post Edited (Kye) : 8/17/2009 3:44:24 AM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-17 02:58
    It's best to divorce any notions of frequency from DUTY mode. It's not like a PWM, where you can control frequency and duty cycle independently. With DUTY mode, the "frequency", if you can call it that, is completely dependent on the duty cycle. With an 80MHz clock, a 50% duty cycle will be 40MHz; 25% or 75% duty cycle, 20MHz; and so forth. Some oddball duty cycles will have waveforms that lack a consistent frequency.

    If what you're looking for is a PWM, your best bet is to consider one of the PWM objects in the OBEX.

    -Phil
  • KyeKye Posts: 2,200
    edited 2009-08-17 03:41
    Ah, this is fun. So I combined the counters using one for duty to control volume and one for NCO to control frequency. And its works nicely with any spin interpreter cog.

    The trick is that the NCO·counter controls the frequency but the Duty counter controls the high masking time vs low time. Since a speaker for example needs an AC signal then·when the duty cycle cog is masking the NCO output the volume is changed because the speaker is spending to much time with a stable voltage that is not changing.

    Pretty nice effect for the prop to be able to generate so easily.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • JonnyMacJonnyMac Posts: 9,197
    edited 2009-08-17 03:48
    I've actually asked Ken to ask Chip to include a another phase register in the Propeller II counters so that we can do set-and-forget PWM with a designated frequency and duty cycle -- like we can with the SX. For example, PHS1A would be the "on" time of the output and PHS2A would be the total counts in the cycle ("off" time is PHS2A - PHS1A).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-17 04:10
    So, Kye, are you saying that both counters output to the same pin, then, and are thus ORed? That should actually work if your downstream circuitry (or the speaker itself) can filter out the DUTY doody. Certain frequency/phase combinations could produce a noticable beat phenomenon, however.

    Jon, what you've suggested is definitely needed.

    -Phil
  • KyeKye Posts: 2,200
    edited 2009-08-17 04:16
    Its not full proof but it works as good as I need it.

    And, yes the speaker is needed to filter the square wave output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.