Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

(ASK) PICBASIC to BASCOM

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various
View previous topic :: View next topic  
Author Message
tioaditia

Bascom Member



Joined: 04 Apr 2014
Posts: 3

PostPosted: Fri Apr 04, 2014 10:44 pm    Post subject: (ASK) PICBASIC to BASCOM Reply with quote

SOURCE CODE of how to BASCOM AVR PICBASIC
using ATmega8 to control IC IC TSA5511.
Please help.

Code:
   
   
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

DEFINE I2C_SCLOUT 1    'Set serial clock to bipolar instead of open-collector

' definition I2C communication
        SCL     var             PORTB.1          ' SCL on RB1  
        SDA         var         PORTB.0          ' SDA on RB0

'press:
        MEMO    var     PORTB.3         '
        UP      var     PORTB.4         ' press for FREQ UP RB.4
        DOWN    var     PORTB.5         ' press for FREQ DOWN RB.5

        INPUT   UP                      'Up et Down sont des entrées
        INPUT   DOWN
        INPUT   MEMO

    'Fmin =88 MHz, F max= 108 MHz
' ** DECLARATION OF THE VARIABLES

b1 var BYTE
b2 var BYTE
b3 var BYTE
b5 var BYTE

F1 var WORD
F2 var WORD
F3 var WORD

ADDR1        VAR BYTE
TMP          VAR WORD
TMP_LO       VAR TMP.LOWBYTE
TMP_HI       VAR TMP.HIGHBYTE
PLLBASE      VAR WORD
PLL          VAR WORD
LO           VAR PLL.LOWBYTE
HI           VAR PLL.HIGHBYTE
PAS          VAR BYTE '1=125kHz, 2=250kHz, 4=500kHz, 8=1MHz

'*** INITIAL DATA ***

ADDR1=$C2 'adress I2C of SDA5055 (ADDR1=$C0 , adress I2C of TSA5511)
PLLBASE=696  'beginning with 87 MHz : 87 / 0,125 = 696
PAS = 1 'step of 0.125 MHZ by default    ?????
PAUSE 100
LCDOUT $FE, 1 ' Clear LCD screen
LCDOUT " PLL FM 88-108" ' post text during 1 second
LCDOUT $FE,$C0
LCDOUT " BT-20"
PAUSE 1000

EEPROM 0,[$90,$01] 'initial data TMP = PLLBASE  corresponds to F = 88 MHz


'The starting point is 88 MHz given by PLLBASE. One adds a shift of 125kHz * TMP
'TMP is on 16 bits, therefore 65535 possible frequencies.
'
'*** READING OF THE DECALAGE TMP ***

READ 0,TMP_LO 'reads the 8 bits of weak weight
READ 1,TMP_HI 'reads the 8 bits of strong weight

' *** BEGINNING OF THE PROGRAM***

MAIN:
PLL = PLLBASE + TMP

I2CWRITE SDA,SCL,ADDR1,[HI,LO,$8E] 'Sending of the data to the module

GOSUB CALCUL 'calculate the frequency for posting
GOSUB AFFICHAGE 'post the frequency
PAUSE 500


'*** press routine ***

BOUCLE:
BUTTON UP,0,10,2,b1,1,MONTE 'supervise the button UP
BUTTON DOWN,0,10,2,b2,1,DESCEND 'supervise the button DOWN
BUTTON MEMO,0,255,0,b5,1,STORE 'supervise the button MEMO
' only step size of 125KHz is handled
' BUTTON CH_PAS,1,255,0,b3,1, CHOIX 'supervise the button PAS
PAUSE 100 'pauses of 0.1s
GOTO BOUCLE


MONTE: '** INCREASE THE FREQUENCY OF 1 PAS (STEP)

TMP = TMP + PAS
IF TMP > 168 THEN TMP = 0 'Fmax = 108 MHz  ---> (Fmax - Fmin) / 0,125   -> (108-87)/0,125  = 168
GOTO MAIN

DESCEND: '** DECREASE THE FREQUENCY OF 1 PAS (STEP)

IF TMP = 0 THEN TOP
TMP = TMP - PAS
GOTO MAIN

TOP: TMP=168   ' max reading in Tmp
GOTO MAIN


GOSUB AFFICHAGE 'post the frequency
GOTO BOUCLE


GOTO BOUCLE

CALCUL: ' ** CALCULATION OF THE FREQUENCY

F1 = PLL 'cut off 1GHz
F2 = F1/8 'give them MHz
F3 = 125*(F1//8)


RETURN

AFFICHAGE:
LCDOUT $FE, 1 'Clear LCD screen
LCDOUT #F2 'post the other digits
LCDOUT "." 'post the comma
LCDOUT #F3 'post the Khz
LCDOUT " MHz "

STORE:                         
                WRITE 0, TMP_LO        
                WRITE 1, TMP_H


(BASCOM-AVR version : 2.0.7.7 , Latest : 2.0.7.7 )
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Sat Apr 05, 2014 8:27 am    Post subject: Reply with quote

I did some project for U6205B for ham radio pll some time ago
here is the code I used change for TSA5511 100Khz steps (PLL XTAL 6.4Mhz)

missing info about what Xtal the TSA5511 use 4 mhz or 6.4Mhz ?
with PLL Xtal 6.4 Mhz you get 100Khz steps
4 Mhz is odd 125Khz steps for FM radio

'Test code
Code:
'TSA5511 Test code     NOTE !!!!   pll xtal 6.4 MHz      give 100 Khz steps
' http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=12237&sid=3d032597060ec1e872c3a17eb0287041
'$sim
$regfile = "m8def.DAT"
$crystal = 8000000
$hwstack = 32
$swstack = 24
$framesize = 32

Config Portb.4 = Input                                                                              'KEY UP 100 kHz
Config Portb.5 = Input                                                                              'KEY DOWN 100 kHz                                     '

Portb.4 = 1                                                                                         'UP  set high on keypress we go low
Portb.5 = 1                                                                                         'DOWN set high on keypress we go low

'LCD setup
Config Lcdpin = Pin , Db4 = Portd.0 , Db5 = Portd.1 , Db6 = Portd.2 , Db7 = Portd.3 , E = Portd.4 , Rs = Portd.5
Config Lcd = 16 * 2
Cursor Off

Config Scl = Portb.1                                                                                'serial clock SCL pin 1
Config Sda = Portb.0                                                                                'serial data SDA pin 0

Declare Sub Update

Dim Snd_bytes As Byte
Dim Ax(4)as Byte
Dim Pll As Word
Dim Pll_lsb As Byte
Dim Pll_msb As Byte
Dim Lcd_frq As Single
Dim Pll_lock As Byte

Const Address_write = 194                                                                           'address
Const Charge_pump = 142                                                                             ' 0.100 pr step   6.4 MHz
Const Control_bit = 10                                                                              'port


 Pll = 870                                                                                          '87/0.100

Cls
Locate 1 , 1
Lcd "PLL FM 87-108"
Locate 2 , 5
Lcd "BT-20"
Wait 2

Call Update

Do

   'step 100 Khz  UP
   If Pinb.4 = 0 Then
      Do
        Pll = Pll + 1
        Call Update
     Loop Until Pinb.4 = 1
     Bitwait Pinb.4 , Set                                                                           'wait until key relase
   End If

   'step 100 Khz DOWN
   If Pinb.5 = 0 Then
      Do
        Pll = Pll - 1
        Call Update
      Loop Until Pinb.5 = 1
      Bitwait Pinb.5 , Set                                                                          'wait until key relase
   End If

Loop

Sub Update()
      If Pll > 1080 Then Pll = 870                                                                  ' 108 Mhz
      If Pll < 870 Then Pll = 1080                                                                  '   87 MHz

      Pll_msb = High(pll)
      Pll_lsb = Low(pll)

      Ax(1) = Pll_msb
      Ax(2) = Pll_lsb
      Ax(3) = Charge_pump
      Ax(4) = Control_bit
      Snd_bytes = 4

      I2csend Address_write , Ax(1) , Snd_bytes

      Cls
      Locate 1 , 1
      Lcd_frq = Pll * 0.100
      Lcd Fusing(lcd_frq , "000.000") ; " Mhz"
      Waitms 180
End Sub
End

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
tioaditia

Bascom Member



Joined: 04 Apr 2014
Posts: 3

PostPosted: Sat Apr 05, 2014 8:17 pm    Post subject: Reply with quote

Ok thanks Mr.Kimmi

sorry there is some source code that I do not understand.

1.How step how to determine the outcome of its datasheet, I do not really understand??

2. This code is generated from the sum of the numbers where?

Code:
Const Address_write = 194                                                                           'address
 
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Sat Apr 05, 2014 8:22 pm    Post subject: Reply with quote

Quote:
Const Address_write = 194

same as 5511 I2C address &HC2

pll xtal calculation :
6.4Mhz = 6400/512 = 12.5khz * 8 = 100Khz steps

freq :
99.4 mhz = 994 * 0.1 =99.4 Mhz

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
tioaditia

Bascom Member



Joined: 04 Apr 2014
Posts: 3

PostPosted: Sat Apr 05, 2014 9:10 pm    Post subject: Reply with quote

Ok .. I just try to source code.
thanks for coming down.
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Sat Apr 05, 2014 10:19 pm    Post subject: Reply with quote

Here is a test code for both 4 & 6.4 Mhz

Setup PLL xtal see code
'SELECT THE PLL XTAL FREQ Pll_xtal = 0 ' 6.4Mhz / 1 = 4Mhz
Pll_xtal = 1


Code:
'TSA5511 Test code     NOTE !!!!   pll xtal 6.4 MHz   100 Khz steps       4Mhz 125 Khz    steps
' http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=12237&sid=3d032597060ec1e872c3a17eb0287041
'$sim
$regfile = "m8def.DAT"
$crystal = 8000000
$hwstack = 32
$swstack = 24
$framesize = 32

Config Portb.4 = Input                                                                              'KEY UP  kHz
Config Portb.5 = Input                                                                              'KEY DOWN  kHz                                     '

Portb.4 = 1                                                                                         'UP  set high on keypress we go low
Portb.5 = 1                                                                                         'DOWN set high on keypress we go low

'LCD setup
Config Lcdpin = Pin , Db4 = Portd.0 , Db5 = Portd.1 , Db6 = Portd.2 , Db7 = Portd.3 , E = Portd.4 , Rs = Portd.5
Config Lcd = 16 * 2
Cursor Off

Config Scl = Portb.1                                                                                'serial clock SCL pin 1
Config Sda = Portb.0                                                                                'serial data SDA pin 0

Declare Sub Update

Dim Snd_bytes As Byte
Dim Ax(4)as Byte
Dim Pll As Word
Dim Pll_lsb As Byte
Dim Pll_msb As Byte
Dim Lcd_frq As Single
Dim Pll_lock As Byte
Dim Pll_xtal As Byte
Const Address_write = 194                                                                           'address
Const Charge_pump = 142                                                                             ' 0.100 pr step   6.4 MHz
Const Control_bit = 10                                                                              'port
'********************************************************************************************************************
'SELECT THE PLL XTAL FREQ   0 = 6.4Mhz    /    1 = 4Mhz
Pll_xtal = 1                                                                                        '6.4Mhz
'*********************************************************************************************************************

If Pll_xtal = 0 Then
   Pll = 870                                                                                        '87/0.1        6.4 MHZ
Else
   Pll = 696                                                                                        '87 / 1.25    4 mHZ
End If


Cls
Locate 1 , 1
Lcd "PLL FM 87-108"
Locate 2 , 5
Lcd "BT-20"
Wait 2

Call Update

Do

   'step 1 Khz  UP
   If Pinb.4 = 0 Then
      Do
         Pll = Pll + 1
         Call Update
      Loop Until Pinb.4 = 1
      Bitwait Pinb.4 , Set                                                                           'wait until key relase
   End If

   'step 1 Khz DOWN
   If Pinb.5 = 0 Then
      Do
         Pll = Pll - 1
         Call Update
      Loop Until Pinb.5 = 1
      Bitwait Pinb.5 , Set                                                                          'wait until key relase
   End If

Loop

Sub Update()
   If Pll_xtal = 0 Then
      ''6.4 Mhz
      If Pll > 1080 Then Pll = 870                                                                  ' 108 Mhz
      If Pll < 870 Then Pll = 1080                                                                  '   87 MHz
      Else
      '4 Mhz
      If Pll > 864 Then Pll = 696                                                                   ' >108 Mhz  set 87Mhz
      If Pll < 696 Then Pll = 864                                                                   '   < 87 MHz  set 108 Mhz
   End If
   Pll_msb = High(pll)
   Pll_lsb = Low(pll)

   Ax(1) = Pll_msb
   Ax(2) = Pll_lsb
   Ax(3) = Charge_pump
   Ax(4) = Control_bit
   Snd_bytes = 4

   I2csend Address_write , Ax(1) , Snd_bytes

   Cls
   Locate 1 , 1
   If Pll_xtal = 0 Then
      Lcd_frq = Pll * 0.100                                                                         '6.4 Mhz
   Else
      Lcd_frq = Pll * 0.125                                                                         ' 4 Mhz
   End If
   Lcd Fusing(lcd_frq , "000.000") ; " Mhz"
   Waitms 180
End Sub
End

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
dekorresley

Bascom Member



Joined: 13 Jul 2012
Posts: 41

indonesia.gif
PostPosted: Sun Apr 06, 2014 7:59 pm    Post subject: Reply with quote

whether this program could be for the control IC LC72131??
Please its support Mr.
how about to controler IC LC72131??
Back to top
View user's profile Visit poster's website
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Sun Apr 06, 2014 8:17 pm    Post subject: Reply with quote

no this works for 5511 the LC72131 is not supported by I2c its SPI
I have not used the LC72131 so can't help you with this chip

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum