# PLL WITH PIC AND TSA5511

Discussion in 'Microcontrollers' started by savnik, Apr 27, 2006.

1. ### savnikNew Member

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
I have this code and i want to go up the 255 but i don't know

-- ----------------------------------- mhz up/down--------------------
procedure mhz is -- 2--
pll
hd44780_line1
hd44780 = "s" hd44780 = "e" hd44780 = "t" hd44780 = " "
hd44780 = "M" hd44780 = "H" hd44780 = "Z" hd44780 = " "
if down then potin = potin - 1 end if -- down
if up then potin = potin + 1 end if -- up
if potin < 0 then potin = 0 end if
eerste = 0 + potin
if eerste >= 0 & eerste < 100 then derde = 0 end if
if eerste > 99 & eerste < 200 then derde = 1 end if
if eerste > 199 & eerste <= 255 then derde = 2 end if
delay_100ms (1)
end procedure

2. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
I think you want to convert a binary value in the range [0..255] into three decimal digits. Is this correct?

Method 1
Divide by 100. Quotient is the most significant digit
Divide Remainder by 10. Quotient is the tens digit.
Remainder is the units digit.

Method 2
Create three tables of 256 bytes each with the appropriate digits.
The first table has the hundres digit, the second table has the tens digit, and third has the units digit.

You could save one table with the original if-then-else construction in the original post.

Method 3
Do the range check in the original post
Subtract 100*digit from the original number
Divide the result by 10 (A divide by 10 is easier than a general purpose divide)
As in method 1 the quitient is the tens digit and the remainder is the units digit.

There may be other methods, and shortcuts. The journey is half the fun of discovery.

3. ### savnikNew Member

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
I have a pll fm from 0 - 255 mhz with pic16f84a and it works fine.
I want the pll go up the 255 mhz , but i don't know.

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)

How to make a PLL cover that frequency range?
Are you sure it is even possible? I guess it is.

You certainly don't expect the circuit to actually work at that frequency on a breadboard do you?

I see two RF inputs on the chip and I've no idea what working from 0-255 Mhz actually means.

Can you post a schematic of what you are talking about?

You say it is working, so you must be able to send and receive data on the I2C bus, but there was no hint of that in the original post.

6. ### savnikNew Member

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
I test it from 75 - 118 mhz with a VCO for FM and it's work.
The frequency on LCD begin from 0 until 255 mhz if press down or up button , and i want to go up to 255 mhz.

7. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
I still do not understand the problem. Is the problem that you cannot display the frequency on the LCD outside of the 75 to 118 MHz. range or is the problem that you cannot program the part via the I2C port to operate outside that range?

8. ### savnikNew Member

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
No
I want to control a vco 440-470 mhz with this source code which i have , but i can't because the hi frequency , which goes the pll is 255 mhz.( a byte value in the range 0..255)

9. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
OK, but the source code you posted has no meaning because I don't know what you think it is doing. It appearts to be incrementing and decrementing a byte variable. This byte variable may or may not be sent over the I2C bus, along with some addressing information, to control the divider in the PLL.

What follows is upper case yelling -- I know that

POST A SCHEMATIC DIAGRAM OF THE CIRCUIT SO WE CAN TELL WHAT YOU ARE TRYING TO DO.

10. ### savnikNew Member

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
-- includes...
include 16f84_4
include jlib
include hd447804
include i2c

const byte tsa5511 = 0b_1100_000 -- tsa5511 I2C adress

-- ------- pushs buttons --- & light ----------------------------
var volatile bit menu is pin_b4
var volatile bit set is pin_b5
var volatile bit up is pin_b6
var volatile bit down is pin_b7

pin_b4_direction = input -- menu button
pin_b5_direction = input -- set button
pin_b6_direction = input -- up button
pin_b7_direction = input -- down button

-- --------------------------------------------------------------
var byte invoer , flow , fhi , rlow , rhi , qlow , qhi
var byte dummy , eerste, tweede , derde -- tbv setfreq
var byte step , potin , potin1 , teller -- tbv setfreq
var byte lamp -- leds status
var byte cp , pll_setting -- pll

-- ---------------------------------------------------------------
procedure intro is -- INTROTEXT

HD44780_line1
hd44780 = " " hd44780 = " " hd44780 = " " hd44780 = "i"
hd44780 = " " hd44780 = "o" hd44780 = "s" hd44780 = " "
hd44780 = " " hd44780 = " " hd44780 = "v" hd44780 = "v"
hd44780 = "a" hd44780 = " " hd44780 = " " hd44780 = " "
HD44780_line2
hd44780 = " " hd44780 = " " hd44780 = " " hd44780 = " "
hd44780 = " " hd44780 = "F" hd44780 = "M" hd44780 = " "
hd44780 = "P" hd44780 = "L" hd44780 = "L" hd44780 = " "
hd44780 = " " hd44780 = " " hd44780 = " " hd44780 = " "
delay_2s
hd44780_clear
end procedure -- INTROTEXT
-- ---------------------------------------------------------------
procedure pll is
HD44780_line2
print_decimal_1( hd44780 , derde , " " )
print_decimal_2( hd44780 , eerste , "0" )
hd44780 = "."
print_decimal_1( hd44780 , tweede , "0" )
hd44780 = " " hd44780 = "M" hd44780 = "H" hd44780 = "Z"
i2c_write_2 ( tsa5511 , rhi , rlow )

delay_10ms
end procedure

-- ***************************************************************
-- ***************************************************************
Procedure Mul16x8U(byte in out Aa0, byte in out Aa1, byte in out Aa2, byte in Ba0) is
Var byte tempb0,tempb1,loopcount
const _C = 0
Aa0 = Aa1 -- Right justify ==> Left justify
Aa1 = Aa2
assembler
local LOOPUM1608A, LUM1608NAP, LOOPUM1608, LUM1608NA

CLRF Aa2 -- clear partial product
MOVF Aa0,W
MOVWF TEMPB0
MOVF Aa1,W
MOVWF TEMPB1
MOVLW 0x08
MOVWF LOOPCOUNT
LOOPUM1608A: RRF Ba0, F
BTFSC STATUS,_C
GOTO LUM1608NAP
DECFSZ LOOPCOUNT, F
GOTO LOOPUM1608A
CLRF Aa0
CLRF Aa1
RETLW 0x00
LUM1608NAP: BCF STATUS,_C
GOTO LUM1608NA
LOOPUM1608: RRF Ba0, F
BTFSS STATUS,_C
GOTO LUM1608NA
MOVF TEMPB1,W
MOVF TEMPB0,W
BTFSC STATUS,_C
INCFSZ TEMPB0,W
LUM1608NA: RRF Aa0, F
RRF Aa1, F
RRF Aa2, F
DECFSZ LOOPCOUNT, F
GOTO LOOPUM1608
RETLW 0x00
end assembler
end procedure

-- ----------------------------------------------------------------------
procedure reken is
-- eerste (MHz) x 10, dan tweede (kHz) erbij optellen
-- dan resultaat x2 en naar pll
flow = eerste -- flow = MHz'en
mul16x8u ( fhi, flow ,dummy, 0x0A ) -- eerste x 10

-- --- tweede + f (hi, low) = r(hi,low) ---------------------------------
assembler -- khz'en optellen bij
clrf rlow -- resultaat van mul16x8u
clrf rhi -- -----------------------
movf flow , w
movwf rlow
--
movf fhi, w
btfsc status , 0
--
movwf rhi
end assembler
mul16x8u ( dummy , rhi, rlow , 0d02 ) -- mul16x8u x 2
end procedure

-- ++++++++++++++++++++++++++++++++++++freq saven in eeprom++++++++++
procedure saved is -- 5 --
eeprom_put ( 0x01 , derde )
eeprom_put ( 0x02 , tweede )
eeprom_put ( 0x03 , eerste )
eeprom_put ( 0x04 , cp )

reken pll delay_10ms(5)
teller = 5
end procedure
-- ----------------------------------- mhz up/down--------------------
procedure mhz is -- 2--
pll
hd44780_line1
hd44780 = "s" hd44780 = "e" hd44780 = "t" hd44780 = " "
hd44780 = "M" hd44780 = "H" hd44780 = "Z" hd44780 = " "
if down then potin = potin - 1 end if -- down
if up then potin = potin + 1 end if -- up
if potin < 0 then potin = 0 end if
if potin > 255 then potin = 255 end if
eerste = 0 + potin
if eerste >= 0 & eerste < 100 then derde = 0 end if
if eerste > 99 & eerste < 200 then derde = 1 end if
if eerste > 199 & eerste <= 255 then derde = 2 end if
delay_100ms (1)
end procedure
-- ------------------------------------ khz up/down-------------
procedure khz is -- 1 --
pll
hd44780_line1
hd44780 = "s" hd44780 = "e" hd44780 = "t" hd44780 = " "
hd44780 = "k" hd44780 = "H" hd44780 = "Z" hd44780 = " "
if down then potin1 = potin1 - 1 end if -- down
if up then potin1 = potin1 + 1 end if -- up
if potin1 > 9 then potin1 = 9 end if
tweede = potin1
delay_100ms (1)
end procedure

File size:
75.8 KB
Views:
4,000
File size:
42.4 KB
Views:
4,424
11. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
Here is what I see:

procedure pll calls procedure i2c_write_2 which writes 2 byte values contained in rhi and rlow into the pll.

procedure pll is called at the beginning of procedures mhz and khz

procedures mhz and khz modify variables potin, eerste, and derde. What I cant figure out is how these variables affect rhi and rlow.

I see where there is a multiply calculation involving rhi and rlow

My questions are:
Why are you writing to the PLL, via the I2C port, at the beginning of the routines mhz and khz. It would seem logical to me that you would want to write to the PLL, via the I2C port, after you made a change in the variables potin, eerste, and derde.

Also on your diagram where does the 440-470 MHz VCO come in and what is your reference frequency?

12. ### savnikNew Member

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
I have found the source code in the internet and modify it.
I don't know the jal very well and so i ask

13. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
What is the "jal"?

14. ### phalanxMember

Joined:
Oct 22, 2003
Messages:
405
Likes:
7
Location:
New Hampshire, USA
"Just Another Language"

I've never had a reason to use it though.

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
16. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
Since you got this stuff off the internet, I'd like to ask a few more questions, and offer some additional observations.

Did you get the datashett for the TSA5511?
Do you understand how the part works?

The minimum input frequency is 64 MHz. -- not 0!
The drawing does not indicate the reference frequency you are using. If you are using a 3.2 MHz. crystal, then your reference frequency is 6250 Hz., and your minimum frequency step will be 50 Kz. To increase the frequency by 1 Mhz., you need to increase the value of the divisor by twenty(20).

In order for the device to control the VFO via pins PD and UD you need to figure out what the divisor should be.

For 440 MHz. you would apply the fixed divisor of 8 to get 55 Mhz. Now you ask what divisor should I apply to 55 Mhz. to ge the reference frequency of 6250 Hz., and the answer is 8800 decimal. This number must be sent over the I2C port as part of a three byte transaction. This number is obviously bigger than one byte, so no one byte quantity can work at that frequency.

For 470 MHz. you would apply the fixed divisor of 8 to get 58.75 Mhz. Now you ask what divisor will divide 58.75 Mhz. down to 6250 Hz., and the answer is 9400 decimal.

To cover that band takes 600 steps [8800..9400] and surprise surprise
Code (text):

(470 - 440)/600 = 0.05 Mhz = 50 kHz. = 50000 Hz.

Isn't that amazing!

In order to completely program the part you need to send a total of five bytes including the address. It appears that you are only sending three including the address, and relying on its default behavior for the rest. To rely on default behavior is really a very poor idea. Would you program a PIC without giving the configuration word a value?

By the way, I have never seen a jal program before, but I was able to get the sense of what was going on. It was sure an improvement over the original post.

If I were you I wouldn't waste any more time with that misbegotten code -- I'd start over.

Joined:
Apr 27, 2006
Messages:
82
Likes:
0
yes
no very well
i know

18. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
Well OK, from your initial post I thought you were trying to control a VCO from DC(0 frequency) to 255 MHz. This was a mistaken impression on my part. It still does not explain what address byte is written to the I2C port along with the values of rhi and rlow, which I'm guessing correspond to a divisor value. How the values of rhi and rlow are established is beyond me at the moment, but I know what they have to be for 440-470 Mhz at the RF input and a 3.2 Mhz crystal.

Are you able to capture, with a scope, the transactions on the I2C bus? This would be a great clue to what is going on.

Joined:
Mar 31, 2006
Messages:
2
Likes:
0
Location:
Indonesia
20. ### PapabravoWell-Known Member

Joined:
Mar 9, 2006
Messages:
2,889
Likes:
25
Location:
Michigan, USA (GMT-5)
I looked on both pages and did not see a schematic diagram on either one.

21. ### dewoNew Member

Joined:
Mar 31, 2006
Messages:
2
Likes:
0
Location:
Indonesia
sorry just joint this topic