Hugh Wills


About me

I'm in UK


  • Hugh Wills has started 2 topics. 5 people are following them.
  • Hugh Wills has made 3 replies.

Recent activity

Subscribe to this feed
  • star

    Hugh Wills marked one of Wolftec's replies in Tibbo as useful. Wolftec replied to the question "STOR-ing word values in EEPROM".

  • question
  • question

    Wolftec replied on May 13, 2008 17:02 to the question "STOR-ing word values in EEPROM" in Tibbo:

    Wolftec
    Thinking of it,
    If your going to work with byte or long variables, asc() and chr() are better for this kind of work

    ddval and ddstr are better with values that are in strings. such as tcp/ip adresses.

    Hope this has helped you.
  • question

    Hugh Wills replied on May 13, 2008 16:28 to the question "STOR-ing word values in EEPROM" in Tibbo:

    Hugh Wills
    Hello again Wolftec,

    I have used ddstr and ddval to store the IP adress in EEPROM, also firmware revision (in format #.#.#), but I don't understand if this can be used here? I have word values of 0-1023 but I thought ddstr/ddval would only work with byte variables?

    As you suggest, I have managed to store word_variable in two bytes:

    low_byte=word_variable AND &b11111111
    high_byte=word_variable/256
    string=chr(low_byte)+chr(high_byte)
    stor.setdata(string, address)

    This is the shortest way I can see to do it. There really should be a method to write mutli-byte data to EEPROM without converting to strings!

    To read back from EEPROM:

    low_byte = asc(stor.getdata(address,1))
    high_byte= asc(stor.getdata(address+1,1))
    word_variable=(256*high_byte)+low_byte

    Thanks for your help. I'd be interested in any more information on the use of ddstr and ddval, as these don't appear to be well documented?

    Hugh
  • question

    Wolftec replied on May 13, 2008 15:36 to the question "STOR-ing word values in EEPROM" in Tibbo:

    Wolftec
    Hi,

    Use the chr() function to encode a byte value to a char.

    Then store it on the eeprom

    Afterwards use the asc() function to restore the value back from a char.

    If you are able to use long variables, ex. 2x 16 bytes data you can also use ddval and ddstr to convert 4 bytes to 4 chars at the same time.

    Usefull to convert and store ip adresses.
  • question

    Hugh Wills asked a question in Tibbo on May 13, 2008 12:26:

    Hugh Wills
    STOR-ing word values in EEPROM
    Hi,

    I am using the stor object on the EM1202 to store equipment data (model number, serial number, IP, port, firmware revision etc) in EEPROM. This is fine as I can store and recall all the data as strings.

    However, I now want to store a whole set of values from a 10-bit A-to-D converter into EEPROM. I have the values in 16-bit word variables and want to store them to EEPROM as 2-bytes each, but stor.setdata and stor.getdata accept strings only. If I convert to strings using the hex function, I end up using minimum 4-bytes, or double the space!

    Can anyone suggest how I can easily write/read these values in only 2-bytes each?

    Thanks.
  • question

    Wolftec replied on May 13, 2008 10:16 to the question "Bitwise Operations" in Tibbo:

    Wolftec
    I'm experiencing some of the limitations myself as i'm coding a base64 encode/decode routine.

    But the workaround is to basicly convert the binary data to string and work on it, or to make logic operations.

    Some examples,

    Setting the 20th bit of the y 32bit long variable

    y=y OR &h080000

    clearing the 20th bit,

    y=y AND &hF7FFFF

    Inverting the 20th bit,
    y=y XOR &h080000

    Some sort of shift left,
    x=Lbin(y) 'convert y to string
    x=right(x,len(x)-2) 'remove the annoying &b from the string

    z=left(x,1) 'get the first caracter 0 or 1
    x=right(x,len(x)-1) 'Shift left

    Use a similar for the shift right.

    It's not as quick or straight forward as i used to work in MicroChip Pic, but it does the job if you don't have time sensitive aplications.

    For those i use a combination of the EM1202 with a pic controler, for example with one-wire ibutton protocols.
  • question

    Hugh Wills replied on May 13, 2008 09:25 to the question "Bitwise Operations" in Tibbo:

    Hugh Wills
    Hi T-bone,
    Here are some extracts from Atom Basic syntax that I find invaluable:

    VARIABLE MODIFIERS (syntax variable.modifier):
    lowbit, highbit, bitn, lownib, highnib, nibn, lowbyte, highbyte, byten,
    lowword, highword, wordn

    So for example, to set the 20th bit of 32-bit variable "stateregister" high:
    stateregister.bit20=%1
    or to convert the 32-bit variable to a 4-digit hex representation:
    errorcode(0)=HEX stateregister.nib3
    errorcode(0)=HEX stateregister.nib2
    errorcode(0)=HEX stateregister.nib1
    errorcode(0)=HEX stateregister.nib0

    Comparison operators (<, >, =, <=, >=, <>) can be used at any of the above levels (bit, nibble, byte, word, long).

    BITWISE OPERATORS:
    & AND expr1 & expr2
    | OR expr1 | expr2
    ^ XOR expr1 ^ expr2
    >> Shift Right expr1>>expr2
    << Shift Left expr1 << expr2
    ~ Invert Bits ~ expr1
    ! Invert Bits ! expr1

    BIT LEVEL FUNCTIONS:
    SHIFTIN read data one bit at a time to synchronous serial device.
    SHIFTOUT write data one bit at a time to a synchronous serial device
    So for example to send a 32-bit variable "stateregister" to a synchronous serial device starting with MSB first:
    SHIFTOUT DEVICE_DATA,DEVICE_SCLK,MSBPOST,[stateregister\32]

    RELATED FUNCTIONS:
    BIN2BCD, BCDTOBIN convert between binary and packed BCD
    DIG isolate a single digit of a decimal number

    There just seems to be no simple way to work with data at the bit, nibble, word, long levels (intermixed) which for low-level engineering applications on the back-end of the excellent high-level comm's capabilities I find very limiting. I am actually using a EM1202 and Atom Pro 28M together on one board at the moment with serial link between them! I would eventually like to use just the EM1202.

    Any thoughts? Thanks for listening :)
  • question

    T-bone replied on May 13, 2008 01:24 to the question "Bitwise Operations" in Tibbo:

    T-bone
    Hey Hugh,

    Was wondering what bit-wise operators you feel is missing that you found useful? We do have the AND, OR, XOR, and NOT operators.
  • question

    Hugh Wills asked a question in Tibbo on May 12, 2008 13:45:

    Hugh Wills
    Bitwise Operations
    Hi,

    I have been using BasicMicro Stamp and Atom controller(s) for many years and have just switched to the EM1202 for the first time in a project. I have found it a great product, but there appears to be a huge omission in terms of programming - individual bit manipulation within byte/word/long variables. Unless I am missing something, there appears to be no easy way of doing this?

    In a previous Atom application I used a 32-bit variable as a "register" to record 32 pass/fail criteria. There is facility in Atom Basic to simply turn individual bits in the variable on or off or use them in operations. You can also separate out any byte of a 16 or 32-bit variable and carry out many other bitwise operations. I can find no way to do these simply in Tibbo Basic.

    I have a work-around by converting the variable to a 32-character binary string representation, manipulating the characters in the string, then converting back to a 32-bit variable. This is VERY slow at processing.

    Am I missing something? If not, PLEASE can we have full bitwise operations in the next release? The Atom was superb at this, so please consult their manual for ideas! There is a whole range of operations I simply can't find a way of doing on the EM1202.

    Hugh