<?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/8480" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2013-06-12T23:04:27+02:00</updated>

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

		<entry>
		<author><name><![CDATA[Niikhawod]]></name></author>
		<updated>2013-06-12T23:04:27+02:00</updated>

		<published>2013-06-12T23:04:27+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25436#p25436</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25436#p25436"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25436#p25436"><![CDATA[
final code for the adc is now: joystick_report.x= (read_adc(4))/4-128;<br />all is now properly working <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" />.<br /><br />thx for the help.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=19760">Niikhawod</a> — Wed Jun 12, 2013 11:04 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2013-06-12T22:29:29+02:00</updated>

		<published>2013-06-12T22:29:29+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25435#p25435</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25435#p25435"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25435#p25435"><![CDATA[
yeah that is because your data reader needs calibrating. <br /><br />example<br /><br />reportBuffer[1]= (read_adc(0)/3 + 200);//pc0 : this is some extreme math <br /><br />You have to now do your own math. Maybe just - 50 from the result ( only a guess ) you'll get it.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Wed Jun 12, 2013 10:29 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Niikhawod]]></name></author>
		<updated>2013-06-12T21:58:53+02:00</updated>

		<published>2013-06-12T21:58:53+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25434#p25434</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25434#p25434"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25434#p25434"><![CDATA[
i have put back the typedef struct, and used joystick_report.x and now it works, but in windows the axis goed to 127 and then jumps to -127 and it does this a few times before it centers on 0.  <img class="smilies" src="./../../../images/smilies/icon_confused.gif" alt=":?" title="Confused" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=19760">Niikhawod</a> — Wed Jun 12, 2013 9:58 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2013-06-12T21:33:07+02:00</updated>

		<published>2013-06-12T21:33:07+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25433#p25433</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25433#p25433"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25433#p25433"><![CDATA[
ok ,what about the report, did you fix that? Should fix the &quot;i have added the code and now its not reporting anything at all.&quot;<br /><br />I dont use a reset like that in my loop this is all I do.<br /><br /><div class="codebox"><p>Code: </p><pre><code> <br />for (;;)<br />{<br />   getdata();<br />   while ( !usbInterruptIsReady () ) { usbPoll(); }<br />   usbSetInterrupt( (void *) &amp;reportBuffer, sizeof(reportBuffer));<br />}<br /></code></pre></div><br />using the while may work better for you.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Wed Jun 12, 2013 9:33 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Niikhawod]]></name></author>
		<updated>2013-06-12T21:18:48+02:00</updated>

		<published>2013-06-12T21:18:48+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25432#p25432</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25432#p25432"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25432#p25432"><![CDATA[
if i take wdt_reset(); out of the main loop the device wil reset itself every second. its there in case the code stops working, and then the device wil restart/reconnect itself.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=19760">Niikhawod</a> — Wed Jun 12, 2013 9:18 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2013-06-12T20:53:56+02:00</updated>

		<published>2013-06-12T20:53:56+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25431#p25431</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25431#p25431"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25431#p25431"><![CDATA[
the only thing I can think of that would give you a disconnect is a infinite loop. This also is a good question for avrfreeks, I dont think the disconnects are v-usb related. I would just debug it and see if your are putting the code in to a long loop.<br /><br />ps: why is  wdt_reset() in the main loop, are you using that for debug? <br />od and where is the 0 report?<br />did you mean:<br />   reportBuffer[0]= (read_adc(0));//pc0<br />   reportBuffer[1]= (read_adc(1))*-1;//pc1<br />   reportBuffer[2]= 128;<br /><br />or <br />joystick_report.x (read_adc(0));//pc0<br />joystick_report.x (read_adc(1))*-1;//pc1<br /><br />never copy from source <img class="smilies" src="./../../../images/smilies/icon_wink.gif" alt=";)" title="Wink" /> !!! I skip 0 for my own reasons.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Wed Jun 12, 2013 8:53 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Niikhawod]]></name></author>
		<updated>2013-06-12T20:40:25+02:00</updated>

		<published>2013-06-12T20:40:25+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25430#p25430</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25430#p25430"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25430#p25430"><![CDATA[
<blockquote><div><cite>ulao wrote:</cite>here is how I do it.<br /><br />//voltage reader.<br />#define ADC_VREF_TYPE 0x40<br />static int read_adc(unsigned char adc_input)<br />{<br />ADMUX=adc_input|ADC_VREF_TYPE;<br />    _delay_us(150);<br />    ADCSRA|=0x40; // Start the AD conversion<br />    while ((ADCSRA &amp; 0x10)==0);// Wait for complete<br />    ADCSRA|=0x10;<br />    return ADCW;<br />} <br /><br />reportBuffer[1]= (read_adc(0));//pc0<br />reportBuffer[2]= (read_adc(1))*-1;//pc1<br /><br />I can not help you with noise that is ore then likely your issue.</div></blockquote><br /><br />i have added the code and now its not reporting anything at all. <img class="smilies" src="./../../../images/smilies/icon_sad.gif" alt=":(" title="Sad" /><br />the device wil disconect and reconnect when i add the ADC interrupt.<br /><br /><br />i have added these lines:<br />declaration of reportBuffer<br /><div class="codebox"><p>Code: </p><pre><code>static uchar    reportBuffer&#91;8&#93;;</code></pre></div><br />added ADC setup to the hardwareInit.<br /><div class="codebox"><p>Code: </p><pre><code>   <br />        ADCSRA |= ((1&lt;&lt;ADPS2) | (1&lt;&lt;ADPS1) | (1&lt;&lt;ADPS0));<br />   ADMUX |= 1&lt;&lt;ADLAR;<br />   ADCSRA |= (1&lt;&lt;ADEN);</code></pre></div><br />then comes the read_adc<br /><br /><div class="codebox"><p>Code: </p><pre><code>static int read_adc(unsigned char adc_input)<br />{<br />   ADMUX=adc_input|ADC_VREF_TYPE;<br />   _delay_us(150);<br />   ADCSRA|=0x40; // Start the AD conversion<br />   while ((ADCSRA &amp; 0x10)==0);// Wait for complete<br />   ADCSRA|=0x10;<br />   return ADCW;<br /><br />} </code></pre></div><br /><br />and last i have the input.<br /><div class="codebox"><p>Code: </p><pre><code>unsigned char input()<br />{<br />   reportBuffer&#91;1&#93;= (read_adc(0));//pc0<br />   reportBuffer&#91;2&#93;= (read_adc(1))*-1;//pc1<br />}</code></pre></div><br /><br />complete code.<br /><div class="codebox"><p>Code: </p><pre><code>#include &lt;avr/io.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/pgmspace.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br /><br />#define F_CPU 20000000L<br />#include &lt;util/delay.h&gt;<br />#include &quot;usbdrv.h&quot;<br />#include &quot;oddebug.h&quot; <br />//voltage reader.<br />#define ADC_VREF_TYPE 1&lt;&lt;REFS0 //0x40<br /><br /><br />static int read_adc(unsigned char adc_input);<br /><br />const PROGMEM char usbHidReportDescriptor&#91;77&#93; = {<br />    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)<br />    0x15, 0x00,                    // LOGICAL_MINIMUM (0)<br />    0x09, 0x04,                    // USAGE (Joystick)<br />    0xa1, 0x01,                    // COLLECTION (Application)<br />    0x05, 0x02,                    //   USAGE_PAGE (Simulation Controls)<br />    0x09, 0xbb,                    //   USAGE (Throttle)<br />    0x15, 0x81,                    //   LOGICAL_MINIMUM (-127)<br />    0x25, 0x7f,                    //   LOGICAL_MAXIMUM (127)<br />    0x75, 0x08,                    //   REPORT_SIZE (8)<br />    0x95, 0x01,                    //   REPORT_COUNT (1)<br />    0x81, 0x02,                    //   INPUT (Data,Var,Abs)<br />    0x05, 0x01,                    //   USAGE_PAGE (Generic Desktop)<br />    0x09, 0x01,                    //   USAGE (Pointer)<br />    0xa1, 0x00,                    //   COLLECTION (Physical)<br />    0x09, 0x30,                    //     USAGE (X)<br />    0x09, 0x31,                    //     USAGE (Y)<br />    0x95, 0x02,                    //     REPORT_COUNT (2)<br />    0x81, 0x02,                    //     INPUT (Data,Var,Abs)<br />    0xc0,                          //   END_COLLECTION<br />    0x09, 0x39,                    //   USAGE (Hat switch)<br />    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)<br />    0x25, 0x03,                    //   LOGICAL_MAXIMUM (3)<br />    0x35, 0x00,                    //   PHYSICAL_MINIMUM (0)<br />    0x46, 0x0e, 0x01,              //   PHYSICAL_MAXIMUM (270)<br />    0x65, 0x14,                    //   UNIT (Eng Rot:Angular Pos)<br />    0x75, 0x04,                    //   REPORT_SIZE (4)<br />    0x95, 0x01,                    //   REPORT_COUNT (1)<br />    0x81, 0x02,                    //   INPUT (Data,Var,Abs)<br />    0x05, 0x09,                    //   USAGE_PAGE (Button)<br />    0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)<br />    0x29, 0x04,                    //   USAGE_MAXIMUM (Button 4)<br />    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)<br />    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)<br />    0x75, 0x01,                    //   REPORT_SIZE (1)<br />    0x95, 0x04,                    //   REPORT_COUNT (4)<br />    0x55, 0x00,                    //   UNIT_EXPONENT (0)<br />    0x65, 0x00,                    //   UNIT (None)<br />    0x81, 0x02,                    //   INPUT (Data,Var,Abs)<br />    0xc0                           // END_COLLECTION<br />};<br /><br /><br />static uchar    reportBuffer&#91;8&#93;;<br />static uchar    idleRate;<br /><br /><br />usbMsgLen_t usbFunctionSetup(uint8_t data&#91;8&#93;)<br />{<br />   usbRequest_t    *rq = (void *)data;<br /><br />   <br />   if((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */<br />      if(rq-&gt;bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */<br />         usbMsgPtr = (void *)&amp;reportBuffer;<br />         return sizeof(reportBuffer);<br />            <br />            }<br />            else if(rq-&gt;bRequest == USBRQ_HID_GET_IDLE){<br />            usbMsgPtr = &amp;idleRate;<br />            return 1;<br />            }      <br />            else if(rq-&gt;bRequest == USBRQ_HID_SET_IDLE){<br />            idleRate = rq-&gt;wValue.bytes&#91;1&#93;;<br />            }<br />         }<br />    else{<br />        /* no vendor specific requests implemented */<br />    }<br />   return 0;<br />}<br /><br /><br /><br />static void hardwareInit(void)<br />{   <br />   PORTB = 0xff;   /* activate all pull-ups */<br />   DDRB = 0;       /* all pins input */<br />   DDRC = 0;       /* all pins input */<br />   PORTD = 0xfa;   /* 1111 1010 bin: activate pull-ups except on USB lines */   <br />   <br /><br />   <br />   uchar   i;<br />   wdt_enable(WDTO_1S);<br />   usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />    <br />   i = 0;<br />    while(--i){             /* fake USB disconnect for &gt; 250 ms */<br />        wdt_reset();<br />        _delay_ms(1);<br />    }<br />   <br />   usbDeviceConnect();<br />   <br />   ADCSRA |= ((1&lt;&lt;ADPS2) | (1&lt;&lt;ADPS1) | (1&lt;&lt;ADPS0));<br />   ADMUX |= 1&lt;&lt;ADLAR;<br />   ADCSRA |= (1&lt;&lt;ADEN); <br /><br />   <br />}<br /><br />static int read_adc(unsigned char adc_input)<br />{<br />   ADMUX=adc_input|ADC_VREF_TYPE;<br />   _delay_us(150);<br />   ADCSRA|=0x40; // Start the AD conversion<br />   while ((ADCSRA &amp; 0x10)==0);// Wait for complete<br />   ADCSRA|=0x10;<br />   return ADCW;<br /><br />} <br /><br />   <br /><br /><br />unsigned char input()<br />{<br />   reportBuffer&#91;1&#93;= (read_adc(0));//pc0<br />   reportBuffer&#91;2&#93;= (read_adc(1))*-1;//pc1<br />   reportBuffer&#91;3&#93;= 128;<br />}<br /><br />int main(void)<br />{<br /><br />   hardwareInit();<br />   usbInit();   <br />   sei();<br /><br />   <br />   <br />   for(;;)<br />   {<br />      wdt_reset();<br />      usbPoll();<br />      input();<br />      <br />      if(usbInterruptIsReady()){<br />            /* called after every poll of the interrupt endpoint */<br />         <br />            usbSetInterrupt((void *)&amp;reportBuffer, sizeof(reportBuffer));<br />        }<br />      <br />   }<br />}<br /></code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=19760">Niikhawod</a> — Wed Jun 12, 2013 8:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2013-06-11T18:18:03+02:00</updated>

		<published>2013-06-11T18:18:03+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25405#p25405</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25405#p25405"/>
		<title type="html"><![CDATA[Re: multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25405#p25405"><![CDATA[
here is how I do it.<br /><br />//voltage reader.<br />#define ADC_VREF_TYPE 0x40<br />static int read_adc(unsigned char adc_input)<br />{<br />ADMUX=adc_input|ADC_VREF_TYPE;<br />    _delay_us(150);<br />    ADCSRA|=0x40; // Start the AD conversion<br />    while ((ADCSRA &amp; 0x10)==0);// Wait for complete<br />    ADCSRA|=0x10;<br />    return ADCW;<br />} <br /><br />reportBuffer[1]= (read_adc(0));//pc0<br />reportBuffer[2]= (read_adc(1))*-1;//pc1<br /><br />I can not help you with noise that is ore then likely your issue.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Tue Jun 11, 2013 6:18 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Niikhawod]]></name></author>
		<updated>2013-06-08T23:33:58+02:00</updated>

		<published>2013-06-08T23:33:58+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25391#p25391</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25391#p25391"/>
		<title type="html"><![CDATA[multiple ADC channels]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8480&amp;p=25391#p25391"><![CDATA[
Hello,<br /><br />i am trying to make a USB-hid device with a atmega328p and i  want to use multiple ADC channels.<br />i have looked at the examples on the main site of objective develpment, but i still can't get it to work propperly.<br />i have managed to get two channels to work but al other channels just have somekind of noise.<br /><br />Here is the code.<br /><div class="codebox"><p>Code: </p><pre><code>#include &lt;avr/io.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/pgmspace.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br /><br />#define F_CPU 20000000L<br />#include &lt;util/delay.h&gt;<br />#include &quot;usbdrv.h&quot;<br />#include &quot;oddebug.h&quot; <br /><br /><br /><br />const PROGMEM char usbHidReportDescriptor&#91;77&#93; = {<br />    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)<br />    0x15, 0x00,                    // LOGICAL_MINIMUM (0)<br />    0x09, 0x04,                    // USAGE (Joystick)<br />    0xa1, 0x01,                    // COLLECTION (Application)<br />    0x05, 0x02,                    //   USAGE_PAGE (Simulation Controls)<br />    0x09, 0xbb,                    //   USAGE (Throttle)<br />    0x15, 0x81,                    //   LOGICAL_MINIMUM (-127)<br />    0x25, 0x7f,                    //   LOGICAL_MAXIMUM (127)<br />    0x75, 0x08,                    //   REPORT_SIZE (8)<br />    0x95, 0x01,                    //   REPORT_COUNT (1)<br />    0x81, 0x02,                    //   INPUT (Data,Var,Abs)<br />    0x05, 0x01,                    //   USAGE_PAGE (Generic Desktop)<br />    0x09, 0x01,                    //   USAGE (Pointer)<br />    0xa1, 0x00,                    //   COLLECTION (Physical)<br />    0x09, 0x30,                    //     USAGE (X)<br />    0x09, 0x31,                    //     USAGE (Y)<br />    0x95, 0x02,                    //     REPORT_COUNT (2)<br />    0x81, 0x02,                    //     INPUT (Data,Var,Abs)<br />    0xc0,                          //   END_COLLECTION<br />    0x09, 0x39,                    //   USAGE (Hat switch)<br />    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)<br />    0x25, 0x03,                    //   LOGICAL_MAXIMUM (3)<br />    0x35, 0x00,                    //   PHYSICAL_MINIMUM (0)<br />    0x46, 0x0e, 0x01,              //   PHYSICAL_MAXIMUM (270)<br />    0x65, 0x14,                    //   UNIT (Eng Rot:Angular Pos)<br />    0x75, 0x04,                    //   REPORT_SIZE (4)<br />    0x95, 0x01,                    //   REPORT_COUNT (1)<br />    0x81, 0x02,                    //   INPUT (Data,Var,Abs)<br />    0x05, 0x09,                    //   USAGE_PAGE (Button)<br />    0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)<br />    0x29, 0x04,                    //   USAGE_MAXIMUM (Button 4)<br />    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)<br />    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)<br />    0x75, 0x01,                    //   REPORT_SIZE (1)<br />    0x95, 0x04,                    //   REPORT_COUNT (4)<br />    0x55, 0x00,                    //   UNIT_EXPONENT (0)<br />    0x65, 0x00,                    //   UNIT (None)<br />    0x81, 0x02,                    //   INPUT (Data,Var,Abs)<br />    0xc0                           // END_COLLECTION<br />};<br /><br /><br /><br /><br />typedef struct{<br />    char   throttle;<br />    char    x;<br />    char    y;<br />    char    buttons;<br />}report_t;<br /><br />static report_t joystick_report;<br />static uchar    idleRate;<br /><br /><br />usbMsgLen_t usbFunctionSetup(uint8_t data&#91;8&#93;)<br />{<br />   usbRequest_t    *rq = (void *)data;<br /><br />   <br />   if((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */<br />      if(rq-&gt;bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */<br />         usbMsgPtr = (void *)&amp;joystick_report;<br />         return sizeof(joystick_report);<br />            <br />            }<br />            else if(rq-&gt;bRequest == USBRQ_HID_GET_IDLE){<br />            usbMsgPtr = &amp;idleRate;<br />            return 1;<br />            }      <br />            else if(rq-&gt;bRequest == USBRQ_HID_SET_IDLE){<br />            idleRate = rq-&gt;wValue.bytes&#91;1&#93;;<br />            }<br />         }<br />    else{<br />        /* no vendor specific requests implemented */<br />    }<br />   return 0;<br />}<br /><br />int input(void)<br />{<br />      //ADCSRA |= 1&lt;&lt;ADSC;<br />      char pins = 0, pinInv;<br />      pins = PINB;<br />      pinInv = ~pins;<br />      //int throttle = (ADCH + 128);<br />      //uint8_t throttle = ;      <br />      //uint8_t x = ;<br />      //uint8_t y = ;<br />      <br />            <br />      <br />      //joystick_report.x = (x + 128);<br />      //joystick_report.y = (y + 128);<br />      joystick_report.buttons = pinInv &lt;&lt; 2;<br />}<br /><br />static void hardwareInit(void)<br />{   <br />   PORTB = 0xff;   /* activate all pull-ups */<br />   DDRB = 0;       /* all pins input */<br />   DDRC = 0;       /* all pins input */<br />   PORTD = 0xfa;   /* 1111 1010 bin: activate pull-ups except on USB lines */   <br />   <br />   uchar   i;<br />   wdt_enable(WDTO_1S);<br />   usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />    <br />   i = 0;<br />    while(--i){             /* fake USB disconnect for &gt; 250 ms */<br />        wdt_reset();<br />        _delay_ms(1);<br />    }<br />   <br />   usbDeviceConnect();<br />   <br /><br />   <br />}<br /><br />int main(void)<br />{<br /><br />   hardwareInit();<br />   usbInit();   <br />   sei();<br /><br />   <br />   <br />   for(;;)<br />   {<br />      wdt_reset();<br />      usbPoll();<br />      input();<br />      if(usbInterruptIsReady()){<br />            /* called after every poll of the interrupt endpoint */<br />         <br />            usbSetInterrupt((void *)&amp;joystick_report, sizeof(joystick_report));<br />        }<br />      <br />   }<br />}<br /><br />ISR(ADC_vect) {<br />   <br />   <br />   //confige ADC      <br />   //enable prescaler - determent by internal/ external clock 20,000,000/128<br />   ADCSRA |= ((1&lt;&lt;ADPS2) | (1&lt;&lt;ADPS1) | (1&lt;&lt;ADPS0));<br />   //8-bit<br />   ADMUX |= 1&lt;&lt;ADLAR;<br />   //set voltage reference<br />   ADMUX |= 1&lt;&lt;REFS0;         //0110 0000 60<br />   //Select input<br />   //ADMUX |= ((0&lt;&lt;MUX3) | (1&lt;&lt;MUX2) | (0&lt;&lt;MUX1) | (1&lt;&lt;MUX0));<br />   //enable interrupts function in ADC<br />   //ADCSRA |= 1&lt;&lt;ADIE;<br />   //enable global interrupts<br />   sei();<br />   //turn on the ADC features<br />   ADCSRA |= 1&lt;&lt;ADEN;<br />   //start the first conversion<br />   ADCSRA |= 1&lt;&lt;ADSC;<br />     <br />      ADCSRA |= 1&lt;&lt;ADSC;<br />      <br />     //ADMUX |= ch;    <br />    // ADCSRA |= (1&lt;&lt;ADSC);<br />     //while (!(ADCSRA &amp; (1&lt;&lt;ADIF)));<br />    // ADCSRA |= (1&lt;&lt;ADIF);<br />    // return ADC;<br />  } <br /></code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=19760">Niikhawod</a> — Sat Jun 08, 2013 11:33 pm</p><hr />
]]></content>
	</entry>
	</feed>
