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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2011-03-01T03:46:48+02:00</updated>

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

		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2011-03-01T03:46:48+02:00</updated>

		<published>2011-03-01T03:46:48+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=5488&amp;p=17753#p17753</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=5488&amp;p=17753#p17753"/>
		<title type="html"><![CDATA[Re: ADC problem with v-usb HID mouse]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=5488&amp;p=17753#p17753"><![CDATA[
I do the same thing. I dont have any issues. <br /><br />this is my adc set up<br /><div class="codebox"><p>Code: </p><pre><code>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 /></code></pre></div><br />and then init<br /><div class="codebox"><p>Code: </p><pre><code>   ADMUX=0x1;//ADC init<br />   ADCSRA=0x83;</code></pre></div><br /><br />here is a read I do.<br /><div class="codebox"><p>Code: </p><pre><code>   reportBuffer&#91;1&#93;=128;reportBuffer&#91;2&#93;=128;<br />      unsigned char newPadX=255-readADC(0);<br />      unsigned char newPadY=255-readADC(1);<br />      reportBuffer&#91;1&#93;=( 6 *(newPadX-padX)+128 ); <br />      padX=newPadX;<br /></code></pre></div><br />In my case I watch for a value from the ADC then move the mouse that amount. Other wise the ADC is normally 0 ( no movement ). I'm sort of emulating a spinner.<br /><br />Now if you see jumps my imitate clue it that your pot is dirty. Did you try to clean the track? Its not an atari or other 30 year old pot/VR I hope <img class="smilies" src="./../../../images/smilies/icon_wink.gif" alt=";)" title="Wink" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Tue Mar 01, 2011 3:46 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2011-02-28T12:58:59+02:00</updated>

		<published>2011-02-28T12:58:59+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=5488&amp;p=17738#p17738</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=5488&amp;p=17738#p17738"/>
		<title type="html"><![CDATA[ADC problem with v-usb HID mouse]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=5488&amp;p=17738#p17738"><![CDATA[
Hello, forum<br /><br />I am using V-USB HID mouse example on ATMEGA8 and it works fine.<br />I want to use ADC for mouse movement. <br />The general idea is that the mouse speed (.dx and .dy) depends on the speed of voltage change on ADC pin (ADC0, pin 23 in my case). The problem is that the mouse pointer (on PC screen) sometimes makes weird jumps ranging from few cm to over a half of the screen width (all on the x-axis as they should be). <br /><br />Here is the code i am using. It is just for x-axis.  The added code:<br /><br />//*****************************************************************************<br />//<br />//  ADC module initialization  <br />//<br />//*****************************************************************************<br />void adc_init(void)<br />{<br />//select reference voltage<br />//AVCC with external capacitor at AREF pin<br />ADMUX|=(0&lt;&lt;REFS1)|(1&lt;&lt;REFS0);<br />//set prescaller and enable ADC<br />ADCSRA|=(1&lt;&lt;ADEN)|(1&lt;&lt;ADIE);//enable ADC with dummy conversion<br />}<br />//*****************************************************************************<br />//<br />//  ADC single conversion routine  <br />//<br />//*****************************************************************************<br />void adc_start_conversion(char channel)<br />{<br />//set ADC channel<br />ADMUX=(ADMUX&amp;0xF0)|channel;<br />//Start conversion with Interrupt after conversion<br />//enable global interrupts<br />sei();<br />ADCSRA |= (1&lt;&lt;ADSC)|(1&lt;&lt;ADIE);<br />}<br /><br />int adc_value;<br />int adc_value_prev;<br />int diff;<br /><br />void value()<br />{<br />adc_value_prev=adc_value;<br />adc_value=ADCL;<br />adc_value+=(ADCH&lt;&lt;8);<br />diff=adc_value-adc_value_prev;<br />reportBuffer.dx=diff;<br />}<br /><br />ISR (ADC_vect)<br />{<br />sei();<br />value();<br />}<br /><br /><br />And here is the main loop with changes:<br /><br /><br />for(;;){                /* main event loop */<br />        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */<br />        wdt_reset();<br />     usbPoll();<br />if(usbInterruptIsReady()){<br />            /* called after every poll of the interrupt endpoint */<br />    adc_start_conversion(0);<br />            DBG1(0x03, 0, 0);   /* debug output: interrupt report prepared */<br />            usbSetInterrupt((void *)&amp;reportBuffer, sizeof(reportBuffer));<br />        }<br /><br />My inital guess was that the interrupt from ADC does not work well together with USB generated interrupts. I tried to use ADC without interrupt (ADCSRA |= (1&lt;&lt;ADSC)|(0&lt;&lt;ADIE);) , but with no significant improvement.<br />Any idea where is the problem?<br />Could it be that the USB interrupts the ADConversion, to that the &quot;current&quot; value of ADC is &quot;0&quot;?<p>Statistics: Posted by Guest — Mon Feb 28, 2011 12:58 pm</p><hr />
]]></content>
	</entry>
	</feed>
