<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="http://forum.robosavvy.com/feed.php?f=5&amp;t=6699" />

<title>RoboSavvy Forum</title>
<subtitle>Robosavvy Forum: The largest online community of Humanoid Robot Builders</subtitle>
<link href="http://forum.robosavvy.com/index.php" />
<updated>2010-12-04T21:09:45+01:00</updated>

<author><name><![CDATA[RoboSavvy Forum]]></name></author>
<id>http://forum.robosavvy.com/feed.php?f=5&amp;t=6699</id>
<entry>
<author><name><![CDATA[billyzelsnack]]></name></author>
<updated>2010-12-04T21:09:45+01:00</updated>
<published>2010-12-04T21:09:45+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29137#p29137</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29137#p29137"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29137#p29137"><![CDATA[
Ok. I think I see what you are talking about now. In my implementation ( <!-- m --><a class="postlink" href="http://robosavvy.com/forum/viewtopic.php?t=5808&amp;sid=c750d31947b8a97da9754ff330fd7488">http://robosavvy.com/forum/viewtopic.ph ... f330fd7488</a><!-- m --> ) I had a dynamixel device and the USB2DYNAMIXEL (or whatever) combined. This allowed me to write out to the second UART (over USB) whenever I wanted.<br /><br />Since the USB2DYNAMIXEL (or whatever) has no knowledge of what data is what, it just passes ALL dynamixel side traffic back over USB. Is this correct?<br /><br />I'm thinking that even with dynamixel protocol 2.0 this will not be possible without USB2DYNAMIXEL firmware updates. At some point the dynamixel to PC bridge (whatever it is) needs to make a decision on what NOT to send over.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=459">billyzelsnack</a> — Sat Dec 04, 2010 9:09 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[i-Bot]]></name></author>
<updated>2010-12-04T17:40:26+01:00</updated>
<published>2010-12-04T17:40:26+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29134#p29134</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29134#p29134"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29134#p29134"><![CDATA[
The servos listen and track the bus protocol for all transactions. They action only packets addressed to them or the broadcast address. They respond to only their address.<br />Existing implementations of syncread use the broadcast address and this violates the dynamixel bus protocol.<br /><blockquote class="uncited"><div><br />ID 0XFE is the Broadcasting ID which indicates all of the connected Dynamixel units. Packets sent with this ID apply to all Dynamixel units on the network. Thus packets sent with a broadcasting ID will not return any status packets.<br /></div></blockquote><br />You would need to check that a syncread response did not confuse devices due to the broadcast ID, but with the top bit cleared in the instruction byte. Or use a different address instead of broadcast for the sync read.<br />Accurate tracking of bus state is important to dynamixel devices, because the 0xFF 0xFF sequence can occur in data.<br /><br />Also you now have two bus masters. While the usual bus master is waiting for a reply it will see all the AX-S1 messages. I assume your usual bus master is dumb (USB2Dynamixel), else why do this anyway.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=159">i-Bot</a> — Sat Dec 04, 2010 5:40 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[billyzelsnack]]></name></author>
<updated>2010-12-04T16:54:56+01:00</updated>
<published>2010-12-04T16:54:56+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29133#p29133</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29133#p29133"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29133#p29133"><![CDATA[
<blockquote><div><cite>i-Bot wrote:</cite><br />If you were to use the AX-S1 to interpret the sync read, you would probably need to do it different to current implementations, and maybe change the servo firmware too.<br />Existing sync reads (Arbotix, urbi,..) are point to point implementations which include the dynamixel protocol. They are not used directly on the dynamixel bus with multiple slaves, because they violate the dynamixel protocol. Since all devices on the dynamixel bus track the bus state, this violation may cause confusion due to the new states introduced by bus cycles within bus cycles, and responses to broadcasts.<br /><br />I guess now we have to await the publication of the dynamixel 2.0 protocol to see what that has in terms of faster bus operation.<br /></div></blockquote><br /><br />I'm not seeing it. The other servos would only respond to their own requests. They can care less whether bus chatter originates from another dynamixel or some USB interface or whatever.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=459">billyzelsnack</a> — Sat Dec 04, 2010 4:54 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[siempre.aprendiendo]]></name></author>
<updated>2010-12-04T16:35:53+01:00</updated>
<published>2010-12-04T16:35:53+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29132#p29132</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29132#p29132"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29132#p29132"><![CDATA[
<blockquote class="uncited"><div><br />...<br />I guess now we have to await the publication of the dynamixel 2.0 protocol to see what that has in terms of faster bus operation.<br /></div></blockquote><br /><br />Dynamixel 2.0? Where do you hear/read about it?<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=698">siempre.aprendiendo</a> — Sat Dec 04, 2010 4:35 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[i-Bot]]></name></author>
<updated>2010-12-04T14:45:22+01:00</updated>
<published>2010-12-04T14:45:22+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29131#p29131</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29131#p29131"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29131#p29131"><![CDATA[
If you were to use the AX-S1 to interpret the sync read, you would probably need to do it different to current implementations, and maybe change the servo firmware too.<br />Existing sync reads (Arbotix, urbi,..) are point to point implementations which include the dynamixel protocol. They are not used directly on the dynamixel bus with multiple slaves, because they violate the dynamixel protocol. Since all devices on the dynamixel bus track the bus state, this violation may cause confusion due to the new states introduced by bus cycles within bus cycles, and responses to broadcasts.<br /><br />I guess now we have to await the publication of the dynamixel 2.0 protocol to see what that has in terms of faster bus operation.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=159">i-Bot</a> — Sat Dec 04, 2010 2:45 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[billyzelsnack]]></name></author>
<updated>2010-12-04T03:57:05+01:00</updated>
<published>2010-12-04T03:57:05+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29122#p29122</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29122#p29122"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=29122#p29122"><![CDATA[
Here's an idea. Make a new firmware that makes the mostly useless AX-S1 (also?) do all the busy work for SYNC_READ support.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=459">billyzelsnack</a> — Sat Dec 04, 2010 3:57 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[limor]]></name></author>
<updated>2010-11-18T13:08:57+01:00</updated>
<published>2010-11-18T13:08:57+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28844#p28844</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28844#p28844"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28844#p28844"><![CDATA[
I spent some time looking through the OpenServo source code thinking that these guys at openservo know their stuff when it comes to servo control so why not use their code. and they sure do.<br /><br />The main loop of openservo looks like this:<br /><dl class="codebox"><dt>Code: </dt><dd><code>main&#40;&#41; &#123;<br />  ...<br />   for&#40;&#41; &#123;<br />      if &#40;adc_position_value_is_ready&#40;&#41;&#41; &#123; ... do stuff ... &#125;<br />      if &#40;adc_power_value_is_ready&#40;&#41;&#41; &#123; ... &#125;<br />      if &#40;twi_data_in_receive_buffer&#40;&#41;&#41; &#123; .... &#125;<br />   &#125;<br />&#125;</code></dd></dl><br /><br /><br />registers.c - a set of global variables used everywhere. Instead of just using a bunch of global variables, the registers.c functions provide two functions: registers_read_word(), registers_write_word() - they disable interrupts, then they read/write from the global variables, then re-enable interrupts. this ensures there is no race condition where an interrupt changes values as they are being read or written to.<br />There are also helper routines like fixed_multiply() which i think are used to multiplies floats or longs.<br /><br />There are 3 interrupts in use:<br />  - ADC sampling is done every 10ms (timer0). this is also the timeframe for changing any control parameters. The advantage of doing it only 100 times/sec is that you get 6-10 point change in the potentiometer sample. so you can use this to determine speed with some degree of precision (if you sample 1000 times/sec you will see 1-2 point change and this makes it hard to determine speed without a speed estimator or a brutal average).<br />  - TWI - for communications over i2c. In our AX12 this is irrelevant since we use the UART interface at 1mhz.<br />  - pulse - pin0changed interrupt + uses timer2 interrupt to measure pulse length<br /><br />The openservo can be compiled to different requirements by setting /unsetting #defines.<br /> - React to RC pwm signal instead (in addition to) I2C. The pulse pwm signal may be coming from RC remote control for example.<br /> - Apply IPD control for position control<br /> - Apply PID control for position control (difference?)<br /> - Estimate velocity by emulating the servo mechanical/electrical model (uses floating point calculations)<br /> - Motion control - Control speed of servo and get it to follow a smooth pre-defined curve (Beizer curve, there's a utility you can download from openservo.org to help create these curves with up to 8 waypoints). go through predefined way-points at given time. so you can control a complex real-time path. this is similar to humanoid/hexapod gait control paradigm only the path is stored in the servo. personally i'd prefer to do this from an embedded linux controlling the speed and curves and modifying them to react to the environment.<br /><br />So if you want IPD control, you just need to set the #define accordingly. the main loop will call the routine and the routine will change the PWM duty cycle that goes to the motor, every time it is called. this happens 100 times/sec every time the ADC is interrupt happens.<br /><br />About &quot;pulse control&quot; - it waits for RC pwm signal (1ms - 2ms) representing 0..1023 available target positions and goes there at full speed.<br /><dl class="codebox"><dt>Code: </dt><dd><code>     registers_write_word&#40;REG_SEEK_POSITION_HI, REG_SEEK_POSITION_LO, pulse_position&#41;;<br />     registers_write_word&#40;REG_SEEK_VELOCITY_HI, REG_SEEK_VELOCITY_LO, 0&#41;;</code></dd></dl><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2">limor</a> — Thu Nov 18, 2010 1:08 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[limor]]></name></author>
<updated>2010-11-18T13:10:53+01:00</updated>
<published>2010-11-18T12:43:22+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28843#p28843</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28843#p28843"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28843#p28843"><![CDATA[
So we have speed control of the AX12.<br /><br />This draft of the AX12 firmware provides 2 control states.<br /><br />Speed control - modifies the PWM duty cycle to compensate for varying for external torque and maintain fixed speed<br /><br />PD position control - once target position is reached, a kind of PID control is applied in order to create a &quot;spring effect&quot; around the target position.<br /><br />You can <a href="https://docs.google.com/leaf?id=0B6v3OAPrxb24YmE0N2IwNmQtMWQzYi00ZjM5LThiZDMtNDMxZDU4Y2Y2ZGY1&amp;hl=en" class="postlink">download</a> and flash the AX12.BIN file and play with it.<br /><br />- use robot terminal, putty or any other terminal emulator connect at 57600 baud<br />- connect to a servo through usb2dynamixel + SMP2Dynamixel <br />(CM5 can be used to power the bus, just make sure it isnt playing any motions and disturbing disturbing the data line)<br />- when you power the bus, press and hold the '#' key and you will see a bootloader '*' prompt where you can enter a few commands like &quot;help&quot; and &quot;load&quot;<br /><br />to modify the code:<br />download AVRSTudio with AVRGCC (free download)<br />-- compile the project (target CPU is Atmega8, 16mhz)<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2">limor</a> — Thu Nov 18, 2010 12:43 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[billyzelsnack]]></name></author>
<updated>2010-11-17T15:40:24+01:00</updated>
<published>2010-11-17T15:40:24+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28830#p28830</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28830#p28830"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28830#p28830"><![CDATA[
MOHITJINDAL. <br /><!-- m --><a class="postlink" href="http://support.robotis.com/en/software/dynamixelsdk.htm">http://support.robotis.com/en/software/dynamixelsdk.htm</a><!-- m --><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=459">billyzelsnack</a> — Wed Nov 17, 2010 3:40 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[MOHIT JINDAL]]></name></author>
<updated>2010-11-17T05:11:05+01:00</updated>
<published>2010-11-17T05:11:05+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28826#p28826</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28826#p28826"/>
<title type="html"><![CDATA[How to control 18 AX 12 from USB2Dynamixel only ?]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28826#p28826"><![CDATA[
Do you have a code program to control 18 Servos from Usb2Dynamixel ?<br /><br />Mail me at <!-- e --><a href="mailto:mohitjindal_niit@yahoo.co.in">mohitjindal_niit@yahoo.co.in</a><!-- e --> <img src="http://forum.robosavvy.com/images/smilies/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes" />  <img src="http://forum.robosavvy.com/images/smilies/icon_question.gif" alt=":?:" title="Question" /><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2428">MOHIT JINDAL</a> — Wed Nov 17, 2010 5:11 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[limor]]></name></author>
<updated>2010-11-16T20:33:37+01:00</updated>
<published>2010-11-16T20:33:37+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28818#p28818</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28818#p28818"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28818#p28818"><![CDATA[
New firmware has been working for a couple of days. Source code will soon be available. The following video shows the AX12 running the new firmware and maintaining constant speed unlike any AX12 with standard dynamixel firmware.<br /><br /><div class='bbmedia' data-url='http://www.youtube.com/watch?v=ZC_g3ztkRbw?fs=1&amp;amp;hl=en_US' style='margin: 1px; display: inline-block; vertical-align: bottom;'><div style='width: 200px; height: 40px; border: 1px solid #999; display: table-cell; text-align: center; vertical-align: middle; font: 10px/10px Verdana; color: #555; opacity: 0.5;'><a style='color: #105289; text-decoration: none;' href='http://phpbbex.com/' target='_blank'>phpBB</a> &#91;media&#93;</div><script>if (typeof bbmedia == 'undefined') { bbmedia = true; var e = document.createElement('script'); e.async = true; e.src = 'js/bbmedia.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(e, s); }</script></div><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2">limor</a> — Tue Nov 16, 2010 8:33 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[limor]]></name></author>
<updated>2010-11-09T22:50:44+01:00</updated>
<published>2010-11-09T22:50:44+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28685#p28685</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28685#p28685"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28685#p28685"><![CDATA[
We are working on is getting the Openservo's PID code running inside AX12  <img src="http://forum.robosavvy.com/images/smilies/icon_wink.gif" alt=":wink:" title="Wink" /> <br /><br />ultimately the plan is to develop new firmware with these specs:<br /><br />1) proper speed control. Current Dynamixel firmware lacks real speed control. it is only good at holding position. Speed control is acheived by changing the amount of current going to the motor to maintain a constant speed.<br /><br />2) a proper control loop between the bus-master and the servos. Currently with Dynamixel the most efficient method is using [billyzelsnack's coined term] SYNC_READ. ie: bus-master asks the servos their position one after the other and then tells them where to go using one long packet SYNC_WRITE. With 12 servos we reached about 170 cycles/sec (where the CM5 is bus-master for a bunch of AX12 servos on the bus<br /><br />= We expect to get 2 times speed improvement : CM5 - AX12<br />= We expect to get about at least 150 cycles/sec : Linux - USB2Dynamixel - AX12<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2">limor</a> — Tue Nov 09, 2010 10:50 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[billyzelsnack]]></name></author>
<updated>2010-11-09T19:40:39+01:00</updated>
<published>2010-11-09T19:40:39+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28683#p28683</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28683#p28683"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28683#p28683"><![CDATA[
Sweet. I was under the impression that something goofy was going on that prevented this. Guess not. This opens up a lot of possibilities.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=459">billyzelsnack</a> — Tue Nov 09, 2010 7:40 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[limor]]></name></author>
<updated>2010-11-09T21:34:28+01:00</updated>
<published>2010-11-09T18:04:27+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28680#p28680</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28680#p28680"/>
<title type="html"><![CDATA[New: alternative firmware for AX12]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6699&amp;p=28680#p28680"><![CDATA[
Ricardo has been playing around with AX12 firmware.<br />(see <!-- m --><a class="postlink" href="http://actuated.wordpress.com">http://actuated.wordpress.com</a><!-- m -->)<br />The process of replacement is quite simple:<br />1) AVRStudio compiles the code, exports hex.<br />2) hex2bin converts to bin file.<br />3) using USB2Dynamixel (+ SMPS2Dynamixel to power the servo), connect servo and in robot-terminal connect to the line at 56700 baud.<br />4) press '#' continuously when powering the servo; bootloader prompt appears<br />5) use the command &quot;load&quot; to load the firmware just like with CM5<br /><br />The following code is a preliminary &quot;sketch&quot;. After loading it, keep the robot-terminal open. It reads the characters from the serial port and expects either + or - and increases/decreases the speed of the motor, printing out the value from the potentiometer.<br /><br /><br /><br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>#include &quot;avr/delay.h&quot;<br />#include &quot;avr/io.h&quot;<br />#include &quot;avr/iom8.h&quot;<br />#include &quot;avr/interrupt.h&quot;<br />#include &quot;ctype.h&quot;<br /><br />#define BIT0 0x1<br />#define BIT1 0x2<br />#define BIT2 0x4<br />#define BIT3 0x8<br />#define BIT4 0x10<br />#define BIT5 0x20<br />#define BIT6 0x40<br />#define BIT7 0x80<br /><br /><br />#define AX12_PING      0x01<br />#define AX12_READ      0x02<br />#define AX12_WRITE      0x03<br />#define AX12_REG      0x04<br />#define AX12_ACTION      0x05<br />#define AX12_RESET      0x06<br />#define AX12_SYNC_WR   0x83<br /><br /><br />#define HalfDuplexTransceiver_Port      PORTD<br />#define HalfDuplexTransceiver_Dir      DDRD<br />#define HalfDuplexTransceiver_PinOUT   BIT7<br />#define HalfDuplexTransceiver_PinIN      BIT6<br /><br />#define Baud9600    207<br />#define Baud57600   34<br />#define Baud115200  16<br />#define Baud500000  3<br />#define Baud1000000 1<br />#define Baud2000000 0<br /><br /><br /><br />#define bit&#40;param&#41; &#40;1&lt;&lt;param&gt;0&#41;?1:0&#41;<br />#define TXBuffEmpty &#40;&#40;&#40;UCSRA&amp;bit&#40;TXC&#41;&#41;&gt;0&#41;?1:0&#41;<br /><br /><br />#define SET_WRITE HalfDuplexTransceiver_Port|=HalfDuplexTransceiver_PinOUT;HalfDuplexTransceiver_Port&amp;=~HalfDuplexTransceiver_PinIN;<br /><br />#define SET_READ HalfDuplexTransceiver_Port&amp;=~HalfDuplexTransceiver_PinOUT;HalfDuplexTransceiver_Port|=HalfDuplexTransceiver_PinIN;<br /><br /><br />#define Position_Dir       DDRC<br />#define Position_Port      PORTC<br />#define Position_Pin      BIT0<br />#define Temperature_Dir       DDRC<br />#define Temperature_Port   PORTC<br />#define Temperature_Pin      BIT2<br /><br /><br /><br /><br />#define SERVOBuffer_MAX_SIZE 100<br /><br />typedef struct SERVO_DATA_STRUCT<br />&#123;<br />   uint8_t u8ServoID;<br />   uint8_t u8ServoInstruction;<br />   uint8_t u8ServoDataLength;<br />   uint8_t u8ServoData&#91;SERVOBuffer_MAX_SIZE&#93;;<br />&#125; stServo_Data;<br /><br /><br /><br />#define UART_Baudrate Baud57600<br /><br /><br />#define Led      BIT2<br />#define Led_Port PORTD<br />#define Led_Dir  DDRD<br /><br /><br /><br />#define LED_ON  Led_Port &amp;= ~Led;<br />#define LED_OFF Led_Port |= Led;<br /><br /><br />#define Motor_Clockwise    BIT1<br />#define Motor_Anticlockwise   BIT2<br />#define Motor_Port          PORTB<br />#define Motor_Dir          DDRB<br /><br />//#define RotateClockwise     Motor_Port |= Motor_Clockwise;Motor_Port &amp;= ~&#40;Motor_Anticlockwise&#41;;<br />//#define RotateAnticlockwise Motor_Port |= Motor_Anticlockwise;Motor_Port &amp;= ~&#40;Motor_Clockwise&#41;;<br />//#define RotateStop         Motor_Port &amp;= ~&#40;Motor_Clockwise|Motor_Anticlockwise&#41;; <br /><br /><br />uint16_t PWM=1000;<br />uint16_t Temperature=0;<br />uint16_t Position=0;<br /><br /><br /><br /><br />void StopMotor&#40;void&#41;<br />&#123;<br />   TCCR1A &amp;= ~&#40;bit&#40;COM1A1&#41;|bit&#40;COM1B1&#41;&#41;;<br />   OCR1A = OCR1B = 0;<br />   Motor_Port&amp;= ~&#40;Motor_Clockwise|Motor_Anticlockwise&#41;;<br />&#125;<br /><br /><br /><br />int8_t SetPWM&#40;uint16_t pwm&#41;<br />&#123;<br />   <br />   TCCR1A &amp;= ~&#40;bit&#40;COM1A1&#41;|bit&#40;COM1B1&#41;&#41;;<br />   OCR1A = OCR1B = 0;<br />   Motor_Port&amp;= ~&#40;Motor_Clockwise|Motor_Anticlockwise&#41;;<br />   if&#40;pwm==1000&#41;<br />   &#123;<br />      TCCR1A &amp;= ~&#40;bit&#40;COM1A1&#41;|bit&#40;COM1B1&#41;&#41;;<br />      OCR1A = OCR1B = 0;<br />      Motor_Port&amp;= ~&#40;Motor_Clockwise|Motor_Anticlockwise&#41;;<br />      return 0;<br />   &#125;<br />   else<br />   if&#40;&#40;pwm&gt;1000&#41; &amp;&amp; &#40;pwm&lt;=2000&#41;&#41;<br />   &#123;<br />      TCCR1A &amp;= ~&#40;bit&#40;COM1A1&#41;|bit&#40;COM1B1&#41;&#41;;<br />      Motor_Port&amp;= ~&#40;Motor_Anticlockwise&#41;;<br />      TCCR1A |= bit&#40;COM1A1&#41;;<br />      OCR1A = &#40;pwm-1000&#41;;<br />      return 1;<br />   &#125;<br />   else<br />   if&#40;&#40;pwm&lt;1000&gt;=0&#41;&#41;<br />   &#123;<br />      TCCR1A &amp;= ~&#40;bit&#40;COM1A1&#41;|bit&#40;COM1B1&#41;&#41;;<br />      Motor_Port&amp;= ~&#40;Motor_Clockwise&#41;;<br />      TCCR1A |= bit&#40;COM1B1&#41;;<br />      OCR1B = &#40;1000-pwm&#41;;<br />      return 1;<br />   &#125;<br />   return -1;<br />&#125;<br /><br /><br />void InitTimer&#40;void&#41;<br />&#123;<br />   //InitTimer0<br />   TCCR0|=bit&#40;CS01&#41;;//assuming the clkIO is 16MHZ, the prescaler devided by 64 wich mean that for 100 positions<br />   //TCCR0|=bit&#40;CS01&#41;;                     // PWM we have 250KHz of timer, meaning this 2500Hz of PWM <br />   TIMSK |= bit&#40;TOIE0&#41;;//enable interrupt<br />   TCNT0=0x00;<br /><br /><br />   //Init Timer 1 for PWM<br />   Motor_Port&amp;= ~&#40;Motor_Clockwise|Motor_Anticlockwise&#41;;   <br /><br />   TCNT1 = 0;<br />   TCCR1A = 0;<br />   TCCR1B = 0;<br />   //TCCR1C = 0;<br />   //TIMSK1 = 0;<br /><br />   ICR1=1000; // 10KHz PWM<br />   <br />   TCCR1B = &#40;bit&#40;WGM13&#41;|bit&#40;CS10&#41;&#41;;<br />   // Set the PWM duty cycle to zero.<br />   <br />   OCR1A = 0;<br />   OCR1B = 0;<br />   <br />   StopMotor&#40;&#41;;<br />   <br />&#125;<br /><br /><br /><br /><br /><br />uint16_t POSITION_AD&#40;void&#41;<br />&#123;<br />   uint16_t returned=0;<br />   uint8_t temp=0;<br />   while&#40;ADCSRA&amp;bit&#40;ADSC&#41;&#41;;<br />   //ADCSRA&amp;=bit&#40;ADIF&#41;;<br />   ADMUX&amp;=~&#40;bit&#40;MUX0&#41;|bit&#40;MUX1&#41;|bit&#40;MUX2&#41;|bit&#40;MUX3&#41;&#41;;// this select the ad multiplexer to channel ADC0 position input<br />   //ADCSRA|=bit&#40;ADEN&#41;;  // start the conversion processes<br />   ADCSRA|=&#40;bit&#40;ADSC&#41;|bit&#40;ADEN&#41;&#41;;  // start the conversion processes<br />   while&#40;ADCSRA&amp;bit&#40;ADSC&#41;&#41;;//wait for the end<br />   temp = ADCL;<br />   returned = ADCH;<br />   returned = &#40;returned&lt;&lt;8&#41;;<br />   returned += temp;<br />   ADCSRA&amp;=&#40;bit&#40;ADEN&#41;&#41;;<br />   return &#40; ADCL + &#40;ADCH&lt;&lt;8&#41;&#41;; // this represents a 16bit variable<br />&#125;<br /><br /><br />uint16_t TEMPERATURE_AD&#40;void&#41;<br />&#123;<br />   uint16_t returned=0;<br />   uint8_t temp=0;<br />   while&#40;ADCSRA&amp;bit&#40;ADSC&#41;&#41;;<br />   //ADCSRA&amp;=bit&#40;ADIF&#41;;<br />   ADMUX&amp;=~&#40;bit&#40;MUX0&#41;|bit&#40;MUX2&#41;|bit&#40;MUX3&#41;&#41;;// this select the ad multiplexer to channel ADC0 position input<br />   ADMUX|=bit&#40;MUX1&#41;;<br />   //ADCSRA|=bit&#40;ADEN&#41;;  // start the conversion processes<br />   ADCSRA|=&#40;bit&#40;ADSC&#41;|bit&#40;ADEN&#41;&#41;;  // start the conversion processes<br />   while&#40;ADCSRA&amp;bit&#40;ADSC&#41;&#41;;//wait for the end<br />   temp = ADCL;<br />   returned = ADCH;<br />   returned = &#40;returned&lt;&lt;8&#41;;<br />   returned += temp;<br />   ADCSRA&amp;=&#40;bit&#40;ADEN&#41;&#41;;<br />   return &#40; ADCL + &#40;ADCH&lt;&lt;8&gt;0&#41;<br />   &#123;<br />      UDR=*Array++;<br />      while&#40;!TXByteEmpty&#41;;<br />      counter--;<br />   &#125;<br />   while&#40;!TXBuffEmpty&#41;;<br />   UCSRA|=bit&#40;TXC&#41;;<br />   SET_READ;<br /><br />&#125;<br /><br /><br />void InitSerial&#40;uint16_t SerialSpeed&#41;<br />&#123;<br />   <br />   <br /><br />   <br />   UCSRA = bit&#40;U2X&#41;;    <br />   //using double speed<br />   UCSRB = &#40;/*bit&#40;RXCIE&#41;|bit&#40;UDRIE&#41;|*/bit&#40;RXEN&#41;|bit&#40;TXEN&#41;/*|bit&#40;TXCIE&#41;*/&#41;; // enable RX and TX interrupt RX and TX<br />   UCSRB &amp;= ~&#40;bit&#40;RXB8&#41;|bit&#40;TXB8&#41;|bit&#40;UCSZ2&#41;&#41;;   // disable  TX and RX nineth bit and reset UCSZ2, this is used with UCSZ1 and UCSZ0 to determine the length of the word<br />   UCSRC = ~&#40;bit&#40;UMSEL&#41;|bit&#40;UPM0&#41;|bit&#40;UPM1&#41;|bit&#40;USBS&#41;|bit&#40;UCPOL&#41;&#41;;//disable parity and set assyncronous, set 1stopBit and polarity on rising edge<br />   UCSRC |= &#40;bit&#40;UCSZ1&#41;|bit&#40;UCSZ0&#41;|bit&#40;UCPOL&#41;&#41;;<br />   //   UCSZ2=0 UCSZ1=1 UCSZ0=1 =&gt; 8bit length<br />   UBRRH = &#40;&#40;SerialSpeed&#41;&gt;&gt;8&#41;;   //set baud counter high<br />   UBRRL = &#40;SerialSpeed&amp;0xFF&#41;;          //set baud counter low                                                                                             <br />   //sei&#40;&#41;;<br />   UCSRA|=bit&#40;TXC&#41;;<br /><br />&#125;<br /><br /><br />void PrintDecimal &#40;int Data&#41;<br />&#123;<br /><br />   volatile uint16_t counter=5, firstNum=0, result=0, temp=0;<br />   volatile uint16_t divisor=10000;<br /><br />   if&#40;Data&gt;0&#41;<br />   &#123;<br />      while&#40;counter--&#41;<br />      &#123;<br />         result=Data/divisor;<br />         if&#40; &#40;result&gt;0&#41; || &#40;firstNum==1&#41;&#41;<br />         &#123;<br />            firstNum=1;<br />            result+=0x30;<br />            SendArray&#40;&#40;uint8_t *&#41;&amp;result,1&#41;;<br />            result-=0x30;<br />         &#125;<br />         Data-=&#40;result*divisor&#41;;<br />         divisor=&#40;divisor/10&#41;;<br />      &#125;<br />   &#125;<br />   else<br />   if&#40;Data&lt;0&gt;0&#41; || &#40;firstNum&gt;0&#41;&#41;<br />         &#123;<br />            firstNum++;<br />            result+=0x30;<br />            if&#40;firstNum==1&#41;<br />            &#123;<br />               SendArray&#40;&quot;-&quot;,1&#41;;<br />            &#125;<br /><br />            SendArray&#40;&#40;uint8_t *&#41;&amp;result,1&#41;;<br />            result-=0x30;<br />         &#125;<br />         Data-=&#40;result*divisor&#41;;<br />         divisor=&#40;divisor/10&#41;;<br />      &#125;<br />   &#125;<br />   else<br />   &#123;<br />      result=0x30;<br />      SendArray&#40;&#40;uint8_t*&#41;&amp;result,1&#41;;<br />   &#125;<br /><br />&#125;<br /><br /><br /><br /><br />uint8_t GetChar&#40;uint8_t *c&#41;<br />&#123;<br />   if&#40;UCSRA&amp;bit&#40;RXC&#41;&#41;<br />   &#123;<br />      *c=UDR;   <br />      return 1;<br />   &#125;<br /><br />   return 0;<br />   <br />&#125;<br /><br />void main &#40;void&#41;<br />&#123;<br /><br />   uint8_t c=0;<br />   WDTCR=0;<br /><br />   Motor_Dir|= &#40;Motor_Clockwise|Motor_Anticlockwise&#41;;<br />   HalfDuplexTransceiver_Dir  |=   &#40;HalfDuplexTransceiver_PinOUT|HalfDuplexTransceiver_PinIN&#41;;<br />   Led_Dir |= Led;<br />   InitSerial&#40;UART_Baudrate&#41;;<br />   InitTimer&#40;&#41;;<br />   //InitADs&#40;&#41;;<br />   //RotateStop<br />   LED_OFF<br />   sei&#40;&#41;;<br />   PWM=1000;<br />   //ADCSRA&amp;=bit&#40;ADIF&#41;; // clear adc interrupt flag<br />   //SendArray&#40;&quot;\n&quot;,1&#41;;<br />   while&#40;1&#41;<br />   &#123;<br />      //SendArray&#40;&quot;Ola Azeiteirinhu\n\r&quot;,18&#41;;<br /><br />      if&#40;GetChar&#40;&amp;c&#41;&#41;<br />      &#123;<br />         if&#40;c==0x2B&#41;<br />         &#123;<br />            if&#40;PWM&lt;1990&gt;=10&#41;<br />            &#123;<br />               PWM-=10;<br />               SetPWM&#40;PWM&#41;;<br />            &#125;<br />            SendArray&#40;&quot;\n\rPWM: &quot;,7&#41;;<br />            PrintDecimal&#40;PWM&#41;;<br />         &#125;<br /><br />         <br />      &#125;<br /><br />      //SET_READ;<br />      /*   SendArray&#40;&quot;\rPosition: &quot;,12&#41;;<br />      PrintDecimal&#40;Position&#41;;<br />      SendArray&#40;&quot;   Temperature: &quot;,16&#41;;<br />      PrintDecimal&#40;Temperature&#41;;<br />      SendArray&#40;&quot;     &quot;,5&#41;;*/<br />      <br />   &#125;<br />&#125;<br /><br /><br /></code></dd></dl><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2">limor</a> — Tue Nov 09, 2010 6:04 pm</p><hr />
]]></content>
</entry>
</feed>