frequency synthesizer
gambrino
Posts: 28
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
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
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).