<?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="https://forums.obdev.at/app.php/feed/topic/4901" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2010-11-27T18:45:53+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/4901</id>

		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2010-11-27T18:45:53+02:00</updated>

		<published>2010-11-27T18:45:53+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4901&amp;p=16860#p16860</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4901&amp;p=16860#p16860"/>
		<title type="html"><![CDATA[Re: Communication is taking more than expected time]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4901&amp;p=16860#p16860"><![CDATA[
Help on what, exactly? Where is the problem?<p>Statistics: Posted by Guest — Sat Nov 27, 2010 6:45 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ajayramak]]></name></author>
		<updated>2010-10-08T13:58:12+02:00</updated>

		<published>2010-10-08T13:58:12+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4901&amp;p=16154#p16154</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4901&amp;p=16154#p16154"/>
		<title type="html"><![CDATA[Communication is taking more than expected time]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4901&amp;p=16154#p16154"><![CDATA[
Hello.<br />We have built a frequency acquisition device based on ATmega8 and Python and are using USB for communication.<br />In the usbdrv.h file it is said that the interrupt takes a maximum of 1200 cycles. We are operating at 16Mhz clock and the communication time is coming out to be 60-80ms. The python code sends a USB control-in transfer once every 250ms and the total number of bytes sent is 200. We are grateful for any help you can give.<br /><br />here is my firmware code<br /><div class="codebox"><p>Code: </p><pre><code>#include &lt;avr/io.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/interrupt.h&gt;  /* for sei() */<br />#include &lt;util/delay.h&gt;     /* for _delay_ms() */<br /><br />#include &lt;avr/pgmspace.h&gt;   /* required by usbdrv.h */<br />#include &quot;usbdrv.h&quot;<br />#define F_CPU 16000000<br /><br />uchar pres,prev,mask,ind&#91;4&#93;;<br />short int ch1,ch2,ch3,ch4,chf1,chf2,chf3,chf4;<br />short int dataBuffer&#91;110&#93;;  <br /><br />/*=============================================================================<br />                Timer2 Interrupt routine<br />=============================================================================*/<br /><br />ISR(TIMER2_COMP_vect)<br />{<br />   sei();<br />   ch1++;<br />   ch2++;<br />   ch3++;<br />   ch4++;<br />   <br />}<br /><br />/* ------------------------------------------------------------------------- */<br />/* ----------------------------- USB interface ----------------------------- */<br />/* ------------------------------------------------------------------------- */<br /><br />usbMsgLen_t usbFunctionSetup(uchar data&#91;8&#93;)<br />{<br />  <br />  TCCR2=0;<br />  TIMSK &amp;=!(1&lt;&lt;OCIE2);<br /><br />usbRequest_t    *rq = (void *)data;<br /><br /><br />    if(rq-&gt;bRequest == 0)                 /* echo -- used for reliability tests */<br />    {       <br />        dataBuffer&#91;0&#93; = rq-&gt;wValue.bytes&#91;0&#93;;<br />        dataBuffer&#91;1&#93; = rq-&gt;wValue.bytes&#91;1&#93;;<br />        dataBuffer&#91;2&#93; = rq-&gt;wIndex.bytes&#91;0&#93;;<br />        dataBuffer&#91;3&#93; = rq-&gt;wIndex.bytes&#91;1&#93;;<br />        usbMsgPtr = dataBuffer;          /* tell the driver which data to return */<br />    return 4;<br />    }<br />    <br />    else if(rq-&gt;bRequest == 1)         /*reset and restart timer by host request */<br />    {<br />        <br />        ch1=ch2=ch3=ch4=0;<br />        ind&#91;0&#93;=1;<br />        ind&#91;1&#93;=26;<br />        ind&#91;2&#93;=51;<br />        ind&#91;3&#93;=76;<br />    <br />    <br />        TIMSK|=(1&lt;&lt;OCIE2);      /*enable compare match interrupt*/<br />        TCCR2=0x09;            /*start timer with no prescaler, CTC mode*/ <br />        TCNT2=0;                 /*Clear timer count*/<br />        TIFR&amp;=!(1&lt;&lt;OCF2);<br />        PORTB&amp;=!(1&lt;&lt;1);<br />    return 0;<br />    }<br />    <br />    else if(rq-&gt;bRequest == 2)<br />    {   <br />    dataBuffer&#91;0&#93;=ind&#91;0&#93;;<br />    dataBuffer&#91;25&#93;=ind&#91;1&#93;;<br />    dataBuffer&#91;50&#93;=ind&#91;2&#93;;<br />    dataBuffer&#91;75&#93;=ind&#91;3&#93;;   <br />        usbMsgPtr = dataBuffer;         /* tell the driver which data to return */<br />    PORTB|=(1&lt;&lt;1);<br />        return 200;                       /* tell the driver to send 200 bytes */<br />    }<br />    return 0;   /* default for not implemented requests: return no data back to host */<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /><br />int main(void)<br />{<br />uchar   i;<br /><br /><br /><br />    wdt_enable(WDTO_1S);<br />    /* Even if you don't use the watchdog, turn it off here. On newer devices,<br />     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!<br />     */<br />    usbInit();<br />    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />    i = 0;<br />    while(--i){             /* fake USB disconnect for &gt; 250 ms */<br />        wdt_reset();<br />        _delay_ms(1);<br />    }<br />    usbDeviceConnect();<br />    <br />    sei();<br />    OCR2=0x78;         /* set compare match value  */<br />    <br />    <br />    DDRC=0xf0;<br />    DDRB=0x3f;<br />    DDRD=0xeb;<br />    prev=PINC;<br />    ind&#91;0&#93;=1;<br />    ind&#91;1&#93;=26;<br />    ind&#91;2&#93;=51;<br />    ind&#91;3&#93;=76;<br />    for(;;)<br />    {  <br />      /* main event loop */<br />        wdt_reset();<br />        usbPoll();<br />    <br />    pres=PINC;<br />    mask=( prev ^ pres ) &amp; pres;    /* rising edge */<br />    if(mask) <br />    {<br />      TIMSK&amp;=!(1&lt;&lt;OCIE2);<br />      chf1 = ch1;        /* Freeze all the counter value upon transition detection*/<br />      chf2 = ch2;<br />      chf3 = ch3;<br />      chf4 = ch4;<br />      TIMSK|=(1&lt;&lt;OCIE2);<br /><br />      if((mask &amp; 1) &amp;&amp; (ind&#91;0&#93;&lt;25))<br />      {<br />        dataBuffer&#91;ind&#91;0&#93;&#93; = chf1;<br />        ind&#91;0&#93;++;<br />        ch1=0;<br />      }<br />      <br />      if((mask &amp; (1&lt;&lt;1)) &amp;&amp; (ind&#91;1&#93;&lt;50))<br />      {<br />        dataBuffer&#91;ind&#91;1&#93;&#93; = chf2;<br />        ind&#91;1&#93;++;<br />        ch2=0;<br />      }<br />      <br />      if((mask &amp; (1&lt;&lt;2)) &amp;&amp; (ind&#91;2&#93;&lt;75))<br />      {<br />        dataBuffer&#91;ind&#91;2&#93;&#93; = chf3;<br />        ind&#91;2&#93;++;<br />        ch3=0;<br />      }<br />      <br />      if((mask &amp; (1&lt;&lt;3)) &amp;&amp; (ind&#91;3&#93;&lt;100))<br />      {<br />        dataBuffer&#91;ind&#91;3&#93;&#93; = chf4;<br />        ind&#91;3&#93;++;<br />        ch4=0;<br />      }<br />    }<br />    prev=pres;<br />    }<br />    return 0;<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /></code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=4424">ajayramak</a> — Fri Oct 08, 2010 1:58 pm</p><hr />
]]></content>
	</entry>
	</feed>
