Results 1 to 5 of 5

Thread: Arbotix - Update Hardware Serial to capabilities of Arduino 1.0.5 capabilities.

  1. #1

    Arbotix - Update Hardware Serial to capabilities of Arduino 1.0.5 capabilities.

    Not sure if this is the best place to ask for this or if I should try to enter a request on github?

    Thinking about the idea of running AX servos on Atmega based processors made me think again about how the hardware serial ports were being processed and wondering if the Arbotix code base had been updated to the later stuff. I am pretty sure it has not.

    Some of the simple differences include: Serial.flush() on 1.0.5 (started I believe on 1.0.3) actually waits until the transmission is complete, not just while the head and tail pointers are not equal to each other.

    They changed the ring_buffer definition which created smaller faster code for processing. In particular they changed the head and tail pointers from int to unsigned int. I actually have hacked my copy to use uint8_t and cut the code size down more.

    In case you are interested: Here is an interrupt vector from Arbotix code: 146 bytes plus call to __divmodhi4
    Code:
    000017fa <__vector_21>:
        17fa:    1f 92           push    r1
        17fc:    0f 92           push    r0
        17fe:    0f b6           in    r0, 0x3f    ; 63
        1800:    0f 92           push    r0
        1802:    11 24           eor    r1, r1
        1804:    2f 93           push    r18
        1806:    3f 93           push    r19
        1808:    4f 93           push    r20
        180a:    5f 93           push    r21
        180c:    6f 93           push    r22
        180e:    7f 93           push    r23
        1810:    8f 93           push    r24
        1812:    9f 93           push    r25
        1814:    af 93           push    r26
        1816:    bf 93           push    r27
        1818:    ef 93           push    r30
        181a:    ff 93           push    r31
        181c:    20 91 a7 04     lds    r18, 0x04A7
        1820:    30 91 a8 04     lds    r19, 0x04A8
        1824:    80 91 a9 04     lds    r24, 0x04A9
        1828:    90 91 aa 04     lds    r25, 0x04AA
        182c:    28 17           cp    r18, r24
        182e:    39 07           cpc    r19, r25
        1830:    31 f4           brne    .+12         ; 0x183e <__vector_21+0x44>
        1832:    80 91 c1 00     lds    r24, 0x00C1
        1836:    8f 7d           andi    r24, 0xDF    ; 223
        1838:    80 93 c1 00     sts    0x00C1, r24
        183c:    16 c0           rjmp    .+44         ; 0x186a <__vector_21+0x70>
        183e:    e0 91 a9 04     lds    r30, 0x04A9
        1842:    f0 91 aa 04     lds    r31, 0x04AA
        1846:    e9 59           subi    r30, 0x99    ; 153
        1848:    fb 4f           sbci    r31, 0xFB    ; 251
        184a:    40 81           ld    r20, Z
        184c:    80 91 a9 04     lds    r24, 0x04A9
        1850:    90 91 aa 04     lds    r25, 0x04AA
        1854:    01 96           adiw    r24, 0x01    ; 1
        1856:    60 e4           ldi    r22, 0x40    ; 64
        1858:    70 e0           ldi    r23, 0x00    ; 0
        185a:    0e 94 9f 0f     call    0x1f3e    ; 0x1f3e <__divmodhi4>
        185e:    90 93 aa 04     sts    0x04AA, r25
        1862:    80 93 a9 04     sts    0x04A9, r24
        1866:    40 93 c6 00     sts    0x00C6, r20
        186a:    ff 91           pop    r31
        186c:    ef 91           pop    r30
        186e:    bf 91           pop    r27
        1870:    af 91           pop    r26
        1872:    9f 91           pop    r25
        1874:    8f 91           pop    r24
        1876:    7f 91           pop    r23
        1878:    6f 91           pop    r22
        187a:    5f 91           pop    r21
        187c:    4f 91           pop    r20
        187e:    3f 91           pop    r19
        1880:    2f 91           pop    r18
        1882:    0f 90           pop    r0
        1884:    0f be           out    0x3f, r0    ; 63
        1886:    0f 90           pop    r0
        1888:    1f 90           pop    r1
        188a:    18 95           reti
    Code base for compiling for Arduino Mega(1280) on 1.0.5 (126 bytes)
    Code:
    000048e8 <__vector_26>:
        48e8:    1f 92           push    r1
        48ea:    0f 92           push    r0
        48ec:    0f b6           in    r0, 0x3f    ; 63
        48ee:    0f 92           push    r0
        48f0:    0b b6           in    r0, 0x3b    ; 59
        48f2:    0f 92           push    r0
        48f4:    11 24           eor    r1, r1
        48f6:    2f 93           push    r18
        48f8:    3f 93           push    r19
        48fa:    8f 93           push    r24
        48fc:    9f 93           push    r25
        48fe:    ef 93           push    r30
        4900:    ff 93           push    r31
        4902:    20 91 07 07     lds    r18, 0x0707
        4906:    30 91 08 07     lds    r19, 0x0708
        490a:    80 91 09 07     lds    r24, 0x0709
        490e:    90 91 0a 07     lds    r25, 0x070A
        4912:    28 17           cp    r18, r24
        4914:    39 07           cpc    r19, r25
        4916:    31 f4           brne    .+12         ; 0x4924 <__vector_26+0x3c>
        4918:    80 91 c1 00     lds    r24, 0x00C1
        491c:    8f 7d           andi    r24, 0xDF    ; 223
        491e:    80 93 c1 00     sts    0x00C1, r24
        4922:    14 c0           rjmp    .+40         ; 0x494c <__vector_26+0x64>
        4924:    e0 91 09 07     lds    r30, 0x0709
        4928:    f0 91 0a 07     lds    r31, 0x070A
        492c:    e9 53           subi    r30, 0x39    ; 57
        492e:    f9 4f           sbci    r31, 0xF9    ; 249
        4930:    20 81           ld    r18, Z
        4932:    80 91 09 07     lds    r24, 0x0709
        4936:    90 91 0a 07     lds    r25, 0x070A
        493a:    01 96           adiw    r24, 0x01    ; 1
        493c:    8f 73           andi    r24, 0x3F    ; 63
        493e:    90 70           andi    r25, 0x00    ; 0
        4940:    90 93 0a 07     sts    0x070A, r25
        4944:    80 93 09 07     sts    0x0709, r24
        4948:    20 93 c6 00     sts    0x00C6, r18
        494c:    ff 91           pop    r31
        494e:    ef 91           pop    r30
        4950:    9f 91           pop    r25
        4952:    8f 91           pop    r24
        4954:    3f 91           pop    r19
        4956:    2f 91           pop    r18
        4958:    0f 90           pop    r0
        495a:    0b be           out    0x3b, r0    ; 59
        495c:    0f 90           pop    r0
        495e:    0f be           out    0x3f, r0    ; 63
        4960:    0f 90           pop    r0
        4962:    1f 90           pop    r1
        4964:    18 95           reti
    And if you switch to an 8 bit value it cuts it down some more: (104 bytes)
    Code:
    048d0 <__vector_26>:
        48d0:    1f 92           push    r1
        48d2:    0f 92           push    r0
        48d4:    0f b6           in    r0, 0x3f    ; 63
        48d6:    0f 92           push    r0
        48d8:    0b b6           in    r0, 0x3b    ; 59
        48da:    0f 92           push    r0
        48dc:    11 24           eor    r1, r1
        48de:    2f 93           push    r18
        48e0:    8f 93           push    r24
        48e2:    9f 93           push    r25
        48e4:    ef 93           push    r30
        48e6:    ff 93           push    r31
        48e8:    90 91 05 07     lds    r25, 0x0705
        48ec:    80 91 06 07     lds    r24, 0x0706
        48f0:    98 17           cp    r25, r24
        48f2:    31 f4           brne    .+12         ; 0x4900 <__vector_26+0x30>
        48f4:    80 91 c1 00     lds    r24, 0x00C1
        48f8:    8f 7d           andi    r24, 0xDF    ; 223
        48fa:    80 93 c1 00     sts    0x00C1, r24
        48fe:    10 c0           rjmp    .+32         ; 0x4920 <__vector_26+0x50>
        4900:    e0 91 06 07     lds    r30, 0x0706
        4904:    f0 e0           ldi    r31, 0x00    ; 0
        4906:    eb 53           subi    r30, 0x3B    ; 59
        4908:    f9 4f           sbci    r31, 0xF9    ; 249
        490a:    20 81           ld    r18, Z
        490c:    80 91 06 07     lds    r24, 0x0706
        4910:    90 e0           ldi    r25, 0x00    ; 0
        4912:    01 96           adiw    r24, 0x01    ; 1
        4914:    8f 73           andi    r24, 0x3F    ; 63
        4916:    90 70           andi    r25, 0x00    ; 0
        4918:    80 93 06 07     sts    0x0706, r24
        491c:    20 93 c6 00     sts    0x00C6, r18
        4920:    ff 91           pop    r31
        4922:    ef 91           pop    r30
        4924:    9f 91           pop    r25
        4926:    8f 91           pop    r24
        4928:    2f 91           pop    r18
        492a:    0f 90           pop    r0
        492c:    0b be           out    0x3b, r0    ; 59
        492e:    0f 90           pop    r0
        4930:    0f be           out    0x3f, r0    ; 63
        4932:    0f 90           pop    r0
        4934:    1f 90           pop    r1
        4936:    18 95           reti
    Note: I did not count clock cycles here, but there is a reasonable difference. Also these code size differences also show up in other functions as well. What I have not done here yet, is to compare this code size/instruction count as compared to the specialized code used for Serial1 on the arbotix.

    Again sorry if this is not the right place to request this.

    Thanks again
    Kurt

  2. #2
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    125

    Re: Arbotix - Update Hardware Serial to capabilities of Arduino 1.0.5 capabilities.

    Kurt,

    A ticket or pull request on github is the best way to get changes into the code base. Back in the early days of Arduino when we first rolled out the ArbotiX, we needed to create our own handler, because their default handler was over 700 instructions, I know they have been updating things quite a bit over the past year or so to improve things.

    -Fergs

  3. #3

    Re: Arbotix - Update Hardware Serial to capabilities of Arduino 1.0.5 capabilities.

    Thanks, will do.

    Will play with it some more. May also experiment with using the change of 2 to 1 byte head/tail pointers with the main hardware code base.

    With that, it would also be interesting to trying some hacks to see how well an Arduino Mega would work with standard serial driver on one of the comm ports. Would need to write some simple functions like setrx and settx. Which may work or not... Something like:
    Code:
    // need to setup for different Serial ports
    void setRX(void) {
        Serial1.flush();
    
        // Maybe clear input buffer... 
        while (Serial1.read() != -1) ;
    
        // enable RX and RX interrupt, disable TX and all TX interrupt
        UCSR1B = ((1 << RXCIE1) | (1 << RXEN1));
    }
    
    void setTX(void) {
        // enable TX, disable RX and all RX interrupt
        UCSR1B = (1 << TXEN1);
    }
    Kurt

  4. #4

    Re: Arbotix - Update Hardware Serial to capabilities of Arduino 1.0.5 capabilities.

    Note: I have created an issue about updating the core to the 1.0.5 compatibility(https://github.com/vanadiumlabs/arbotix/issues/7). I run into a new issue today, with the differences.

    That is if you use the Serial.readBytes() on 1.0.5, you can read in however many bytes you are interested in. It will timeout according to the value you pass in to the call: Serial.setTimeout().

    The issue is the arbotix version is doing:
    Code:
    nt Stream::readBytes( char *buffer, size_t length)
    {
       return readBytesUntil( 0, buffer, length);
    }
    The problem is suppose your input buffer (packet) has internal Null characters, The ReadBytesUntil, will bail on the first null character.

    The current 1.0.5 version does:
    Code:
    size_t Stream::readBytes(char *buffer, size_t length)
    {
      size_t count = 0;
      while (count < length) {
        int c = timedRead();
        if (c < 0) break;
        *buffer++ = (char)c;
        count++;
      }
      return count;
    }
    Which does not have this problem. Another way to do this would be to change the type of the terminator passed in to readBytesTo from char to int and then pass -1 (or the like).

    Kurt

  5. #5

    Re: Arbotix - Update Hardware Serial to capabilities of Arduino 1.0.5 capabilities.

    Looks like the sub-forum names have changed and this thread would be better in the Arbotix forum...

    Not sure if anyone else cares: But I am experimenting some with updating the hardware/core to be up to date. Got tired of things like: INPUT_PULLUP not being defined (was there at least by Arduino 1.0.1), likewise the other issues I mentioned.

    So I replaced the contents of the Arbotix\hardware\cores\Arbotix with the current 1.0.5 stuff and then did the commenting out of the creation of the Serial1 object. May make a 2nd pass and instead of simply commenting it out, maybe define some #define in the variant such that I can do like I earlier did and have a variant that allows me have the Serial1 object created...

    Anyway I updated my Fork of the Arbotix code base with this. So far it looks like my Phantom Phoenix is working, likewise the pypose version Hexapod_Mark_II appears to work. If others wish to try it out, it is up at: https://github.com/KurtE/arbotix
    If desired, could try to issue Pull request to get it into main branch.

    Kurt

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Add Pose Capabilities to USB2AX?
    By KurtEck in forum Arbotix, Microcontrollers, Arduino
    Replies: 41
    Last Post: 12-13-2013, 06:11 PM
  2. Arduino Mega 2560 and Serial Comunication issues
    By DVS in forum Arbotix, Microcontrollers, Arduino
    Replies: 3
    Last Post: 07-10-2013, 02:31 PM
  3. Question(s) Arbotix and Arduino Software Serial Library
    By Jules in forum Arbotix, Microcontrollers, Arduino
    Replies: 4
    Last Post: 06-21-2012, 10:19 AM
  4. Question(s) Arduino IDE Serial Monitor output on Linux
    By Stephen in forum Software and Programming
    Replies: 5
    Last Post: 10-02-2010, 04:55 PM
  5. Question(s) Arduino serial problems
    By ROBOTMAN in forum Arbotix, Microcontrollers, Arduino
    Replies: 10
    Last Post: 05-09-2009, 10:59 PM

Posting Permissions

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