Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

AX-12 control with PIC32

Bioloid robot kit from Korean company Robotis; CM5 controller block, AX12 servos..
54 postsPage 1 of 41, 2, 3, 4
54 postsPage 1 of 41, 2, 3, 4

AX-12 control with PIC32

Post by ColdStart » Thu Jan 20, 2011 9:39 am

Post by ColdStart
Thu Jan 20, 2011 9:39 am

Hello, i have a PIC32 microcontroller, and i have connected its RX and TX lines to AX-12 through the 74HC126 and 74HC004 appropriately...

my microcontroller configured to 9600bps, the first command i sent to ax12 is to change its baud rate to 9600... the next... to turn on LED... but it does not respond to any of those commands?

actually its just does not respond to anything...

the only thing is it blinks once when powered... thats it...after that nothing...

now, what you think of such a way of interconnecting it? and what you think i might missing?

thanks
Hello, i have a PIC32 microcontroller, and i have connected its RX and TX lines to AX-12 through the 74HC126 and 74HC004 appropriately...

my microcontroller configured to 9600bps, the first command i sent to ax12 is to change its baud rate to 9600... the next... to turn on LED... but it does not respond to any of those commands?

actually its just does not respond to anything...

the only thing is it blinks once when powered... thats it...after that nothing...

now, what you think of such a way of interconnecting it? and what you think i might missing?

thanks
ColdStart
Robot Builder
Robot Builder
Posts: 17
Joined: Thu Jan 20, 2011 9:28 am

Post by Fritzoid » Thu Jan 20, 2011 2:36 pm

Post by Fritzoid
Thu Jan 20, 2011 2:36 pm

Hi ColdStart,

The dynamixel keeps its current baud rate in its EEPROM storage. When you power on the device, the firmware configures the UART using the baud rate found in the EEPROM. Your dynamixel is probably using the default baud rate of 1M bps and will only respond to commands sent at this speed.

So you need to issue your write_data command at 1M bps.

Once you update the EEPROM by writing a new baud rate in the control table the dynamixel will start using the new speed immediately. It will continue to use this new speed from then on whenever you power on your servo. So this is a one-time operation.

Robotis has provided a number of tools to help you change the baud rate on a dynamixel. You can use the Dynamixel Wizard if you have a USB2Dynamixel and a special cable. You can use Roboplus Manage if you have a CM-5 or CM-510 controller.

Or you can try to configure you PIC UART to use 1M bps.
Hi ColdStart,

The dynamixel keeps its current baud rate in its EEPROM storage. When you power on the device, the firmware configures the UART using the baud rate found in the EEPROM. Your dynamixel is probably using the default baud rate of 1M bps and will only respond to commands sent at this speed.

So you need to issue your write_data command at 1M bps.

Once you update the EEPROM by writing a new baud rate in the control table the dynamixel will start using the new speed immediately. It will continue to use this new speed from then on whenever you power on your servo. So this is a one-time operation.

Robotis has provided a number of tools to help you change the baud rate on a dynamixel. You can use the Dynamixel Wizard if you have a USB2Dynamixel and a special cable. You can use Roboplus Manage if you have a CM-5 or CM-510 controller.

Or you can try to configure you PIC UART to use 1M bps.
Fritzoid
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 331
Joined: Mon Dec 18, 2006 1:00 am

Post by ColdStart » Thu Jan 20, 2011 6:39 pm

Post by ColdStart
Thu Jan 20, 2011 6:39 pm

thank you for reply,ill give it a try and come back. but what you think of my interconnection of TX/RX lines directly from PIC to the ax12 through 74HS126/004 series... that sounds OK?
thank you for reply,ill give it a try and come back. but what you think of my interconnection of TX/RX lines directly from PIC to the ax12 through 74HS126/004 series... that sounds OK?
ColdStart
Robot Builder
Robot Builder
Posts: 17
Joined: Thu Jan 20, 2011 9:28 am

Post by i-Bot » Thu Jan 20, 2011 8:04 pm

Post by i-Bot
Thu Jan 20, 2011 8:04 pm

Interconnection of the RX and TX via the HC126 is fine. It just depends on how well you control the direction enable. Make sure to the enable is switched quickly on TX complete of the last transmit byte (checksum)
Interconnection of the RX and TX via the HC126 is fine. It just depends on how well you control the direction enable. Make sure to the enable is switched quickly on TX complete of the last transmit byte (checksum)
i-Bot
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1142
Joined: Wed May 17, 2006 1:00 am

Post by Fraser » Sat Jan 22, 2011 12:43 am

Post by Fraser
Sat Jan 22, 2011 12:43 am

74HC126 buffers should work well, because it is tristate: If you float the switch line instead of pulling it low then you can do away with the 74HC004.

Also make sure that you wait until you see the shift register empty flag on the UART output buffer before you switch to RX. There are usually two flags, one for TX buffer empty and one for TX shift register out empty. I had a bit of a head scratcher over this because I had previously just been writing for full duplex 2 wire comms in which case the final shift register can be ignored.
74HC126 buffers should work well, because it is tristate: If you float the switch line instead of pulling it low then you can do away with the 74HC004.

Also make sure that you wait until you see the shift register empty flag on the UART output buffer before you switch to RX. There are usually two flags, one for TX buffer empty and one for TX shift register out empty. I had a bit of a head scratcher over this because I had previously just been writing for full duplex 2 wire comms in which case the final shift register can be ignored.
Fraser
Savvy Roboteer
Savvy Roboteer
Posts: 84
Joined: Tue Nov 30, 2010 2:16 pm

Post by ColdStart » Sat Jan 22, 2011 1:31 am

Post by ColdStart
Sat Jan 22, 2011 1:31 am

well its really not working at all.. I wonder there were no code for this servo for this popular family of microcontrollers, if i''l be able to make it through im going to post complete schematics and project files...

so, what i did is i set up my PIC32 UART1 to 1000000. UART2 channel intended to talk to PC and PIC is set to 9600... its just for debug.

now, here is how my code looks like:

Code: Select all
   while(1)
   {


   if (Button1Pressed)
   {
      LED2On(); //show that button is pressed

      // now talk to servo
      DIR1(); // direction pin to high

      WriteUART1(0xff);
      WriteUART1(0xff);
      WriteUART1(0x01);
      WriteUART1(0x04);
      WriteUART1(0x03);
      WriteUART1(0x19);
      WriteUART1(0x01);
      WriteUART1(0xdd);

      while(BusyUART1());
      DIR0(); // direction pin to low

      putsUART2("Command 2 is sent.\r\n");

                while (Button1Pressed) ; // wait until button is depressed


   } else
      LED2Off();

}



and nothing happens... however, when i power my servo, it blinks Once. And in this command, you can see that i am talking to it as its ID is 1... supposed to be factory setting...

ill go ahead debug more, and see what i get from it.. but i just get crap..

ok, here is an update of experiment, i have hooked channel2 of scope to the direction pin connecting from PIC32. And channel1 to the Data pin of AX12...

you can see that 50us duration of high pulse.. means that in my code period from DIR1(); to DIR0()...

and during this period you see what happens on Data pin on channel1... seems like it is what it should be?

two long pulses on chan1 maybe associated somehow with 0xff 0xff...

but the LED does not turn on... ill go ahead do more than that, but it would be nice to hear what you think up until now?

here is picture:


thank you.http://picpaste.com/pics/Image0047-B6rN0w2w.1295662264.jpg
well its really not working at all.. I wonder there were no code for this servo for this popular family of microcontrollers, if i''l be able to make it through im going to post complete schematics and project files...

so, what i did is i set up my PIC32 UART1 to 1000000. UART2 channel intended to talk to PC and PIC is set to 9600... its just for debug.

now, here is how my code looks like:

Code: Select all
   while(1)
   {


   if (Button1Pressed)
   {
      LED2On(); //show that button is pressed

      // now talk to servo
      DIR1(); // direction pin to high

      WriteUART1(0xff);
      WriteUART1(0xff);
      WriteUART1(0x01);
      WriteUART1(0x04);
      WriteUART1(0x03);
      WriteUART1(0x19);
      WriteUART1(0x01);
      WriteUART1(0xdd);

      while(BusyUART1());
      DIR0(); // direction pin to low

      putsUART2("Command 2 is sent.\r\n");

                while (Button1Pressed) ; // wait until button is depressed


   } else
      LED2Off();

}



and nothing happens... however, when i power my servo, it blinks Once. And in this command, you can see that i am talking to it as its ID is 1... supposed to be factory setting...

ill go ahead debug more, and see what i get from it.. but i just get crap..

ok, here is an update of experiment, i have hooked channel2 of scope to the direction pin connecting from PIC32. And channel1 to the Data pin of AX12...

you can see that 50us duration of high pulse.. means that in my code period from DIR1(); to DIR0()...

and during this period you see what happens on Data pin on channel1... seems like it is what it should be?

two long pulses on chan1 maybe associated somehow with 0xff 0xff...

but the LED does not turn on... ill go ahead do more than that, but it would be nice to hear what you think up until now?

here is picture:


thank you.http://picpaste.com/pics/Image0047-B6rN0w2w.1295662264.jpg
ColdStart
Robot Builder
Robot Builder
Posts: 17
Joined: Thu Jan 20, 2011 9:28 am

Post by i-Bot » Sat Jan 22, 2011 12:29 pm

Post by i-Bot
Sat Jan 22, 2011 12:29 pm

The clue is in the length of 50us. Each character should take 10us, so 8 characters should take 80us.

I don't have the latest PIC32 libraries, but I think the problem is there. The WriteUART1 writes direct to the transmit FIFO which I guess is 4 levels deep and then to the TX shift register, giving 5 levels available for buffering (50us). The WriteUART1 does not appear to check if the buffer is full, so the last byte is likely overwritten 3 times.

If you put a while(BusyUART1()); between each write it should work, or use putcUART1 instead of WriteUART1. In more complex code this wait would be better done with a check on the UTXBF bit rather than the TRMT, so the FIFO is used. You must still keep the while(BusyUART1()); before the change of direction at the end though.

Check out the datasheet and the library source for more help
The clue is in the length of 50us. Each character should take 10us, so 8 characters should take 80us.

I don't have the latest PIC32 libraries, but I think the problem is there. The WriteUART1 writes direct to the transmit FIFO which I guess is 4 levels deep and then to the TX shift register, giving 5 levels available for buffering (50us). The WriteUART1 does not appear to check if the buffer is full, so the last byte is likely overwritten 3 times.

If you put a while(BusyUART1()); between each write it should work, or use putcUART1 instead of WriteUART1. In more complex code this wait would be better done with a check on the UTXBF bit rather than the TRMT, so the FIFO is used. You must still keep the while(BusyUART1()); before the change of direction at the end though.

Check out the datasheet and the library source for more help
i-Bot
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1142
Joined: Wed May 17, 2006 1:00 am

Post by ColdStart » Mon Jan 24, 2011 8:08 am

Post by ColdStart
Mon Jan 24, 2011 8:08 am

i-Bot, i really appreciate your advice, i changed to putcUART1(...) and it worked just fine. i will have to take time study better that kind of UART. thank you.

so yea then that piece of code, together with datasheet schematics to tx/rx lines to PIC32 works.
i-Bot, i really appreciate your advice, i changed to putcUART1(...) and it worked just fine. i will have to take time study better that kind of UART. thank you.

so yea then that piece of code, together with datasheet schematics to tx/rx lines to PIC32 works.
ColdStart
Robot Builder
Robot Builder
Posts: 17
Joined: Thu Jan 20, 2011 9:28 am

Post by billyzelsnack » Mon Jan 24, 2011 4:02 pm

Post by billyzelsnack
Mon Jan 24, 2011 4:02 pm

Fraser wrote:74HC126 buffers should work well, because it is tristate: If you float the switch line instead of pulling it low then you can do away with the 74HC004.


Can you elaborate on how this would work? It would be nice to get rid of the inverter chip. (I still like having the tri-state though)
Fraser wrote:74HC126 buffers should work well, because it is tristate: If you float the switch line instead of pulling it low then you can do away with the 74HC004.


Can you elaborate on how this would work? It would be nice to get rid of the inverter chip. (I still like having the tri-state though)
billyzelsnack
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 618
Joined: Sat Dec 30, 2006 1:00 am

Post by ColdStart » Mon Jan 24, 2011 4:47 pm

Post by ColdStart
Mon Jan 24, 2011 4:47 pm

i guess just use 0 instead of 1 when you want to transmit... i kind of didnt think about it and used inverter just initially...
i guess just use 0 instead of 1 when you want to transmit... i kind of didnt think about it and used inverter just initially...
ColdStart
Robot Builder
Robot Builder
Posts: 17
Joined: Thu Jan 20, 2011 9:28 am

Post by i-Bot » Mon Jan 24, 2011 5:20 pm

Post by i-Bot
Mon Jan 24, 2011 5:20 pm

If you ground the input to a spare 126 gate and have a pullup on the gate output, then when the OE is high, the output is low, and when OE is low the output is high.
If you ground the input to a spare 126 gate and have a pullup on the gate output, then when the OE is high, the output is low, and when OE is low the output is high.
i-Bot
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1142
Joined: Wed May 17, 2006 1:00 am

Post by Fraser » Mon Jan 24, 2011 6:24 pm

Post by Fraser
Mon Jan 24, 2011 6:24 pm

billyzelsnack wrote:
Fraser wrote:74HC126 buffers should work well, because it is tristate: If you float the switch line instead of pulling it low then you can do away with the 74HC004.


Can you elaborate on how this would work? It would be nice to get rid of the inverter chip. (I still like having the tri-state though)


My post was a bit garbled, Just looked at 74126 datasheet, when 74126 gate is set low then the output floats.

I thought the NAND was being used for something else than just inverting the logic. But yes, easy to do away with inverter in code or use spare buffers in the quad package like i-Bot said.

With Atmel you could also do away with 74126 (which also frees up the IO pins used for enables), tie TX and RX together:

TX mode:
Disable RX interrupt.
Set TX pin as output.

RX mode:
Clear RX buffer (read it)
Enable RX interrupt.
Set TX pin as input (makes it Hi Z)

Not sure with PIC though, maybe the same can be done?

edit:
Glad you've got it working coldstart.
billyzelsnack wrote:
Fraser wrote:74HC126 buffers should work well, because it is tristate: If you float the switch line instead of pulling it low then you can do away with the 74HC004.


Can you elaborate on how this would work? It would be nice to get rid of the inverter chip. (I still like having the tri-state though)


My post was a bit garbled, Just looked at 74126 datasheet, when 74126 gate is set low then the output floats.

I thought the NAND was being used for something else than just inverting the logic. But yes, easy to do away with inverter in code or use spare buffers in the quad package like i-Bot said.

With Atmel you could also do away with 74126 (which also frees up the IO pins used for enables), tie TX and RX together:

TX mode:
Disable RX interrupt.
Set TX pin as output.

RX mode:
Clear RX buffer (read it)
Enable RX interrupt.
Set TX pin as input (makes it Hi Z)

Not sure with PIC though, maybe the same can be done?

edit:
Glad you've got it working coldstart.
Fraser
Savvy Roboteer
Savvy Roboteer
Posts: 84
Joined: Tue Nov 30, 2010 2:16 pm

Post by billyzelsnack » Mon Jan 24, 2011 10:36 pm

Post by billyzelsnack
Mon Jan 24, 2011 10:36 pm

I've had some trouble tying the pins together so I prefer to use the extra circuitry.
I've had some trouble tying the pins together so I prefer to use the extra circuitry.
billyzelsnack
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 618
Joined: Sat Dec 30, 2006 1:00 am

reading problems

Post by ColdStart » Tue May 10, 2011 3:33 am

Post by ColdStart
Tue May 10, 2011 3:33 am

In order not to start new topic i just decided to post back here. So i can now easily send any type of command to AX12 from PIC32, through the HC126/04. But problem is i do not receive anything. Here is a code:

Code: Select all
while(1)
{

   if (Button1Pressed)
   {
      LED1On();

      // obtain status
      DIR1();
        putcUART1(0xff);
        putcUART1(0xff);
        putcUART1(0x01);
        putcUART1(0x02);
        putcUART1(0x01);
        putcUART1(0xfb);

      while(BusyUART1());
      DIR0();

int di = 0; // data index

// This code is responsible for reading UART1 byte by byte
// and saving each byte in an array data[10].
 while (DataRdyUART1())
 {
 data[di] = getcUART1();
 di+=1;
 }


      putsUART2("Command 1 is sent.\r\n");

      
      while (Button1Pressed) ; // wait until depressed


   } else
      LED1Off();

   if (Button2Pressed)
   {
      LED2On();

      // now talk to servo
      DIR1();

      // reset servo
      putcUART1(0xff);
      putcUART1(0xff);
      putcUART1(0x01);
      putcUART1(0x02);
      putcUART1(0x06);
      putcUART1(0xf6);

      while(BusyUART1());
      DIR0();



      // writing the results on SD card
      int i=0;
      for(i=0; i<9; i++)
      {
         FSfwrite (&data[i], 1, 1, pointer);
      }

            FSfclose(pointer);




      putsUART2("Command 2 is sent.\r\n");

      
      while (Button2Pressed) ; // wait until depressed


   } else
      LED2Off();


}



Now, when i transfer to PC and open my binary file, i just see nine bytes with just some garbage values. However, i was supposed to see the following bytes:

ff ff 01 02 00 fc

According to the page 22 of the AX12 manual, from example 3.


And again, the code does no get stuck anywhere, means all needed pieces and loops arebeing executed. Also, if i would change commands for obtaining status for Button1 to command say...turn motor or turn on LED. it would work.

But after the obtain status set of commands, the loop with DataRdyUART1 condition starts recording data which is in RX buffer received from AX12... and when on the BUtton2 i reset servo, and start saving recorded data...i see that 9 bytes of garbage...

So it only means that AX12 sent wrong values....

any other ideas?

thank you.
In order not to start new topic i just decided to post back here. So i can now easily send any type of command to AX12 from PIC32, through the HC126/04. But problem is i do not receive anything. Here is a code:

Code: Select all
while(1)
{

   if (Button1Pressed)
   {
      LED1On();

      // obtain status
      DIR1();
        putcUART1(0xff);
        putcUART1(0xff);
        putcUART1(0x01);
        putcUART1(0x02);
        putcUART1(0x01);
        putcUART1(0xfb);

      while(BusyUART1());
      DIR0();

int di = 0; // data index

// This code is responsible for reading UART1 byte by byte
// and saving each byte in an array data[10].
 while (DataRdyUART1())
 {
 data[di] = getcUART1();
 di+=1;
 }


      putsUART2("Command 1 is sent.\r\n");

      
      while (Button1Pressed) ; // wait until depressed


   } else
      LED1Off();

   if (Button2Pressed)
   {
      LED2On();

      // now talk to servo
      DIR1();

      // reset servo
      putcUART1(0xff);
      putcUART1(0xff);
      putcUART1(0x01);
      putcUART1(0x02);
      putcUART1(0x06);
      putcUART1(0xf6);

      while(BusyUART1());
      DIR0();



      // writing the results on SD card
      int i=0;
      for(i=0; i<9; i++)
      {
         FSfwrite (&data[i], 1, 1, pointer);
      }

            FSfclose(pointer);




      putsUART2("Command 2 is sent.\r\n");

      
      while (Button2Pressed) ; // wait until depressed


   } else
      LED2Off();


}



Now, when i transfer to PC and open my binary file, i just see nine bytes with just some garbage values. However, i was supposed to see the following bytes:

ff ff 01 02 00 fc

According to the page 22 of the AX12 manual, from example 3.


And again, the code does no get stuck anywhere, means all needed pieces and loops arebeing executed. Also, if i would change commands for obtaining status for Button1 to command say...turn motor or turn on LED. it would work.

But after the obtain status set of commands, the loop with DataRdyUART1 condition starts recording data which is in RX buffer received from AX12... and when on the BUtton2 i reset servo, and start saving recorded data...i see that 9 bytes of garbage...

So it only means that AX12 sent wrong values....

any other ideas?

thank you.
ColdStart
Robot Builder
Robot Builder
Posts: 17
Joined: Thu Jan 20, 2011 9:28 am

Post by ColdStart » Tue May 10, 2011 3:46 am

Post by ColdStart
Tue May 10, 2011 3:46 am

another detail.

When i decided to print out in a file the value of di, the index used to be incremented while RX buffer is full, it turned out to be 01.

So it means that when the RX buffer was full, and i read it only once with getcUART1(), it became empty... so... it turns that it had only 1 byte... means that AX12 as a response to my obtain status command sent only 1 byte... however he had to sent a set of bytes as mentiond in previous post.

any ideas why would that be?

thanks
another detail.

When i decided to print out in a file the value of di, the index used to be incremented while RX buffer is full, it turned out to be 01.

So it means that when the RX buffer was full, and i read it only once with getcUART1(), it became empty... so... it turns that it had only 1 byte... means that AX12 as a response to my obtain status command sent only 1 byte... however he had to sent a set of bytes as mentiond in previous post.

any ideas why would that be?

thanks
ColdStart
Robot Builder
Robot Builder
Posts: 17
Joined: Thu Jan 20, 2011 9:28 am

Next
54 postsPage 1 of 41, 2, 3, 4
54 postsPage 1 of 41, 2, 3, 4