Shop OBEX P1 Docs P2 Docs Learn Events
Need help getting Tracking freq generator to work!! — Parallax Forums

Need help getting Tracking freq generator to work!!

Armondo522Armondo522 Posts: 9
edited 2007-04-10 16:51 in Propeller 1
I have used the Propeller chip on numerous projects and I am very impressed with its capabilities. I find more and more each day.My problem is: I need to generate 4 distinct frequencies. 3 are preset and that section works very well. The 4th section needs to track an incoming frequency and multiply it up by 100. It works when the software first starts then does not track or reset the 4th generator. i am at wits end...Any help would be appreciated.


Regardssmhair.gif


OBJ
· Freq : "Synth_sweep_BP"
····
PUB CTR_main····················································· ''' Start of Main Routine
· DirA[noparse][[/noparse]5]:=%1··········· 'control signal
· Dira[noparse][[/noparse]7] :=%1·········· 'control signal
· DirA[noparse][[/noparse]3] := %0········· 'counter in
· DirA[noparse][[/noparse]6] := %1········· 'auto in
· DirA[noparse][[/noparse]10] := %0········ 'ms start sequence
· OUTA[noparse][[/noparse]7]:=%0
·· dirA[noparse][[/noparse]0..2]:=%1······· ' output ports 0,1,2

· dirA[noparse][[/noparse]9]:=%1
· OUTA[noparse][[/noparse]9]:=%1··········· 'set port to output 1
· dirA[noparse][[/noparse]11]:=%1
· OUTA[noparse][[/noparse]11]:=%0·········· 'set port to ground





· cognew(ref_in,@stack4)······················ ' output 240 hz clk· always active··························· works
· cognew(FirstCtr,@stack3)···················· ' output 20khz and 24khz clocks always active·········· Works
·




Repeat
· get_freq······································ 'read input freq and update 4th counter
repeat

''####################· end of Main Routine


PUB FirstCtr
· Freq.Synth("A",Pin,FrequencyB)······ ' 20khz·
· Freq.Synth("B",PinA,FrequencyC)····· ' 24khz·
repeat



pub get_freq···
··· Frequency1 :=0
··· CTRA := 0 'Clear CTRA settings
··· CTRA := (%01010 << 26 ) | (%001 << 23) | (0 << 9) | (3) 'Trigger to count ' rising edge on A4
··· FRQA := 1000 'Count 1000 each trigger
··· PHSA := 0 'Clear accumulated value
··· WaitCNT( 80_000_000 + CNT ) 'Wait for 1 second
··· Frequency1 := PHSA / 1000
··············· if Frequency1 > 20 ' and INa[noparse][[/noparse]6]· enable at a later time bit 6
·······
····················· freq2:=frequency1*100······ ' need 100 times roll-off freq
·······
····················· Freq.synth_sweep (Freq2)·· 'Should set new frequency in counter·4

··· WaitCNT( 80_000_000/100 + CNT )
·
repeat




·····
pub Ref_gen2···· ' not used in this program
·}············································· ' keep cog alive
pub ctr_sweep
· Freq.synth_sweep(freq2)
repeat
pub ref_in
Freq.ref_gen
repeat···························

'··································································· The following works but only on first pass through

pub synth_sweep (Freq2) | s, d, ctr, frq
·· if Freq2 < 500_000···················
··· ctr := constant(%00100 << 26)·····
··· s := 1····························
·· else································
··· ctr := constant(%00010 << 26)····· '..set PLL mode
··· d := >|((Freq2 - 1) / 1_000_000)··· 'determine PLLDIV
··· s := 4 - d························ 'determine shift
··· ctr |= d << 23···················· 'set PLLDIV
·
·· frq := fraction(Freq2, CLKFREQ, s)··· 'Compute FRQA value
·· ctr |= 2'Pin·························· 'set PINA to complete CTRA/CTRB value
···· CTRA := ctr······················· 'set CTRA
···· FRQA := frq······················· 'set FRQA··················
···· DIRA[noparse][[/noparse]2]~~······················· 'make pin output
·················
repeat·································


Post Edited (Armondo522) : 4/9/2007 7:38:26 PM GMT

Comments

  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-04-09 20:38
    To measure the frequency, you are better off using assembly. You are losing several clock cycles in your spin code. You can use the one in the below link. Watch out for the typo on teh cognew command, there is supposed to be an extra @.
    http://www.parallax.com/dl/appnt/prop/AN001-PropellerCounters-v1.0.zip

    Do you care about matching the phase of the input frequencies? Are you aware of the fact that since you are only using a 1 bit DAC (MSB of phase register), there will be a lot of jitter if you work at high frequencies?

    Also, I am having trouble understanding the "repeat"s in your code. There's a feature in the IDE view options that helps the visualization of the indentations by adding light gray lines to group blocks of code.
  • Armondo522Armondo522 Posts: 9
    edited 2007-04-09 21:31
    Thanks Toaster for quick reply.

    I do not care about phase jitter or phaseing. The highest freq i will put out is 3 MHZ. It appears to read the frequency correct, but only on the first pass through the routine. After that it appears to ignore the whole get_freq routine. I put the repeats in to keep the cogs alive..is that a wrong assumption. If i take the repeat out, the frequency changes, but at a 10 ms rate which is unacceptable. I will keep on pluggin



    thanks again.yeah.gif
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-04-09 23:25
    I just visually checked your code, I don't want to mess with my current Propeller circuit. To me, it seems that your problem is that cog0 executes pub get_freq and gets stuck at the end with the "repeat" that does nothing.

    I'd recommend that you use the GEAR Windows emulator to load up your program and check how the cogs are running. Scroll to the end of
    http://forums.parallax.com/forums/default.aspx?f=25&m=164602
    and obtain your copy.

    Also, you need to download the Microsoft .net extensions mentioned in the thread.
  • Armondo522Armondo522 Posts: 9
    edited 2007-04-10 16:51
    Toaster...
    Thanks for the help. The problem was I was reading and writing the frequency info to the same counter..One should have been A the other B..It works great now...
Sign In or Register to comment.