<?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=17&amp;t=6510" />

<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-08-22T07:27:41+01:00</updated>

<author><name><![CDATA[RoboSavvy Forum]]></name></author>
<id>http://forum.robosavvy.com/feed.php?f=17&amp;t=6510</id>
<entry>
<author><name><![CDATA[roboard]]></name></author>
<updated>2010-08-22T07:27:41+01:00</updated>
<published>2010-08-22T07:27:41+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6510&amp;p=27936#p27936</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6510&amp;p=27936#p27936"/>
<title type="html"><![CDATA[Re: C++ PWM Sample Code]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6510&amp;p=27936#p27936"><![CDATA[
Some programming information can be found in RoBoIO 1.6 Introducion Slide, which can be downloaded from:<br /><br /><!-- m --><a class="postlink" href="http://www.roboard.com/download_ml.htm">http://www.roboard.com/download_ml.htm</a><!-- m --><br /><br /><br />We also plan to release a set of simple demo tools for RoBoIO functions in the future. The following is the source code of the PWM demo tool for your reference: <img src="http://forum.robosavvy.com/images/smilies/icon_smile.gif" alt=":)" title="Smile" /><br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>#include &lt;stdio.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br />#ifdef WINCE<br />    #include &lt;windows.h&gt;<br />#endif<br /><br />#if defined&#40;WINCE&#41; || defined&#40;WIN32&#41;<br />    #include &lt;roboard_dll.h&gt;  // use the DLL version of RoBoIO lib<br />    // #include &lt;roboard.h&gt;   // use the static version of RoBoIO lib<br />#else<br />    #include &lt;roboard.h&gt;<br />#endif<br /><br /><br />void PWM_help&#40;char* s&#41; &#123;<br />    printf&#40;<br />        &quot;Parameter                                                       \n&quot;<br />        &quot;==========                                                      \n&quot;<br />        &quot;%s &#91;channel&#93; &#91;period&#93; &#91;duty&#93; &#91;count&#93;                            \n&quot;<br />        &quot;                                                                \n&quot;<br />        &quot;   &#91;channel&#93; :                                                  \n&quot;<br />        &quot;      0 ~ 23 &#40;for RB-100&#41;                                       \n&quot;<br />        &quot;      0 ~ 15 &#40;for RB-110&#41;                                       \n&quot;<br />        &quot;                                                                \n&quot;<br />        &quot;   &#91;period&#93; &#40;PWM period&#41;:                                       \n&quot;<br />        &quot;      set PWM period &#40;unit: microsecond&#41;                        \n&quot;<br />        &quot;      period time must &gt; duty time.                             \n&quot;<br />        &quot;                                                                \n&quot;<br />        &quot;   &#91;duty&#93; &#40;PWM duty&#41;:                                           \n&quot;<br />        &quot;      set PWM duty &#40;unit: microsecond&#41;                          \n&quot;<br />        &quot;                                                                \n&quot;<br />        &quot;   &#91;count&#93; : &#40;PWM pulse count&#41;                                  \n&quot;<br />        &quot;      set the count of PWM pulses to output.                    \n&quot;<br />        &quot;                                                                \n&quot;<br />        &quot;&#40;Press Enter key to continue...&#41;                                \n&quot;<br />        , s<br />    &#41;;<br />    getchar&#40;&#41;;<br /><br />    printf&#40;<br />        &quot;example                                                         \n&quot;<br />        &quot;========                                                        \n&quot;<br />        &quot;%s 0 1000 150 200                                               \n&quot;<br />        &quot;    send 200 PWM pulses with period 1ms and duty 0.15ms on PWM  \n&quot;<br />        &quot;    channel 0 &#40;pin S1&#41;.                                         \n&quot;<br />        &quot;                                                                \n&quot;<br />        &quot;%s 3 10000 1200 100                                             \n&quot;<br />        &quot;    send 100 PWM pulses with period 10ms and duty 1.2ms on PWM  \n&quot;<br />        &quot;    channel 3 &#40;pin S4&#41;.                                         \n&quot;<br />        &quot;                                                                \n&quot;<br />        , s, s<br />    &#41;;<br /><br />&#125;<br /><br />int GetChannel&#40;char* str&#91;&#93;&#41; &#123;<br />    unsigned int val;<br /><br />    val = &#40;unsigned int&#41; atoi&#40;str&#91;1&#93;&#41;;<br /><br />    //if&#40;val &gt;= 16&#41; // for RB-110<br />    if&#40;val &gt;= 24&#41;   // for RB-100<br />    &#123;<br />        printf&#40;&quot;ERR: wrong PWM channel!!!\n\n&quot;&#41;;<br />        PWM_help&#40;str&#91;0&#93;&#41;;<br />        exit&#40;1&#41;;<br />    &#125;<br /><br />    return val;<br />&#125;<br /><br />unsigned long GetPeriod&#40;char* str&#91;&#93;&#41; &#123;<br />    unsigned long period;<br /><br />    period =  &#40;unsigned long&#41; atol&#40;str&#91;2&#93;&#41;;<br /><br />    if&#40;period == 0L&#41;<br />    &#123;<br />        printf&#40;&quot;ERR: period is zero !!!\n\n&quot;&#41;;<br />        PWM_help&#40;str&#91;0&#93;&#41;;<br />        exit&#40;1&#41;;<br />    &#125;<br /><br />    return period;<br />&#125;<br /><br />unsigned long GetDuty&#40;char* str&#91;&#93;, unsigned long period&#41; &#123;<br />    unsigned long duty;<br /><br />    duty =  &#40;unsigned long&#41; atol&#40;str&#91;3&#93;&#41;;<br /><br />    if&#40;duty == 0L&#41;<br />    &#123;<br />        printf&#40;&quot;ERR: duty is zero !!!\n\n&quot;&#41;;<br />        PWM_help&#40;str&#91;0&#93;&#41;;<br />        exit&#40;1&#41;;<br />    &#125;<br /><br />    if&#40;duty &gt;= period&#41;<br />    &#123;<br />        printf&#40;&quot;ERR: duty &gt;= period !!!\n\n&quot;&#41;;<br />        PWM_help&#40;str&#91;0&#93;&#41;;<br />        exit&#40;1&#41;;<br />    &#125;<br /><br />    return duty;<br />&#125;<br /><br /><br />unsigned long GetCount&#40;char* str&#91;&#93;&#41; &#123;<br />    unsigned long count;<br /><br />    count =  &#40;unsigned long&#41; atol&#40;str&#91;4&#93;&#41;;<br /><br />    if&#40;count == 0L&#41;<br />    &#123;<br />        printf&#40;&quot;ERR: count is zero !!!\n\n&quot;&#41;;<br />        PWM_help&#40;str&#91;0&#93;&#41;;<br />        exit&#40;1&#41;;<br />    &#125;<br /><br />    return count;<br />&#125;<br /><br /><br />#ifdef WINCE<br />int _tmain&#40;int argc, _TCHAR* _argv&#91;&#93;&#41;<br />&#123;<br />    char  argvbuf&#91;50&#93;&#91;100&#93; = &#123;'\0'&#125;;<br />    char* argv&#91;50&#93;;<br /><br />    if &#40;argc &gt; 50&#41; argc = 50;<br />    for &#40;int _argc=0; _argc&lt;argc; _argc++&#41;<br />    &#123;<br />        argv&#91;_argc&#93; = &amp;&#40;argvbuf&#91;_argc&#93;&#91;0&#93;&#41;;<br />        wcstombs&#40;argv&#91;_argc&#93;, _argv&#91;_argc&#93;, 100&#41;;<br />    &#125;<br />#else<br />int main&#40;int argc, char* argv&#91;&#93;&#41;<br />&#123;<br />#endif<br /><br />    int channel;<br />    unsigned long usedchannel;<br />    unsigned long period, duty, count;<br /><br />    usedchannel = RCSERVO_USECHANNEL0 +RCSERVO_USECHANNEL1 +RCSERVO_USECHANNEL2 +RCSERVO_USECHANNEL3 + RCSERVO_USECHANNEL4 +RCSERVO_USECHANNEL5 +RCSERVO_USECHANNEL6 +RCSERVO_USECHANNEL7 +RCSERVO_USECHANNEL8 +RCSERVO_USECHANNEL9 +RCSERVO_USECHANNEL10 +RCSERVO_USECHANNEL11 +RCSERVO_USECHANNEL12 +RCSERVO_USECHANNEL13 +RCSERVO_USECHANNEL14 +RCSERVO_USECHANNEL15 +RCSERVO_USECHANNEL16 +RCSERVO_USECHANNEL17 +RCSERVO_USECHANNEL18 +RCSERVO_USECHANNEL19 +RCSERVO_USECHANNEL20 +RCSERVO_USECHANNEL21 +RCSERVO_USECHANNEL22 +RCSERVO_USECHANNEL23; // for RB-100<br />/*<br />    usedchannel = RCSERVO_USECHANNEL0 +RCSERVO_USECHANNEL1 +RCSERVO_USECHANNEL2 +RCSERVO_USECHANNEL3 +RCSERVO_USECHANNEL4 +RCSERVO_USECHANNEL5 +RCSERVO_USECHANNEL6 +RCSERVO_USECHANNEL7 +RCSERVO_USECHANNEL8 +RCSERVO_USECHANNEL9 +RCSERVO_USECHANNEL10 +RCSERVO_USECHANNEL11 +RCSERVO_USECHANNEL12 +RCSERVO_USECHANNEL13 +RCSERVO_USECHANNEL14 +RCSERVO_USECHANNEL15; // for RB-110<br />*/<br /><br />    // Before using any specific lib in RoBoIO, one must<br />    // call roboio_SetRBVer&#40;&#41; to set the version of RoBoard<br />    // so that the hardware features of different version<br />    // of RoBoards can be recognized correctly.<br /><br />    roboio_SetRBVer&#40;RB_100&#41;;<br /><br />    if&#40;argc == 1&#41;<br />    &#123;<br />        PWM_help&#40;argv&#91;0&#93;&#41;;<br />        return 0;<br />    &#125;<br /><br />    if &#40;argc != 5&#41;<br />    &#123;<br />        printf&#40;&quot;ERR: wrong parameter number!!!\n\n&quot;&#41;;<br />        PWM_help&#40;argv&#91;0&#93;&#41;;<br />        return 1;<br />    &#125;<br /><br />    channel = GetChannel&#40;argv&#41;;<br />    period  = GetPeriod&#40;argv&#41;;<br />    duty    = GetDuty&#40;argv, period&#41;;<br />    count   = GetCount&#40;argv&#41;;<br /><br />    // Initialize PWM interface<br />    if &#40;rcservo_Initialize&#40;usedchannel&#41; == false&#41;<br />    &#123;<br />        printf&#40;&quot;ERR: fail to initialize RCSERVO &#40;%s&#41;!\n&quot;, roboio_GetErrMsg&#40;&#41;&#41;;<br />        return 1;<br />    &#125;<br />    <br />    rcservo_EnterPWMMode&#40;&#41;;<br /><br />    rcservo_SendPWMPulses&#40;channel, period, duty, count&#41;;<br /><br />    printf&#40;&quot;Start to send %ld PWM pluses with period %ld us\n&quot;<br />           &quot;and duty %ld us on PWM channel %d.\n\n&quot;, count, period, duty, channel&#41;;<br /><br />    while&#40;rcservo_IsPWMCompleted&#40;channel&#41; == false&#41;;<br /><br />    printf&#40;&quot;Send %ld PWM pulses completed.\n&quot;, count&#41;;<br />    rcservo_Close&#40;&#41;;<br />    return 0;<br />&#125;<br /></code></dd></dl><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1542">roboard</a> — Sun Aug 22, 2010 7:27 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[snest]]></name></author>
<updated>2010-08-22T01:04:47+01:00</updated>
<published>2010-08-22T01:04:47+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6510&amp;p=27934#p27934</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6510&amp;p=27934#p27934"/>
<title type="html"><![CDATA[C++ PWM Sample Code]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6510&amp;p=27934#p27934"><![CDATA[
Does anybody have an example of C++ code that will get a PWM working?<br /><br />I'm running Linux, and the only API I've seen for the Roboard amounts to comments in the various library files. It's not clear to me which functions I need to call, and with what range of inputs, in order to get a PWM up and running.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2254">snest</a> — Sun Aug 22, 2010 1:04 am</p><hr />
]]></content>
</entry>
</feed>