Shop OBEX P1 Docs P2 Docs Learn Events
Frequency generator — Parallax Forums

Frequency generator

JTCJTC Posts: 60
edited 2007-04-30 12:40 in Propeller 1
· What is the best way to generate a frequency from 0 to 4.5khz
and ramp it up over about 20 to 30 seconds, needs to be a linear ramp.
Then run at that frequecy.
I think there has to be an easy way to do this.
Thanks for an hints you can give.
Jim

Comments

  • OzStampOzStamp Posts: 377
    edited 2007-04-28 11:37
    Hi Jim

    One of my very early SPIN files .. needs a little cleaning up but it is close
    Play with the M values right down the bottom and even delete one of the case statements totally
    It ramps up·. ramps slower...· + runs at a speed forever until reset.

    Cheers· Ronald Nollet Australia

    {{ This code ramps pulses to pin4
    Once ramped up the motor runs forever.
    }}

    CON
    · _clkmode = xtal1 + pll16x
    · _xinfreq = 5_000_000
    · Pulse_width = 2000······ 'Delay, in clock cycles for on/off time
    · Minimum···· = 1500

    Var
    long··· M


    PUB Flashes
    · M := 400_000
    · dira[noparse][[/noparse]4]~~···················· 'Set I/O Pins to output direction··········································
    · dira[noparse][[/noparse]19..23]~~
    ·· repeat
    ····· !outa[noparse][[/noparse]4]
    ····· waitcnt(Pulse_width + cnt )
    ····· !outa[noparse][[/noparse]4]
    ····· waitcnt(M + cnt)
    ····· case M
    ······· 50_000..400_000····· : M := M - 1000·····
    ······· 3999..49999········· : M := M - 5
    ······· 50..3999············ : M :=1400 + Minimum
    ································
  • JTCJTC Posts: 60
    edited 2007-04-28 14:54
    ·· Thank you for your quick response.

    ··· I will give this a try this morning and let you know how it worked.

    ·· My attempt would ramp very slowly a first but as it got faster the change was faster

    ··· due to changes in the speed caused the changes to happen sooner.

    ··· Thanks

    ··· Jim
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-04-28 17:27
    You might also look at AN001, which shows how to do a linear ramp using the counter modules.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • JTCJTC Posts: 60
    edited 2007-04-29 02:09
    · Thanks Tracy. I have it downloaded.

    · Jim
  • JTCJTC Posts: 60
    edited 2007-04-30 12:40
    · Tracy,
    ··· I noticed there is a CTR.spin in the lib that is a very good place to start learning to use counters.
    Thanks for the heads up.
    Jim
    ·
Sign In or Register to comment.