Two decimals Frecuency division "CTRA"
hal2000
Posts: 66
hi
I'm doing a software that needs to vary the frequency in fraciones, I had this idea to get a decimal.
· frq := fraction(Freq, CLKFREQ*10, s)· "Multiply for 10"
15 = 15hz but with the change 15 = 1.5 Hz :-)
I want to use two decimals. but Multiply it for 100, not run
Does you· any better idea· ?
PUB Synth(CTR_AB, Pin, Freq) | s, d, ctr, frq
· 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*10, s)··· 'Compute FRQA/FRQB value·· " Multiplicamos por 10 para sacar un decimal"
· ctr |= Pin·························· 'set PINA to complete CTRA/CTRB value
· if CTR_AB == "A"
···· CTRA := ctr······················· 'set CTRA
···· FRQA := frq······················· 'set FRQA··················
···· DIRA[noparse][[/noparse]Pin]~~······················· 'make pin output
····
· if CTR_AB == "B"
···· CTRB := ctr······················· 'set CTRB
···· FRQB := frq······················· 'set FRQB··················
···· DIRA[noparse][[/noparse]Pin]~~······················· 'make pin output
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Did the curiosity kill the cat?
......................................
I'm doing a software that needs to vary the frequency in fraciones, I had this idea to get a decimal.
· frq := fraction(Freq, CLKFREQ*10, s)· "Multiply for 10"
15 = 15hz but with the change 15 = 1.5 Hz :-)
I want to use two decimals. but Multiply it for 100, not run
Does you· any better idea· ?
PUB Synth(CTR_AB, Pin, Freq) | s, d, ctr, frq
· 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*10, s)··· 'Compute FRQA/FRQB value·· " Multiplicamos por 10 para sacar un decimal"
· ctr |= Pin·························· 'set PINA to complete CTRA/CTRB value
· if CTR_AB == "A"
···· CTRA := ctr······················· 'set CTRA
···· FRQA := frq······················· 'set FRQA··················
···· DIRA[noparse][[/noparse]Pin]~~······················· 'make pin output
····
· if CTR_AB == "B"
···· CTRB := ctr······················· 'set CTRB
···· FRQB := frq······················· 'set FRQB··················
···· DIRA[noparse][[/noparse]Pin]~~······················· 'make pin output
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Did the curiosity kill the cat?
......................................
Comments
frq := fraction(Freq, CLKFREQ, s) / 100
you get 2 decimals: Freq: 15 = 0.15Hz, Freq: 789 = 7.89 Hz,...
Andy
jejej that simple
I never realized how obvious
I think the oscillator is only accurate to a decimal and the other decimal the half.
Greetings!
I see:
Prop·········Osciloscope
1000_00 = 1000,00 Hz
1000_10 = 1000,10 Hz
1000_11 = 1000,10 Hz
1000_12 = 1000,12 Hz
1000_13 = 1000,12 Hz
1000_14 = 1000,14 Hz
1000_15 = 1000,14 Hz
1000_16 = 1000,16 Hz
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Did the curiosity kill the cat?
......................................
Envio editado por (hal2000) : 2/25/2009 12:13:52 AM GMT
The solution looks obvious, but I also had to think twice. It's a matter of always stay in the 32 bit range of the variables.
The resolution of the frequency is: clkfreq / (2^32) = 0.018 Hz @ 80MHz
Andy
Thanks Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Did the curiosity kill the cat?
......................................