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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2008-04-23T09:26:22+02:00</updated>

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

		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-04-23T09:26:22+02:00</updated>

		<published>2008-04-23T09:26:22+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5149#p5149</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5149#p5149"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5149#p5149"><![CDATA[
See the AVR-Doper example. It contains an interface to the UART with custom requests to a HID class device. There's also a command line tool in the avrdebug directory.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Wed Apr 23, 2008 9:26 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2008-04-22T21:26:11+02:00</updated>

		<published>2008-04-22T21:26:11+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5144#p5144</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5144#p5144"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5144#p5144"><![CDATA[
Just found that making UART - &gt; HID is really complex task (for me as newbee). Maybe someone did something common to this?<p>Statistics: Posted by Guest — Tue Apr 22, 2008 9:26 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2008-04-22T12:27:26+02:00</updated>

		<published>2008-04-22T12:27:26+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5140#p5140</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5140#p5140"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5140#p5140"><![CDATA[
Thank you for reply. I will not ask about it  <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" />  Anyway Asm is Oo for me. I connected 2 AVR's using UART and it works fine (using AVR-USB CDC). Now i will make it UART -&gt; HID. Thank you.<br />Best regards.<p>Statistics: Posted by Guest — Tue Apr 22, 2008 12:27 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-04-22T10:47:21+02:00</updated>

		<published>2008-04-22T10:47:21+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5137#p5137</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5137#p5137"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5137#p5137"><![CDATA[
If you can use two AVRs: connect them with SPI or whatever (low priority interrupts), use 20 MHz for the frequency measuring AVR and writhe the SPI interrupt routine in assembler. You need to count the number of input pulses during a given period (e.g. 1 second) and the number of CPU clocks taken for these pulses. You get the frequency by dividing.<br /><br />I'm using the following ICP interrupt handler for a similar task:<br /><div class="codebox"><p>Code: </p><pre><code>/*<br />General Description:<br />The input capture pin is connected to a VCO. We want to measure the frequency<br />of that VCO as exact as possible because it represents our analog value.<br />This is done by counting VCO pulses during one timer1 period and measure the<br />total time interval in timer1 ticks during all those pulses. The quotient is<br />then proportional to the frequency. The resulting ADC resolution is 16 bits<br />for one timer1 period. If we sum up multiple timer1 periods, we can increase<br />the resolution accordingly &#40;e.g. 20 bits for a sum of 16 periods&#41;.<br /><br />Limitations:<br />The current interrupt implementation requires:<br />- VCO frequency &gt; clock / 65536 &#40;= 61 Hz @ 4 MHz clock&#41;<br />- VCO frequency &lt; clock / &#40;32 + 1&#41; &#40;= 120kHz @ 4MHz clock&#41;<br /><br />The evaluation code in the main loop may require tighter limits.<br />*/<br /><br />/* configs for io.h */<br />#define __SFR_OFFSET 0<br />#define _VECTOR&#40;N&#41; __vector_ ## N   /* io.h does not define this for asm */<br />#include &lt;avr/io.h&gt; /* for CPU I/O register definitions and vectors */<br />#include &quot;hardware.h&quot;<br /><br />#define x1  r24<br />#define x2  r25<br />#define x3  r26<br /><br />//#define AVERAGE_CNT &#40;F_CPU / T1_PRESCALE / 65536 + UPDATE_FREQ / 2&#41; / UPDATE_FREQ<br /><br />#define AVERAGE_CNT 22<br />/* we choose an averaging count which gives a total measurement time as close as<br /> * possible to 1/50Hz. This should result in good ripple rejection.<br /> * F_CPU = 4e6<br /> * 22 * 65536 / 4e6 = 0.360448s ~ 18/50Hz &#40;deviation = 2.24% of a mains period&#41;<br /> */<br /><br />.text<br /><br />.global SIG_INPUT_CAPTURE1<br />.type   SIG_INPUT_CAPTURE1, @function<br />SIG_INPUT_CAPTURE1:<br />intCapture1:                    ;2 &#40;branch taken from vector&#41;<br />    push    x1                  ;2<br />    in      x1, SREG            ;1<br />    push    x1                  ;2<br />    in      x1, TIFR            ;1<br />    andi    x1, 1 &lt;&lt; TOV1       ;1<br />    brne    .tm1HadOverflow     ;1 -&gt; 10<br />.ignoreOverflow:<br />    lds     x1, _totalPulses    ;2<br />    subi    x1, lo8&#40;-1&#41;         ;1<br />    sts     _totalPulses, x1    ;2<br />    lds     x1, _totalPulses+1  ;2<br />    sbci    x1, hi8&#40;-1&#41;         ;1<br />    sts     _totalPulses+1, x1  ;2<br />.capture1Ready:<br />    pop     x1                  ;2<br />    out     SREG, x1            ;1<br />    pop     x1                  ;2<br />    reti                        ;4<br />                            ;--------<br />                                ; 29 cycles for typical intr / 40 for ignored overflow<br />                                ; avg. 5 cycles latency -&gt; fmaxload = fcpu/34 &#40;117k @ 4M&#41;<br /><br />; process data once every timer 1 overflow<br />.tm1HadOverflow:                ;1 for branch taken<br />    ldi     x1, 1 &lt;&lt; TOV1       ;1<br />    out     TIFR, x1            ;1<br />    lds     x1, _timerWrapCnt   ;2<br />    dec     x1                  ;1<br />    breq    .doEval             ;1 -&gt; 17<br />    sts     _timerWrapCnt, x1   ;2<br />    rjmp    .ignoreOverflow     ;2 -&gt; 21<br />.doEval:                        ;1 for branch taken<br />    push    x2                  ;2<br />    push    x3                  ;2<br />    in      x1, ICR1L           ;1 -&gt; 21 get captured value before next capture<br />    in      x2, ICR1H           ;1 11 cycles latency + 21 = 32 -&gt; fmax = fcpu/32 &#40;125k @ 4M&#41;<br />    lds     x3, _totalPulses    ;2<br />    subi    x3, lo8&#40;-1&#41;         ;1<br />    sts     totalPulses, x3     ;2 store values in global variable &#40;no underscore&#41;<br />    lds     x3, _totalPulses+1  ;2<br />    sbci    x3, hi8&#40;-1&#41;         ;1<br />    sts     totalPulses+1, x3   ;2<br />    clr     x3                  ;1<br />    sts     _totalPulses, x3    ;2 clear local counter<br />    sts     _totalPulses+1, x3  ;2<br />    sei                         ;1 -&gt; 40 cycles until intr enable<br />; now we have time and can relax :-&#41;<br />    lds     x3, _startPulsePos<br />    sts     _startPulsePos, x1  ; store new pulsePos<br />    sub     x1, x3<br />    lds     x3, _startPulsePos+1<br />    sts     _startPulsePos+1, x2<br />    sbc     x2, x3              ; x2:x1 holds pos2 - pos1 now<br />    sts     totalClocks, x1<br />    sts     totalClocks+1, x2<br />    ldi     x3, AVERAGE_CNT<br />    sts     _timerWrapCnt, x3<br />    sbrc    x2, 7<br />    dec     x3                  ; account for negative delta<br />    sts     totalClocks+2, x3<br />    pop     x3<br />    pop     x2<br />    rjmp    .capture1Ready<br /><br /><br />; Local symbols:<br />    .lcomm _totalPulses, 2      ; total captured pulses<br />    .lcomm _startPulsePos, 2    ; pulse position of starting edge in timer1 counts<br /><br />.data<br />    .type   _timerWrapCnt, @object<br />    .size   _timerWrapCnt, 1<br />_timerWrapCnt:                  ; remaining number of overflows until measurement end<br />    .byte   AVERAGE_CNT<br /></code></pre></div><br /><br />Please don't ask me for details about this code <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":-)" title="Smile" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Tue Apr 22, 2008 10:47 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2008-04-21T22:17:21+02:00</updated>

		<published>2008-04-21T22:17:21+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5134#p5134</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5134#p5134"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5134#p5134"><![CDATA[
Well, this is my study project and i simply must do it, either i whant it or not. But while it is study project i'm still intresting in it as in hobby project and want to get it. I have very experienced last days, but now kinda stucked. I cant understand main algorithm in program good.<br /><br />i know:<br /><br /><div class="codebox"><p>Code: </p><pre><code>1. Count pulses with T1 input capture.<br />2. Count time with other timer.<br />3. When time reaches 1 sec. Send T1 contents to USB-HID.<br /></code></pre></div><br /><br />if i cant get enough power for 2 tasks, maybe make other AVR just counting and this one as for sample SPI &gt; USB-HID.<p>Statistics: Posted by Guest — Mon Apr 21, 2008 10:17 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-04-21T20:12:11+02:00</updated>

		<published>2008-04-21T20:12:11+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5133#p5133</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5133#p5133"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5133#p5133"><![CDATA[
You can extend Timer0 in software, but that's not easy. Connect the signal to T1 instead and switch between modes as required.<br /><br />The entire task is not easy. You must be very careful to avoid problems when you are in ICP mode and the frequency increases. I would not recommend this as a beginner's project, at least not with this complexity. If you could use always the same algorithm, it would be much easier.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Mon Apr 21, 2008 8:12 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ps1x]]></name></author>
		<updated>2008-04-21T19:18:20+02:00</updated>

		<published>2008-04-21T19:18:20+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5131#p5131</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5131#p5131"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5131#p5131"><![CDATA[
But T0 is just 8bit timer. It cant contain large values, right?<br />And to setup T1 i must use<br /><div class="codebox"><p>Code: </p><pre><code>TCCR1B=0x06;<br /></code></pre></div><br />?<br />And then, read counted pulses using<br /><div class="codebox"><p>Code: </p><pre><code>TIFR1</code></pre></div><br />?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=995">ps1x</a> — Mon Apr 21, 2008 7:18 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-04-21T18:55:31+02:00</updated>

		<published>2008-04-21T18:55:31+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5129#p5129</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5129#p5129"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5129#p5129"><![CDATA[
You could connect your input signal to T0 AND to ICP. If the input frequency is below 3 kHz, use ICP for high resolution, if it's above 3 kHz, count pulses. This is not straight forward to implement and has problems if the input frequency changes, but it's the only idea I have which does not require external hardware.<br /><br />Regarding gcc: see <!-- m --><a class="postlink" href="http://www.nongnu.org/avr-libc/user-manual/pages.html">http://www.nongnu.org/avr-libc/user-manual/pages.html</a><!-- m --> for a good introduction.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Mon Apr 21, 2008 6:55 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ps1x]]></name></author>
		<updated>2008-04-21T17:58:47+02:00</updated>

		<published>2008-04-21T17:58:47+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5128#p5128</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5128#p5128"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5128#p5128"><![CDATA[
But i have frequencys from 1 to 30000 Hz. And You say this will work for 300 Hz. I need count input pulses which i make with outstanding hardware comparator.<br /><br />Where can i read about WinAVR C language? its very different with CV-AVR...<br /><br />Best regards!<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=995">ps1x</a> — Mon Apr 21, 2008 5:58 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-04-21T12:49:59+02:00</updated>

		<published>2008-04-21T12:49:59+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5127#p5127</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5127#p5127"/>
		<title type="html"><![CDATA[AVR-USB frequency meter]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1358&amp;p=5127#p5127"><![CDATA[
With the input capture unit, use pin ICP1. It captures the value of timer 1 when it triggers and generates an interrupt.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Mon Apr 21, 2008 12:49 pm</p><hr />
]]></content>
	</entry>
	</feed>
