LBB much slower than LB in this pgm

Discussions about the Liberty BASIC language, with particular reference to LB Booster
xtal
Posts: 20
Joined: Fri Apr 06, 2018 12:17 am

LBB much slower than LB in this pgm

Post by xtal » Sat Dec 28, 2019 5:18 pm

any suggestions ?

Have not tried slower serial/i2d lcds



Code: Select all

'' I'm coding a serial lcd for 115200 baud [checking busy bit] and needed a test program, I created the
'' following program in Liberty Basic 4.5.1 pro,  which completes in 43+ seconds..

'' This tests a 20 x 4 Serial LCD @ 115200 baud 

'' I tried LBB before and after compiling, which in 73+ seconds, I suspect the  
'' serial handling , but not sure ....why slower



nomainwin                                    

com = 512         '' LB runs test in 43+ seconds     '' LBB runs test in 73++ 
  
pn=12
''open "com";str$(pn);":115200,n,8,1" for random as #serial 

open "COM12: baud=115200 parity=n data=8 stop=1" for random as #serial 

'' open "COMn: [115200] [n] [8] [1]" for random as #serial   '' not work 

'' LBB Com OPEN
'' open "com12:115200,n,8,1 " for random as #serial

'' Cannot get any to work   
'' open "com12:115200,n,8,1, [odsr=on] [octs=off] [rts=off]" for random as #serial
'' open "COMn: baud=115200, parity=n, data=8, stop=1" for random as #serial
'' open "COMn: [baud=115200] [parity=n] [data=8] [stop=1]
''      [odsr=on] [octs=off] [rts=off] " for random as #serial

'' LB Com OPEN  requires the following for this pgm and comm adapter
''  open "com12:115200,n,8,1,ds0,cs0,rs" for random as #serial
 
'' q is a crap return var

q=   LcdClearLine(1)                              ' clear line 1
q=   LcdClearLine(2)                              ' clear line 2
q=   LcdSetBackLight(0)                           ' 0xB3 @ 0%  set back light  -- works
q=   DelayMS(1000)

FOR ZIP = 5 to 100 step 5
q=   LcdSetCursor(10,1)                           ' set cur 128[Line1] + 10
q=   LcdSendBytes(ZIP)
q=   LcdSendStr("  ")
q=   LcdSetBackLight(ZIP)                         ' 0xB3 @ x%  set back light  -- works
q=   DelayMS(500)
next ZIP

FOR ZIP = 100 to 0 step -5
q=   LcdSetCursor(10,2)                           ' set cur 192[Line2] + 10
q=   LcdSendBytes(ZIP)                            ' print #serial, ZIP;"  "
q=   LcdSendStr("  ")
q=   LcdSetBackLight(ZIP)                         ' 0xB3 @ x%  set back light  -- works
q=   DelayMS(300)
next ZIP

q=   DelayMS(1000)
q=   LcdSetBackLight(75)                          ' 0xB3 @ 75%  set back light  -- works
q=   DelayMS(500)
q=   Beepx()

    first = time$("milliseconds")
FOR ZIP = 500 TO 0 step -5
    NN = ZIP-425                                  ' create variable delay
    if NN >0 then
       NN = NN * 4
    else
       NN=0
    end if
q=   LcdClearDisplay()                             ' 0xB1   clear display   ???????? B1=177
q=   DelayMS(NN)

q=   LcdSetCursor(0,1)                             ' L=1 P=0     print #serial, chr$(128)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line1 Data
q=   LcdSetCursor(0,2)                             ' L=2 P=0     print #serial, chr$(192)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line2 Data
q=   LcdSetCursor(0,3)                             ' L=3 P=0     print #serial, chr$(148)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line3 Data
q=   LcdSetCursor(0,4)                             ' L=4 P=0     print #serial, chr$(212)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line4 Data

q=   DelayMS(NN)
q=   LcdClearDisplay()                             ' 0xB1 clear display ?????????? B1=177
q=   DelayMS(NN)

q=   LcdSetCursor(0,1)
q=   LcdSendStr("01234567890123456789")           ' Line1 Data
q=   LcdSetCursor(0,2)
q=   LcdSendStr("01234567890123456789")           ' Line2 Data
q=   LcdSetCursor(0,3)
q=   LcdSendStr("01234567890123456789")           ' Line3 Data
q=   LcdSetCursor(0,4)
q=   LcdSendStr("01234567890123456789")           ' Line4 Data

q=   DelayMS(NN)
q=   LcdClearLine(1)
q=   LcdSendStr("11111111111111111111")           ' Line1 Data
q=   DelayMS(NN)
q=   LcdClearLine(2)
q=   LcdSendStr("22222222222222222222")           ' Line2 Data
q=   DelayMS(NN)
q=   LcdClearLine(3)
q=   LcdSendStr("33333333333333333333")           ' Line3 Data
q=   DelayMS(NN)
q=   LcdClearLine(4)
q=   LcdSendStr("44444444444444444444")           ' Line4 Data

q=   DelayMS(NN)
q=   LcdClearLine(1)                              ' B9  clr line 1
q=   LcdSetCursor(19,1)                           ' 128 + 19 = 147 => x80 + x13 = x93
q=   LcdSendStr("W")
q=   LcdSetCursor(0,1)
q=   LcdSendStr("Line-1             ")

q=   DelayMS(NN)
q=   LcdClearLine(2)
q=   LcdSetCursor(19,2)                           ' 192 + 19 = 211 => x80 +x64 +x13 = D3
q=   LcdSendStr("X")
q=   LcdSetCursor(0,2)                            ' 192 - C0
q=   LcdSendStr("Line-2             ")

q=   DelayMS(NN)
q=   LcdClearLine(3)                              ' BB  clr line 3
q=   LcdSetCursor(19,3)                           ' 148 + 19 = 167 => x94 + x13 = xA7
q=   LcdSendStr("Y")
q=   LcdSetCursor(0,3)                            ' 148   =>  x94
q=   LcdSendStr("Line-3             ")

q=   DelayMS(NN)
q=   LcdClearLine(4)                              ' 188  => xBC  clr line 4
q=   LcdSetCursor(19,4)                           ' 212 + 19 = 231 => xD4 + x13 = xE7
q=   LcdSendStr("Z")
q=   LcdSetCursor(0,4)                            ' 212 = xD4
q=   LcdSendStr("Line-4             ")            ' display Line-4

q=   LcdSetCursor(8,4)                            ' 212 + 8 = 220 => xd4 + 8 = xDC
q=   LcdSendBytes(ZIP)                            ' display the count
q=   DelayMS(NN)

next ZIP

last = time$("milliseconds")                      ' get last time
total = int(last-first)                           ' compute elapsed MS
q=   LcdSetCursor(8,3)                            ' set curspr @ Line3 Total ms
q=   LcdSendBytes(total)                          ' print elapsed MS
q=   LcdSendStr("-ms")                            '



    close #serial


    end
'=========================================================================================
'                   q=   DelayMS(xxx)     Delay xxx milliseconds -- not ideal but works
'-----------------------------------------------------------------------------------------
function DelayMS(value)
   td = time$("milliseconds") + value
   do
   loop until time$("milliseconds") >= td
end function
'-----------------------------------------------------------------------------------------
function LcdSetCursor(Position,LineX)
   select case LineX
     case 1
        Cpos = 128      ' 128  x80
     case 2
        Cpos = 192      ' 192  xC0
     case 3
        Cpos = 148      ' 148  x94
     case 4
        Cpos = 212      ' 212  xD4
   end select
   print #serial, chr$(Cpos + Position)
end function
'===========================================================================================
function LcdSendBytes(zip)
   PRINT #serial,str$(zip)
end function
'-------------------------------------------------------------------------------------------
function LcdSendStr(X$)
   print #serial, X$
end function
'-------------------------------------------------------------------------------------------
function LcdClearLine(LineX)
   PRINT #serial,chr$(LineX + 184)
end function
'-------------------------------------------------------------------------------------------
function LcdClr()
   PRINT #serial,chr$(1)
end function
'-------------------------------------------------------------------------------------------
function LcdClearDisplay()
   PRINT #serial,chr$(177)
end function
'-------------------------------------------------------------------------------------------
function LcdSetBackLight(percent)               ' percent max is 100
  print #serial, chr$(179);chr$(percent)
end function
'-------------------------------------------------------------------------------------------
function Beepx()
  print #serial,chr$(7)
end function
'----------


guest
Site Admin
Posts: 96
Joined: Tue Apr 03, 2018 1:34 pm

Re: LBB much slower than LB in this pgm

Post by guest » Sat Dec 28, 2019 7:55 pm

xtal wrote:
Sat Dec 28, 2019 5:18 pm
any suggestions ?
Use 'Run... Profile Program' (or Ctrl+F5) to discover where the time is being spent.

Code: Select all

'=========================================================================================
'                   q=   DelayMS(xxx)     Delay xxx milliseconds -- not ideal but works
'-----------------------------------------------------------------------------------------
function DelayMS(value)
   td = time$("milliseconds") + value
   do
   loop until time$("milliseconds") >= td
end function
'-----------------------------------------------------------------------------------------
"Not ideal" indeed! Don't do this, it uses 100% CPU time when waiting so is highly undesirable. The proper way to implement a delay is either to use TIMER or to call the Windows Sleep() API.

xtal
Posts: 20
Joined: Fri Apr 06, 2018 12:17 am

Re: LBB much slower than LB in this pgm

Post by xtal » Sun Dec 29, 2019 1:22 am

With changed code...
LB now 29+ seconds with and without timer 0 added

LBB is 49+ seconds without timer 0
LBB is 61+ seconds with timer 0

You mentioned sleep , I don't see any info on that ....

changed code to this.........

Code: Select all

function DelayMS(value)
   Timer int(value/15)+1,[TF]
   wait
[TF]
Timer 0
 ''  td = time$("milliseconds") + value
 ''  do
 ''  loop until time$("milliseconds") >= td
end function


xtal
Posts: 20
Joined: Fri Apr 06, 2018 12:17 am

Re: LBB much slower than LB in this pgm

Post by xtal » Sun Dec 29, 2019 2:19 am

tried this code:
LB takes 43+ seconds
LBB takes 73+ seconds

Other sugestions?
All thats need to test code is a usb serial adapter then delete nomainwin and add print total before close stmt.

Code: Select all

function DelayMS(value)
  calldll #kernel32,"Sleep",value as ulong,r as void
end function

guest
Site Admin
Posts: 96
Joined: Tue Apr 03, 2018 1:34 pm

Re: LBB much slower than LB in this pgm

Post by guest » Sun Dec 29, 2019 10:17 am

xtal wrote:
Sun Dec 29, 2019 2:19 am
Other sugestions?
I suggested that you used Run.. Profile Program (Ctrl+F5) but you have not reported on the results or listed them here. The whole point of a profiler is to tell you where in a program the time is being spent, so if the program is running more slowly than you expect it should tell you exactly what part of the code is responsible. Once we know that it may be possible to give more specific advice.

Can I just check that you understand that this code outputs three characters - CHR$(1) + CHR$(13) + CHR$(10) - not one:

Code: Select all

   PRINT #serial,chr$(1)
To output just the single character CHR$(1) you would need to add a semicolon:

Code: Select all

   PRINT #serial,chr$(1);

xtal
Posts: 20
Joined: Fri Apr 06, 2018 12:17 am

Re: LBB much slower than LB in this pgm

Post by xtal » Sun Dec 29, 2019 3:01 pm

looks to me like ;
48 seconds of delays --- delays are non essential only for looks will try test without delays
5 seconds setting screen position
36 seconds of sending 20 or less char lines
2.3 seconds of line clearing

the remainder misc serial

With out being able to compare this data to LB I have no clue
why this pgm runs 30 seconds slower on LBB than LB.




Profiler report for C:\Users\msw10\Downloads\Lcdtest1.bas

Sun. 29 Dec 2019, 09:31:33

Figures in the first column indicate approximate
time in milliseconds spent in each program line.

Figures in the second column indicate approximate
percentage of the time spent in each program line.

Time spent profiling: 125.584 seconds.

80: 0.06
0: '' I'm coding a serial lcd for 115200 baud [checking busy bit] and needed a test program, I created the
0: '' following program in Liberty Basic 4.5.1 pro, which copmpletes in 43+ seconds..
0:
0: '' This tests a 20 x 4 Serial LCD @ 115200 baud
0:
0: '' I tried LBB before and after compiling, which in 73+ seconds, I suspect the
0: '' serial handling , but not sure ....
0:
0:
0:
0: ''''nomainwin
0:
0:
0: com = 512 '' LB runs test in 43+ seconds '' LBB runs test in 73++
0:
0: pn=12
0: ''open "com";str$(pn);":115200,n,8,1" for random as #serial
48: 0.04 open "COM12: baud=115200 parity=n data=8 stop=1" for random as #serial
0: '' open "COMn: [115200] [n] [8] [1]" for random as #serial '' not work
0:
0: '' LBB Com OPEN
0: '' open "com12:115200,n,8,1 " for random as #serial
0:
0: '' Cannot get any to work
0: '' open "com12:115200,n,8,1, [odsr=on] [octs=off] [rts=off]" for random as #serial
0: '' open "COMn: baud=115200, parity=n, data=8, stop=1" for random as #serial
0: '' open "COMn: [baud=115200] [parity=n] [data=8] [stop=1]
0: '' [odsr=on] [octs=off] [rts=off] " for random as #serial
0:
0: '' LB Com OPEN requires the following for this pgm and comm adapter
0: '' open "com12:115200,n,8,1,ds0,cs0,rs" for random as #serial
0:
0: '' q is a crap return var
0:
0: q= LcdClearLine(1) ' clear line 1
0: q= LcdClearLine(2) ' clear line 2
0: q= LcdSetBackLight(0) ' 0xB3 @ 0% set back light -- works
0: q= DelayMS(1000)
0:
0: FOR ZIP = 5 to 100 step 5
0: q= LcdSetCursor(10,1) ' set cur 128[Line1] + 10
0: q= LcdSendBytes(ZIP)
2: q= LcdSendStr(" ")
0: q= LcdSetBackLight(ZIP) ' 0xB3 @ x% set back light -- works
0: q= DelayMS(500)
0: next ZIP
0:
0: FOR ZIP = 100 to 0 step -5
0: q= LcdSetCursor(10,2) ' set cur 192[Line2] + 10
0: q= LcdSendBytes(ZIP) ' print #serial, ZIP;" "
0: q= LcdSendStr(" ")
4: q= LcdSetBackLight(ZIP) ' 0xB3 @ x% set back light -- works
4: q= DelayMS(300)
0: next ZIP
0:
0: q= DelayMS(1000)
0: q= LcdSetBackLight(75) ' 0xB3 @ 75% set back light -- works
0: q= DelayMS(500)
0: q= Beepx()
0:
0: first = time$("milliseconds")
0: FOR ZIP = 500 TO 0 step -5
2: NN = ZIP-425 ' create variable delay
0: if NN >0 then
0: NN = NN * 4
0: else
0: NN=0
0: end if
0: q= LcdClearDisplay() ' 0xB1 clear display ???????? B1=177
2: q= DelayMS(NN)
0:
0: q= LcdSetCursor(0,1) ' L=1 P=0 print #serial, chr$(128)
2: q= LcdSendStr("ABCDEFGHIJKLMNOPQRST") ' Line1 Data
0: q= LcdSetCursor(0,2) ' L=2 P=0 print #serial, chr$(192)
0: q= LcdSendStr("ABCDEFGHIJKLMNOPQRST") ' Line2 Data
0: q= LcdSetCursor(0,3) ' L=3 P=0 print #serial, chr$(148)
2: q= LcdSendStr("ABCDEFGHIJKLMNOPQRST") ' Line3 Data
4: q= LcdSetCursor(0,4) ' L=4 P=0 print #serial, chr$(212)
4: q= LcdSendStr("ABCDEFGHIJKLMNOPQRST") ' Line4 Data
0:
4: q= DelayMS(NN)
0: q= LcdClearDisplay() ' 0xB1 clear display ?????????? B1=177
2: q= DelayMS(NN)
0:
2: q= LcdSetCursor(0,1)
0: q= LcdSendStr("01234567890123456789") ' Line1 Data
0: q= LcdSetCursor(0,2)
0: q= LcdSendStr("01234567890123456789") ' Line2 Data
0: q= LcdSetCursor(0,3)
0: q= LcdSendStr("01234567890123456789") ' Line3 Data
4: q= LcdSetCursor(0,4)
0: q= LcdSendStr("01234567890123456789") ' Line4 Data
0:
2: q= DelayMS(NN)
0: q= LcdClearLine(1)
2: q= LcdSendStr("11111111111111111111") ' Line1 Data
2: q= DelayMS(NN)
0: q= LcdClearLine(2)
2: q= LcdSendStr("22222222222222222222") ' Line2 Data
0: q= DelayMS(NN)
0: q= LcdClearLine(3)
0: q= LcdSendStr("33333333333333333333") ' Line3 Data
4: q= DelayMS(NN)
0: q= LcdClearLine(4)
0: q= LcdSendStr("44444444444444444444") ' Line4 Data
0:
2: q= DelayMS(NN)
2: q= LcdClearLine(1) ' B9 clr line 1
4: q= LcdSetCursor(19,1) ' 128 + 19 = 147 => x80 + x13 = x93
0: q= LcdSendStr("W")
6: q= LcdSetCursor(0,1)
2: q= LcdSendStr("Line-1 ")
0:
6: q= DelayMS(NN)
2: q= LcdClearLine(2)
2: q= LcdSetCursor(19,2) ' 192 + 19 = 211 => x80 +x64 +x13 = D3
4: q= LcdSendStr("X")
0: q= LcdSetCursor(0,2) ' 192 - C0
6: q= LcdSendStr("Line-2 ")
0:
2: q= DelayMS(NN)
2: q= LcdClearLine(3) ' BB clr line 3
4: q= LcdSetCursor(19,3) ' 148 + 19 = 167 => x94 + x13 = xA7
0: q= LcdSendStr("Y")
4: q= LcdSetCursor(0,3) ' 148 => x94
2: q= LcdSendStr("Line-3 ")
0:
0: q= DelayMS(NN)
2: q= LcdClearLine(4) ' 188 => xBC clr line 4
0: q= LcdSetCursor(19,4) ' 212 + 19 = 231 => xD4 + x13 = xE7
4: q= LcdSendStr("Z")
0: q= LcdSetCursor(0,4) ' 212 = xD4
0: q= LcdSendStr("Line-4 ") ' display Line-4
0:
2: q= LcdSetCursor(8,4) ' 212 + 8 = 220 => xd4 + 8 = xDC
2: q= LcdSendBytes(ZIP) ' display the count
0: q= DelayMS(NN)
0:
0: next ZIP
0:
0: last = time$("milliseconds") ' get last time
0: total = int(last-first) ' compute elapsed MS
0: q= LcdSetCursor(8,3) ' set curspr @ Line3 Total ms
0: q= LcdSendBytes(total) ' print elapsed MS
0: q= LcdSendStr("-ms") '
0:
2: print total;
0: print " ms"+chr$(10)+chr$(13)
0:
2: close #serial
0:
0:
32042: 25.51 end
0: '=========================================================================================
0: ' q= DelayMS(xxx) Delay xxx milliseconds -- not ideal but works
0: '-----------------------------------------------------------------------------------------
0: '-------------------------------------------------------------------------------------------------
10: 0.01 function DelayMS(value)
47870: 38.12 calldll #kernel32,"Sleep",value as ulong,r as void
16: 0.01 end function
0: '-----------------------------------------------------------------------------------------
4: function LcdSetCursor(Position,LineX)
6: select case LineX
6: case 1
2: Cpos = 128 ' 128 x80
2: case 2
0: Cpos = 192 ' 192 xC0
0: case 3
0: Cpos = 148 ' 148 x94
0: case 4
0: Cpos = 212 ' 212 xD4
0: end select
5098: 4.06 print #serial, chr$(Cpos + Position)
8: 0.01 end function
0: '===========================================================================================
0: function LcdSendBytes(zip)
638: 0.51 PRINT #serial,str$(zip)
0: end function
0: '-------------------------------------------------------------------------------------------
10: 0.01 function LcdSendStr(X$)
36518: 29.08 print #serial, X$
8: 0.01 end function
0: '-------------------------------------------------------------------------------------------
2: function LcdClearLine(LineX)
2274: 1.81 PRINT #serial,chr$(LineX + 184)
6: end function
0: '-------------------------------------------------------------------------------------------
0: function LcdClr()
0: PRINT #serial,chr$(1)
0: end function
0: '-------------------------------------------------------------------------------------------
0: function LcdClearDisplay()
568: 0.45 PRINT #serial,chr$(177)
2: end function
0: '-------------------------------------------------------------------------------------------
0: function LcdSetBackLight(percent) ' percent max is 100
158: 0.13 print #serial, chr$(179);chr$(percent)
0: end function
0: '-------------------------------------------------------------------------------------------
0: function Beepx()
4: print #serial,chr$(7)
0: end function
0: '-------------------------------------------------------------------------------------------
0:
0:
0:

90: 0.07 (Unaccounted for)

xtal
Posts: 20
Joined: Fri Apr 06, 2018 12:17 am

Re: LBB much slower than LB in this pgm

Post by xtal » Sun Dec 29, 2019 3:14 pm

when commenting delay out----

LBB takes 45032 ms
LB takes 14548 ms

still 30 seconds difference

xtal
Posts: 20
Joined: Fri Apr 06, 2018 12:17 am

Re: LBB much slower than LB in this pgm

Post by xtal » Sun Dec 29, 2019 5:40 pm

Program section times and function times - TOTALS in Milliseconds

The LBB SndStr stands out 30+ seconds more

Code: Select all

function LcdSendStr(X$)                  '' total 3
    f1=time$("milliseconds")
   print #serial, X$
    f2=time$("milliseconds")
     total3 = total3 + f2-f1
end function


--- LB  --- Timing                                                                          --- LBB --- Timing 
Open   - 15        17       14       14        14        14        15               14         13      14     14     14     13     14     
BackL  - 507      512      512     514      515      510       514                  631       634       632     631       631     631     631   
Total  -   26274  17252  15850  16786  18617   16448   16142                        45040   45032   45035   45037  45034  45034  45031 
SetCur - 12017  7838    5188    5195   5099     7097     5216                       5260     5255    5249     5263    5262    5249   5259  
SndByt - 428      411     425      425     406       426      423                   652       653      654      651      653      652    651   
SndStr - 6157    6039   6078     6102   5995      6101    6106                      36531   36521   36515  36520   36523  36517  36503 
ClrLne - 2406    2343   2348     2368   2320      2380    2393                       2422    2424     2419    2426    2422    2415   2419  
ClrLcd - 0         0         0          0         0           0         0                   0         0          0         0         0          0        0
ClrDsp - 604    584       585      590     578        591      596                   601       602      599   604        604      604    604   
SetBL  - 129    119       130      129     117        129      129                   172       171      172    172       172      172    172  
Beep   - 3         2         3          3         2           3          3                 3           3          3        3          3         3      3    
Modified PGM

Code: Select all

'''nomainwin                                    ' Data => 0x80 [128] is cmd

global total, total1,total2,total3,total4,total5,total6,total7,total8,total9,total10
com = 512
total = 0
total1 = 0
total2 = 0
total3 = 0
total4 = 0
total5 = 0
total6 = 0
total7 = 0
total8 = 0
total9 = 0
total10 = 0

  f1=time$("milliseconds")
''pn=12
''open "com12";str$(pn);":115200,n,8,1" for random as #serial

open "com12:115200,n,8,1" for random as #serial
''open "com12:115200,n,8,1,cs0" for random as #serial
'open "com12:115200,n,8,1,ds0,cs0,rs" for random as #serial
'open "com12:115200,n,8,1,ds0,cs0,rs" for random as #serial
'open "com12:115200,n,8,1,ds0,cs0,rs" for random as #serial
 f2=time$("milliseconds")
     total9 = total9 + f2-f1                      ' open time  

f1=time$("milliseconds")
q=   LcdClearLine(1)                              ' clear line 1
q=   LcdClearLine(2)                              ' clear line 2
q=   LcdSetBackLight(0)                           ' 0xB3 @ 0%  set back light  -- works

q=   DelayMS(1000)

FOR ZIP = 5 to 100 step 5
q=   LcdSetCursor(10,1)                           ' set cur 128[Line1] + 10
q=   LcdSendBytes(ZIP)
q=   LcdSendStr("  ")
q=   LcdSetBackLight(ZIP)                         ' 0xB3 @ x%  set back light  -- works
q=   DelayMS(500)
next ZIP

FOR ZIP = 100 to 0 step -5
q=   LcdSetCursor(10,2)                           ' set cur 192[Line2] + 10
q=   LcdSendBytes(ZIP)                            ' print #serial, ZIP;"  "
q=   LcdSendStr("  ")
q=   LcdSetBackLight(ZIP)                         ' 0xB3 @ x%  set back light  -- works
q=   DelayMS(300)
next ZIP

q=   DelayMS(1000)
q=   LcdSetBackLight(75)                          ' 0xB3 @ 75%  set back light  -- works
q=   DelayMS(500)
q=   Beepx()
f2=time$("milliseconds")
     total10 = total10 + f2-f1  

    first = time$("milliseconds")
FOR ZIP = 500 TO 0 step -5
    NN = ZIP-425                                  ' create variable delay
    if NN >0 then
       NN = NN * 4
    else
       NN=0
    end if
q=   LcdClearDisplay()                             ' 0xB1   clear display   ???????? B1=177
q=   DelayMS(NN)

q=   LcdSetCursor(0,1)                             ' L=1 P=0     print #serial, chr$(128)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line1 Data
q=   LcdSetCursor(0,2)                             ' L=2 P=0     print #serial, chr$(192)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line2 Data
q=   LcdSetCursor(0,3)                             ' L=3 P=0     print #serial, chr$(148)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line3 Data
q=   LcdSetCursor(0,4)                             ' L=4 P=0     print #serial, chr$(212)
q=   LcdSendStr("ABCDEFGHIJKLMNOPQRST")            ' Line4 Data

q=   DelayMS(NN)
q=   LcdClearDisplay()                             ' 0xB1 clear display ?????????? B1=177
q=   DelayMS(NN)

q=   LcdSetCursor(0,1)
q=   LcdSendStr("01234567890123456789")           ' Line1 Data
q=   LcdSetCursor(0,2)
q=   LcdSendStr("01234567890123456789")           ' Line2 Data
q=   LcdSetCursor(0,3)
q=   LcdSendStr("01234567890123456789")           ' Line3 Data
q=   LcdSetCursor(0,4)
q=   LcdSendStr("01234567890123456789")           ' Line4 Data

q=   DelayMS(NN)
q=   LcdClearLine(1)
q=   LcdSendStr("11111111111111111111")           ' Line1 Data
q=   DelayMS(NN)
q=   LcdClearLine(2)
q=   LcdSendStr("22222222222222222222")           ' Line2 Data
q=   DelayMS(NN)
q=   LcdClearLine(3)
q=   LcdSendStr("33333333333333333333")           ' Line3 Data
q=   DelayMS(NN)
q=   LcdClearLine(4)
q=   LcdSendStr("44444444444444444444")           ' Line4 Data

q=   DelayMS(NN)
q=   LcdClearLine(1)                              ' B9  clr line 1
q=   LcdSetCursor(19,1)                           ' 128 + 19 = 147 => x80 + x13 = x93
q=   LcdSendStr("W")
q=   LcdSetCursor(0,1)
q=   LcdSendStr("Line-1             ")

q=   DelayMS(NN)
q=   LcdClearLine(2)
q=   LcdSetCursor(19,2)                           ' 192 + 19 = 211 => x80 +x64 +x13 = D3
q=   LcdSendStr("X")
q=   LcdSetCursor(0,2)                            ' 192 - C0
q=   LcdSendStr("Line-2             ")

q=   DelayMS(NN)
q=   LcdClearLine(3)                              ' BB  clr line 3
q=   LcdSetCursor(19,3)                           ' 148 + 19 = 167 => x94 + x13 = xA7
q=   LcdSendStr("Y")
q=   LcdSetCursor(0,3)                            ' 148   =>  x94
q=   LcdSendStr("Line-3             ")

q=   DelayMS(NN)
q=   LcdClearLine(4)                              ' 188  => xBC  clr line 4
q=   LcdSetCursor(19,4)                           ' 212 + 19 = 231 => xD4 + x13 = xE7
q=   LcdSendStr("Z")
q=   LcdSetCursor(0,4)                            ' 212 = xD4
q=   LcdSendStr("Line-4             ")            ' display Line-4

q=   LcdSetCursor(8,4)                            ' 212 + 8 = 220 => xd4 + 8 = xDC
q=   LcdSendBytes(ZIP)                            ' display the count
q=   DelayMS(NN)

next ZIP

last = time$("milliseconds")                      ' get last time
total = int(last-first)                           ' compute elapsed MS
q=   LcdSetCursor(8,3)                            ' set curspr @ Line3 Total ms
q=   LcdSendBytes(total)                          ' print elapsed MS
q=   LcdSendStr("-ms")                            '

print "--- LBB --- Timing"
print "Open   - "; : print total9
print "BackL  - "; : print total10
print "Total  - "; : print total
print "SetCur - "; : print total1
print "SndByt - "; : print total2
print "SndStr - "; : print total3
print "ClrLne - "; : print total4
print "ClrLcd - "; : print total5
print "ClrDsp - "; : print total6
print "SetBL  - "; : print total7
print "Beep   - "; : print total8

    close #serial


    end
'=========================================================================================
'                   q=   DelayMS(xxx)     Delay xxx milliseconds -- not ideal but works
'-----------------------------------------------------------------------------------------
function DelayMS(value)

''calldll #kernel32,"Sleep",value as ulong,r as void

end function
'-----------------------------------------------------------------------------------------
function LcdSetCursor(Position,LineX)   '' total 1
    f1=time$("milliseconds")
   select case LineX
     case 1
        Cpos = 128      ' 128  x80
     case 2
        Cpos = 192      ' 192  xC0
     case 3
        Cpos = 148      ' 148  x94
     case 4
        Cpos = 212      ' 212  xD4
   end select
   print #serial, chr$(Cpos + Position)
     f2=time$("milliseconds")
     total1 = total1 + f2-f1
end function
'===========================================================================================
function LcdSendBytes(zip)               '' total 2
    f1=time$("milliseconds")
   PRINT #serial,str$(zip)
    f2=time$("milliseconds")
     total2 = total2 + f2-f1
end function
'-------------------------------------------------------------------------------------------
function LcdSendStr(X$)                  '' total 3
    f1=time$("milliseconds")
   print #serial, X$
    f2=time$("milliseconds")
     total3 = total3 + f2-f1
end function
'-------------------------------------------------------------------------------------------
function LcdClearLine(LineX)             '' total 4
    f1=time$("milliseconds")
   PRINT #serial,chr$(LineX + 184)
    f2=time$("milliseconds")
     total4 = total4 + f2-f1
end function
'-------------------------------------------------------------------------------------------
function LcdClr()                        '' total 5
    f1=time$("milliseconds")
   PRINT #serial,chr$(1)
    f2=time$("milliseconds")
     total5 = total5 + f2-f1
end function
'-------------------------------------------------------------------------------------------
function LcdClearDisplay()                '' total 6
    f1=time$("milliseconds")
   PRINT #serial,chr$(177)
    f2=time$("milliseconds")
     total6 = total6 + f2-f1
end function
'-------------------------------------------------------------------------------------------
function LcdSetBackLight(percent)           '' total 7    ' percent max is 100
   f1=time$("milliseconds")
  print #serial, chr$(179);chr$(percent)
   f2=time$("milliseconds")
     total7 = total7 + f2-f1
end function
'-------------------------------------------------------------------------------------------
function Beepx()                            '' total 8
    f1=time$("milliseconds")
  print #serial,chr$(7)
   f2=time$("milliseconds")
     total8 = total8 + f2-f1

end function
'-------------------------------------------------------------------------------------------


guest
Site Admin
Posts: 96
Joined: Tue Apr 03, 2018 1:34 pm

Re: LBB much slower than LB in this pgm

Post by guest » Sun Dec 29, 2019 6:50 pm

xtal wrote:
Sun Dec 29, 2019 3:01 pm
I have no clue
why this pgm runs 30 seconds slower on LBB than LB.
LBB simply calls the standard Windows API functions for accessing the serial port, so the time taken should depend only on the baud rate and the number of characters sent. At 115200 baud each character takes about 87 microseconds to send, so you should be able to calculate the total time from that. The only thing which might slow it down is if you are using some form of flow-control, e.g. CTS, to stop the PC sending data if the receiving end is not ready to receive it.

Further diagnosis will probably require using an oscilloscope to monitor the serial connection directly, if you have one.

xtal
Posts: 20
Joined: Fri Apr 06, 2018 12:17 am

Re: LBB much slower than LB in this pgm

Post by xtal » Sun Dec 29, 2019 7:16 pm

I'm using usb to serial adapter IE no flow control unless its embeded inside usb driver, how ever I've used 2 different adapters and have
similiar results.

I use this for LBB open "com12:115200,n,8,1" for random as #serial
[ cannot figure out options equiv to ds0,cs0,rs]


I use this for LB open "com12:115200,n,8,1,ds0,cs0,rs" for random as #serial
[ this will work with cs0 only, but makes no difference, cannot get
LB to work with open "com12:115200,n,8,1" for random as #serial
may be windows 10 ??]

I agree it looks like throttling on the LBB side

I do notice that LB is more sensitive to external events IE counts vary more , where as LBB counts are more consistant,
why is that???

I do have a scope, however I don't think its worth looking at , raw Tx hmmm....

Post Reply