16bit variable and degrees conversion


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Thanks

    Thank you All ,

    I will have a look and give it a try this weekend, but both Ingvar and Luciano
    pointed me in the direction

    I only need to check the SERIN2 command to see how to handle the incomming string in my previous msg

    Precision is 2 decimals

    The project is to read out 2 position absolute encoders
    which are polled by a controller over a RS485 line at 9600bd

    Thanks again to everyone who helped me

    Walter

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Ok, since you only need 2 decimals and my code gives 3 you can use the extra precision to round the result .......

    IntPartOfPos1 = 16bitPosition1 ** 360
    FracPartOfPos1 = 16bitPosition1 * 360
    FracPartOfPos1 = FracPartOfPos1 ** 1000
    FracPartOfPos1 = (FracPartOfPos1 + 5) / 10
    LCDOUT DEC3 IntPartOfPos1, ".", DEC2 FracPartOfPos1

    ..... should give you a correctly rounded result with 2 decimals.

    /Ingvar

  3. #3


    Did you find this post helpful? Yes | No

    Default Serin2 help

    Hmm looks that I'm doing something wrong


    I receive serial at 9600 bd N8,1 the following in hex

    example:
    21 AD 34 01 22 EF 23 02

    loop:
    AZ var word
    EL var Word

    Serin2 portb.2,84,[wait ("!"),AZ] => "!" is the ascii represenataion of 21 hex
    would like to store AD 34 in variable AZ, 01 dont care
    then the same for EF 23 in EL

    Use an SP485 RS485 driver in front

  4. #4
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Your example data:
    21 AD 34 01 22 EF 23 02

    ===============================================
    ' The code (Not tested)

    my_array VAR BYTE[7] ' Define array variable with 7 locations

    SERIN2 IN_PIN, BAUD,[WAIT("!") STR my_array\7]

    ' Waits for the string "!", then collects the next 7 characters.
    ' (21 HEX = ASCII !)


    ===============================================

    This could be valid data:
    21 21 21 01 22 21 21 02

    Make sure you verify that "01" "22" "02" are in the
    right position in the array.

    * * * * * *

    From PicBasic manual:

    An optional Timeout and Label may be included to allow the program
    to continue if a character is not received within a certain amount of time.
    Timeout is specified in 1 millisecond units. If the serial input pin stays in
    the idle state during the Timeout time, the program will exit the SERIN2
    command and jump to Label.

    * * * * * *

    PicBasic Pro Code that demonstrates the use of modifiers
    with the Serin2 and Serout2 commands.

    http://www.microengineeringlabs.com/...bp/ser2mod.bas


    Luciano
    Last edited by Luciano; - 22nd April 2005 at 11:54.

  5. #5


    Did you find this post helpful? Yes | No

    Default Thanks

    Everything is working

    I would like to thank those who post some replys

    If someone is in the Belgian Area, I will certainly offer a Beer

    Walter

Similar Threads

  1. Conversion problem
    By eva in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th March 2007, 18:21

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