Shop OBEX P1 Docs P2 Docs Learn Events
frequency synthesizer — Parallax Forums

frequency synthesizer

gambrinogambrino Posts: 28
edited 2008-10-26 16:42 in Learn with BlocklyProp
Hello Forum , can i use this code to generate a frequency of 4KHz ( for example) with duty cycle of 50% using Synth and FrequencySynth.spin from Propeller Library :
CON

_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000

Pin = 5

Frequency = 4_000
VAR

OBJ
Freq : "Synth"

PUB main
CTRA := %00100 << 26 'sets CTRA's CTRMODE field to the NCO mode (%00100) and all other bits to zero
CTRB := %00000 'Counter disabled (off)
PUB CTR_Demo

Freq.Synth("A",Pin, Frequency)

repeat 'loop forever to keep cog alive

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-26 16:42
    You need to take out these lines:

    CTRA := %00100 << 26 'sets CTRA's CTRMODE field to the NCO mode (%00100) and all other bits to zero
    CTRB := %00000 'Counter disabled (off)
    PUB CTR_Demo

    The Freq.Synth call will initialize CTRA and CTRB is disabled by default

    The PUB CTR_Demo is not needed and will result in the program not working (since it's never called and PUB main will exit, stopping the cog).
Sign In or Register to comment.