Shop OBEX P1 Docs P2 Docs Learn Events
Phase watching and phase degree — Parallax Forums

Phase watching and phase degree

selcukselcuk Posts: 7
edited 2008-05-29 09:11 in Propeller 1
Hi everyone,

I want to follow input frequency and I want to put same frequency to output,But I cant catch same frequnency.cry.gif
My code list below.
please help me...


CON
······· _clkmode = xtal1 + pll16x
······· _XinFREQ = 6_400_000
OBJ
······· txt : "VGA_Text"
VAR
······· long ctr, frq
······· long stack[noparse][[/noparse]80]
······· long stack2[noparse][[/noparse]80]
······· long freq,cog,freqmain
PUB Go | Time, freqnew, freqold,freqtmp
··· txt.start(16)
··· cognew(counterf, @stack)
··· repeat
····· if freqmain <> 0·······
······· pwmb_start
······· freqold := freqmain
······· Time := cnt
······· repeat
········· txt.out($00)················· 'clear the screen
········· txt.dec(freq)················ 'display the value (in Hz)
········· waitcnt(Time+=8_000_000)
········· freqnew := freqmain
·········· if freqnew <> freqold
··········· freqold := freqmain
··········· pwmb_start·······························

PUB pwmb_start | success······· '' pwm B CHANNEL start
· pwm_stop
· success := ( cog := cognew(pwm_b_channel,@stack2) + 1 )
PUB pwm_stop··················· '' pwm B CHANNEL stop
· if cog
··· cogstop(cog~ -1)
PUB counterf | cntadd, cnt_, temp, old···· '' TX frequency meter
· cntadd := 102_400_000
· cnt_· := 0
· temp· := 0
· old·· := 0·
· ctra := ctra_
· frqa := 1···························
· cnt_ := cnt
· repeat
··· waitcnt(cnt_+=cntadd)
··· freq := phsa
··· temp := freq
··· freq := freq - old
··· old· := temp
··· freqmain := freq
PUB pwm_b_channel | cnt_, period········ '' pwm B CHANNEL RUTiNE
· dira[noparse][[/noparse]7]~~
·
· period :=· 102_400_000 / freqmain
· ctra := ctra_pwm
· frqa := 1
· waitpeq(%0,%1,0)············· ' wait for tx signal =0
· waitpeq(%1,%1,0)············· ' wait for tx signal =1
·

· cnt_ := cnt
· cnt_ := cnt_ + period
·
· repeat
··· waitcnt(cnt_+=period)·
··· phsa := - (period / 2)
·····
DAT
ctra_·· long· %01010 << 26 + 0
ctra_pwm····· long····· %00100 << 26 + 7

Comments

  • Ken PetersonKen Peterson Posts: 806
    edited 2008-05-28 19:00
    Can you explain in a little more detail about what you want it to do?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • selcukselcuk Posts: 7
    edited 2008-05-29 07:33
    I want to capture input frequency and I want to put to output same frequency, But I cant hold same frequency...
    Please help me...

    Thanks for all reply
  • selcukselcuk Posts: 7
    edited 2008-05-29 08:06
    I changed my code. Where is my mistake and how can I hold external input frequency to the output.
    CON
    _clkmode = xtal1 +pll16x
    _xinfreq = 6_400_000
    
    VAR
    
    long freq2,ctr,frq
    PUB go | tim
    
    
    cognew(@entry, @freq2)
    ' freq2:= 12_000
    tim := cnt
    repeat
    ' waitcnt(tim += 80_000_000)
    pwm_b(freq2)
    CTRA := ctr 'set CTRA
    FRQA := frq 'set FRQA 
    DIRA[noparse][[/noparse]7]~~   'make pin output
    
    
    
    PRI pwm_b(Freq) | s, d
    
    Freq := Freq #> 0 <# 128_000_000 'limit frequency range
    
    if Freq < 500_000 'if 0 to 499_999 Hz,
    ctr := constant(%00100 << 26)    '..set NCO mode
    s := 1 '..shift = 1
    
    else 'if 500_000 to 128_000_000 Hz,
    ctr := constant(%00010 << 26)   '..set PLL mode
    d := >|((Freq - 1) / 1_000_000) 'determine PLLDIV
    s := 4 - d 'determine shift
    ctr |= d << 23 'set PLLDIV
    
    frq := fraction(Freq, CLKFREQ, s) 'Compute FRQA/FRQB value
    ctr |= 7                          'set PINA to complete CTRA/CTRB value
    
    
    PRI fraction(a, b, shift) : f
    
    if shift > 0 'if shift, pre-shift a or b left
    a <<= shift  'to maintain significant bits while 
    if shift < 0 'insuring proper result
    b <<= -shift
    
    repeat 32    'perform long division of a/b
    f <<= 1
    if a => b
    a -= b
    f++ 
    a <<= 1
    DAT
    org
    entry mov ctra, ctra_ 'establish mode and start counter
    mov frqa, #1          'increment for each edge seen
    mov cnt_, cnt         'setup time delay
    add cnt_, cntadd
    
    :loop waitcnt cnt_, cntadd 'wait for next sample
    mov new, phsa              'record new count
    mov temp, new              'make second copy
    sub new, old               'get delta
    mov old, temp              'set next delta's base
    wrlong new, par
    jmp #:loop
    
    ctra_ long %01010 << 26 + 0 'mode + APIN
    cntadd long 102_400_000     'wait 1 second, answer in Hz
    cnt_ res 1                  'next count to wait on
    new res 1
    old res 1
    temp res 1  
    


    Post Edited (selcuk) : 5/29/2008 9:49:39 AM GMT
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-05-29 09:11
    please put your code in code tags, [noparse][[/noparse] code ] and [noparse][[/noparse] / code ] (but without the spaces).

    You can edit your post to do this.
Sign In or Register to comment.