Multi-digit word variable to string


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    OK, I see.

    So, if you want to move the trackbar to position $28 you will use

    Code:
    HserOut [$01,$05,$00,$00,$28,$2C]
    and the slider will goto position $28.

    But I guess you have to set beforehand the two ends of the trackbar? I mean the zero can be 100 and the maximum position 200, or whatever.

    Can you try and see if you can move the trackbar just by sending straight in values? and the CRC computed by hand.

    Then you may do more complicated things.

    Ioannis

  2. #2
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    in my case i do not use the trackbar, but the LED digits as shown below.

    Name:  command5.png
Views: 1213
Size:  90.0 KB

    In the software 4D SYstems they have, you can set manually a number for example 167, and will show you the command as shown in the SET DIGIT VALUE:

    Name:  command6.png
Views: 1204
Size:  36.4 KB

    I have tried to give manually a constant number and it worked!

    what i did is:

    i set a new var mTEMP ' for manually hex number and
    a new var mTEMPIR ' for manually hex number as well.

    In our case the number 167 for:

    Code:
    mTEMP = $00
    mTEMPIR = $a7
    then i did the CS calculation and return to the HSEROUT command.

    Code:
    IRCS=0
    IRCS= $01^$0F^$00^mTEMP
    IRCS = IRCS ^ mTEMPIR
    I placed it with:

    Code:
    HSEROUT [$01,$0F,$00,mTEMP,mTEMPIR,IRCS)
    then i got the right result on the display.

    The problem is that when i use the variables i cannot get the right values.
    Last edited by astanapane; - 18th December 2021 at 22:14.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    i assume the real question in this jumble is how do i sent a word var as a binary number msb first using hserout

    Temp var word
    Temp=167


    HSEROUT [$01,$0F,$00,Temp.highbyte,Temp.lowbyte,IRCS)
    Warning I'm not a teacher

  4. #4
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard!!!!

    it really worked!!!

    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                         VAR for IR to LCD          '
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    IRCS         var byte       ' this is the checksum for the IR required in external display command
    TEMP         var word       ' this is the word variable for TEMP 
    temperature  var word       ' for result and output to lcd 
    TEMPIR       var word       ' set a variable tempir 
    Remainder    var word       ' Get the remainder = tempir//50
    
    '------------------------------------------------------------------------------*
    '                    Measure IR object temp sent to uLCD                          *
    '------------------------------------------------------------------------------*
    object:
    
    reg    = $07             ' based on the datasheet $07 is the object's temp
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    addr   = %10110101       ' $B5  Binary value: %10110101
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07
    
    tempir = (temp.highbyte << 8) + temp.lowbyte
    
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    
    pause 100
    gosub display
    return
    
    '------------------------------------------------------------------------------*
    '                    IR  Display 1 the parameters                              *
    '------------------------------------------------------------------------------*
    display: ' IR TEMP 
    hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
    Hserin2  timeout,error,[wait(6)]
    hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature,".",dec2 remainder,"*C",00] 'this one works on display 1 which doesnt require CS 
    Hserin2  timeout,error,[wait(6)]
     
    
    gosub checksum2    
    HSEROUT [$01,$0F,$00,temperature.highbyte,temperature.lowbyte,IRCS)   ' this one works.
    Hserin  timeout,error,[wait(6)]
    return
    
    '------------------------------------------------------------------------------|
    '                               CHECKSUM IR                                    |
    '------------------------------------------------------------------------------|
    checksum2:
    IRCS = 0
    IRCS = $01 ^ $0F ^ $00 ^ temperature
    'IRCS = IRCS ^ remainder ' commended this as i need to figure out how to import it in the HSEROUT command.
    return
    Now i'm trying to figure out how to add the remainder in the command.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Now i'm trying to figure out how to add the remainder in the command.
    i hope this is not a medical diagnostic device
    your temperature calculation is not accurate and the remainder calculation is mathematically incorrect


    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    yields the temp in deg C to about 1 deg of resolution with an error of +- 1 degree

    Code:
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    calculated the 100 modulus of the temp in deg kelvin

    adding them together is nonsense , trying to display a two decimal point result is from any of these results is just not right

    Name:  Screenshot 2021-12-19 163013.jpg
Views: 1185
Size:  194.2 KB

    Code:
    wtf tempir = (temp.highbyte << 8) + temp.lowbyte ;just Nooooo! its the hardest most convoluted way i have ever encountered to go 
    tempir = temp which serves no purpose anyway
    
    
    
    
    don't like this either, it pisses away too much resolution hence its not particularly accurate 
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    
    
    ;this is good  although it could be even more accurate [temperature  = temp*2  - 27315 ; temp x 2 - 273.15*100 ] >==>temperature*100] if the raw value won't exceed 32768 
    
    
    temperature  = (temp  - 13657)<<1  ; (temp-[273.15*50]) x 2   <==> temperature*100; is good
    
    
    
    
    i make the assumption temperature * 100 is the value required by the slider display
    
    
    tempir and remainder are not needed
    display like this

    Code:
    '------------------------------------------------------------------------------*'                    IR  Display 1 the parameters                              *
    '------------------------------------------------------------------------------*
    display: ' IR TEMP 
    hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
    Hserin2  timeout,error,[wait(6)]
    hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature/100,".",dec2 temperature//100,"*C",00] 
    Hserin2  timeout,error,[wait(6)]
     
    
    
    gosub checksum2    
    hserout [$01,$0F,$00,temperature.highbyte,temperature.lowbyte,IRCS]   
    Hserin  timeout,error,[wait(6)]
    return
    
    
    '------------------------------------------------------------------------------|
    '                               CHECKSUM IR                                    |
    '------------------------------------------------------------------------------|
    checksum2:
    IRCS = 0
    IRCS = $01 ^ $0F ^ $00 ^ temperature.highbyte ^ temperature.lowbyte 
    return

    then lets have a look at the i2c stuff , its not right either really


    ps if negative temps are possible then additional code req
    Last edited by richard; - 19th December 2021 at 09:07.
    Warning I'm not a teacher

  6. #6
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    really thanks for your time.

    I found this,if i remember correctly somewhere related to this specific sensor.

    Code:
    tempir = (temp.highbyte << 8) + temp.lowbyte
    Then in the equation i have added the following
    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    Your way is much more efficient and works just as expected. Im very happy.

    Now what is wrong with the I2C command?
    Attached Images Attached Images  

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string


    I found this,if i remember correctly somewhere related to this specific sensor.


    Code:
    tempir = (temp.highbyte << 8) + temp.lowbyte
    maybe but in conjunction with
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07

    its not useful in any way

    Now what is wrong with the I2C command?
    all this achieves is exactly nothing
    Code:
    reg    = $07             ' based on the datasheet $07 is the object's temp
    
    
    grave doubts about all of this  it looks like some mishmash of a C code method where no read/write register command exists as it does in pbp 
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    
    i2cwrite sda, scl, addr,reg, [some data of some sort]  ' register is $07 ;would be the normal way if you had any data to write 
    
    
    totally bogus in pbp bit 0 should always be 0
    addr   = %10110101       ' $B5  Binary value: %10110101
    
    
    a form of torture to i2c chips with an incomplete transaction
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    all that's needed
    reg = $07
    addr = %10110100
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07 ;would be the normal pbp way
    Warning I'm not a teacher

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Quote Originally Posted by astanapane View Post
    Richard,

    Then in the equation i have added the following
    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    Well, if that compiler could do floating, maybe it could be used. But in PBP integer math? I do not think so. You need what Richard did as a workaround.

    Ioannis

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts