<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=15740&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2016-08-21T21:02:31+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=15740&amp;mode</id>
<entry>
<author><name><![CDATA[jaca_76]]></name></author>
<updated>2016-08-21T21:02:31+01:00</updated>
<published>2016-08-21T21:02:31+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=166725#p166725</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=166725#p166725"/>
<title type="html"><![CDATA[Re: Kalibracja AS3935]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=166725#p166725"><![CDATA[
Zadanie jest takie znaleźć wartość rejestru przy którym częstotliwość generowana na nóżce jest najbliżej 31250Hz.<br />Pętla for służy do zmiany wartości wpisywanej do rejestru a w niej sprawdzamy częstotliwość.<br />Na chwilę obecną zrobiłem to przy pomocy dodatkowej funkcji na wzór z Arduino millis(). Nie za bardzo mi się podoba to rozwiązanie.<br />Kod wygląda następująco:<br />[syntax=c]uint8_t tuneAntena (void)<br />{<br /><br />uint16_t stop_count=0;<br />uint16_t target = 3125;<br />int bestdiff = 32767;<br />int currdiff = 0;<br />uint8_t bestTune = 0;<br />uint8_t currTune = 0;<br />cli();<br />Timer0_init();<br />Int2_init();<br />int32_t setupTime;<br /><br />// set lco_fdiv divider to 0, which translates to 16<br />// so we are looking for 31250Hz on irq pin<br />// and since we are counting for 100ms that translates to number 3125<br />// each capacitor changes second least significant digit<br />// using this timing so this is probably the best way to go<br />sei();<br />start();<br />registerWrite(AS3935_LCO_FDIV,0);<br />registerWrite(AS3935_DISP_LCO,1);<br />// tuning is not linear, can't do any shortcuts here<br />// going over all built-in cap values and finding the best<br />   for (currTune = 0; currTune &lt;= 0x0F ; currTune++)<br />      {<br /><br /><br />registerWrite(AS3935_TUN_CAP,currTune);<br />         // wait to settle<br />_delay_ms(10);<br />currentcount=0;<br />stop_count=0;<br />setupTime=millis()+100;<br />// wait 100ms for measurments<br />while ((long int)millis() - setupTime&lt;0)<br />{<br />//<br />}<br />ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {<br />stop_count=currentcount;<br />}<br />currentcount=0;<br /> currdiff = target - stop_count;<br /> // don't look at me, abs() misbehaves<br /> if(currdiff &lt; 0)<br /> currdiff = -currdiff;<br /> if(bestdiff &gt; currdiff)<br /> {<br /> bestdiff = currdiff;<br /> bestTune = currTune;<br /> }<br />      }<br /><br /><br />if (bestdiff&lt;109)<br />{<br />   registerWrite(AS3935_TUN_CAP,bestTune);<br />_delay_ms(2);<br />registerWrite(AS3935_DISP_LCO,0);<br />// and now do RCO calibration<br />powerUp();<br />uart_putint(bestTune,10);<br />     uart_puts(&quot; &quot;);<br />    uart_putint(bestdiff,10);<br />     uart_puts(&quot;\r\n&quot;);<br />return (1);<br />}<br />// if error is over 109, we are outside allowed tuning range of +/-3.5%<br />else<br />{<br />powerUp();<br />return (0);<br /><br />}<br />}<br /><br />ISR(INT2_vect)<br />{<br />currentcount++;<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2479">jaca_76</a> — 21 sie 2016, o 21:02</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[matekogon]]></name></author>
<updated>2016-07-10T09:21:20+01:00</updated>
<published>2016-07-10T09:21:20+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163762#p163762</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163762#p163762"/>
<title type="html"><![CDATA[Re: Kalibracja AS3935]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163762#p163762"><![CDATA[
Kolego delaye mają wpływ bo wstrzymują  cały program. Trochę ten kod jakiś zagmatwany bo jeśli chcesz obliczyć czestotliwosc sygnału. To musisz zliczyć ilość impulsów następnie otrzymujesz częstotliwość f=1s/ilość impulsów. Czyli program powinien wyglądać tak Włączasz zliczanie impulsów włączasz timera odliczania czasu 1s i po odliczeniu czasu odczytujesz wartość zliczonych impulsów. Nie wiem dla czego wykorzystujesz tu pętle for a następnie w niej wykonujesz while ( czekasz na flagę)<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1380">matekogon</a> — 10 lip 2016, o 09:21</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jaca_76]]></name></author>
<updated>2016-07-08T22:04:55+01:00</updated>
<published>2016-07-08T22:04:55+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163708#p163708</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163708#p163708"/>
<title type="html"><![CDATA[Re: Kalibracja AS3935]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163708#p163708"><![CDATA[
Tam jest wygodniej , przynajmniej dla mnie.<br /><br />Dzięki za :<br />TIMSK1 &amp;=~(1&lt;&lt;OCIE1A);<br /><br />Ale czy licznik się wyzreuje? Czy też powinienem wpisać OCR1A = 1799 ?<br />Edit:<br /><br />I jeszcze jedno spostrzeżenie, kiedy zamiast w każdym przejściu pętli for zwiększać currentune i wpisywać go do rejestru w celu znalezienia najlepszej konfiguracji ustawię go na sztywno - 0 <br />z poniższym kodem mam tak że w pierwszym przebiegu mam mniej przerwań   . Kolejne są stabilne.<br />Podobnie jest dla innych wartości .<br />Skąd ta różnica ??<br />I dlaczego delay ma wpływ na pomiar ?<br /><br /><br />[syntax=c]void tuneAntena (void)<br />{<br />int stop_count=0;<br />int target = 3125;<br />int bestdiff = 32767;<br />int currdiff = 0;<br />uint8_t bestTune = 0;<br />uint8_t currTune = 0;<br />// set lco_fdiv divider to 0, which translates to 16<br />// so we are looking for 31250Hz on irq pin<br />// and since we are counting for 100ms that translates to number 3125<br />// each capacitor changes second least significant digit<br />// using this timing so this is probably the best way to go<br />registerWrite(AS3935_LCO_FDIV,0);<br />registerWrite(AS3935_DISP_LCO,1);<br />// tuning is not linear, can't do any shortcuts here<br />// going over all built-in cap values and finding the best<br />   for (currTune = 0; currTune &lt;= 0x0F ; currTune++)<br />      {<br />registerWrite(AS3935_TUN_CAP,0);<br />         // wait to settle<br />       //  _delay_ms(10);<br />//        cli();<br />         TIMSK1 &amp;=~(1&lt;&lt;OCIE1A);<br />         OCR1A=1799;<br />         ms_flag=0;<br />    //  sei();<br />         TIMSK1 |= (1&lt;&lt;OCIE1A);<br />         currentcount = 0;<br /><br />         while (!ms_flag)<br />         {<br /><br />         }<br />         stop_count=currentcount;<br />        uart_putint(stop_count,10);<br />        uart_puts(&quot;\r\n&quot;);<br /> currdiff = target - stop_count;<br /> // don't look at me, abs() misbehaves<br /> if(currdiff &lt; 0)<br /> currdiff = -currdiff;<br /> if(bestdiff &gt; currdiff)<br /> {<br /> bestdiff = currdiff;<br /> bestTune = currTune;<br /> }<br />      }<br />   uart_puts(&quot;Best Tune:  \r\n&quot;);<br />   uart_putint(bestTune,10);<br />   uart_puts(&quot;\r\n&quot;);<br />   uart_puts(&quot;Best diff:  \r\n&quot;);<br />   uart_putint(bestdiff,10);<br />   uart_puts(&quot;\r\n&quot;);<br />registerWrite(AS3935_TUN_CAP,bestTune);<br />_delay_ms(2);<br />registerWrite(AS3935_DISP_LCO,0);<br />// and now do RCO calibration<br />powerUp();<br />// if error is over 109, we are outside allowed tuning range of +/-3.5%<br />}[/syntax]<br /><a href="https://obrazkiforum.atnel.pl/2479/347d7eef674ace5b24af73b2ee1ea1cb.PNG"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/2479/347d7eef674ace5b24af73b2ee1ea1cb.PNG" alt="Obrazek" /></a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2479">jaca_76</a> — 8 lip 2016, o 22:04</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jaca_76]]></name></author>
<updated>2016-07-08T22:04:54+01:00</updated>
<published>2016-07-08T22:04:54+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163707#p163707</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163707#p163707"/>
<title type="html"><![CDATA[Re: Kalibracja AS3935]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163707#p163707"><![CDATA[
Tam jest wygodniej , przynajmniej dla mnie.<br /><br />Dzięki za :<br />TIMSK1 &amp;=~(1&lt;&lt;OCIE1A);<br /><br />Ale czy licznik się wyzreuje? Czy też powinienem wpisać OCR1A = 1799 ?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2479">jaca_76</a> — 8 lip 2016, o 22:04</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[matekogon]]></name></author>
<updated>2016-07-08T21:51:34+01:00</updated>
<published>2016-07-08T21:51:34+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163706#p163706</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163706#p163706"/>
<title type="html"><![CDATA[Re: Kalibracja AS3935]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163706#p163706"><![CDATA[
Kolego odpaliłeś timera a nadal używasz  delaya:) Jeśli dobrze pamiętam sei() włączenie globalnego zezwolenia na wszystkie  przerwania więc jak wyłaczasz to wylączasz wszystkie  . Timer możesz wyłączyć poprzez wyłączenie &quot;zezwolenia na przerwania od porównania&quot; czyli TIMSK1 &amp;=~(1&lt;&lt;OCIE1A);<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1380">matekogon</a> — 8 lip 2016, o 21:51</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jaca_76]]></name></author>
<updated>2016-07-08T21:07:03+01:00</updated>
<published>2016-07-08T21:07:03+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163704#p163704</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163704#p163704"/>
<title type="html"><![CDATA[Re: Kalibracja AS3935]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163704#p163704"><![CDATA[
taki monolog.<br />Próba z timerem dała lepsze wyniki.<br />Nie podoba mi się tylko inicjowanie timera przy każdym przejściu pętli ale nie wiem jak zatrzymać/zrestartować timer.<br />Clock 18432000Hz<br />Atmega644P<br /><br />[syntax=c]void Timer_init(void)<br />{<br />TIMSK1 |= (1&lt;&lt;OCIE1A);<br />TCCR1B |= (1&lt;&lt;WGM12); //CTC<br />TCCR1B |= (1&lt;&lt;CS12) | (1&lt;&lt;CS10); //1024<br />OCR1A = 1799;<br />}<br /><br />void tuneAntena (void)<br />{<br />int stop_count=0;<br />int target = 3125;<br />int bestdiff = 32767;<br />int currdiff = 0;<br />uint8_t bestTune = 0;<br />uint8_t currTune = 0;<br />// set lco_fdiv divider to 0, which translates to 16<br />// so we are looking for 31250Hz on irq pin<br />// and since we are counting for 100ms that translates to number 3125<br />// each capacitor changes second least significant digit<br />// using this timing so this is probably the best way to go<br />registerWrite(AS3935_LCO_FDIV,0);<br />registerWrite(AS3935_DISP_LCO,1);<br />// tuning is not linear, can't do any shortcuts here<br />// going over all built-in cap values and finding the best<br />   for (currTune = 0; currTune &lt;= 0x0F ; currTune++)<br />      {<br />registerWrite(AS3935_TUN_CAP,currTune);<br />         // wait to settle<br />         _delay_ms(10);<br /><br />         currentcount = 0;<br />         ms_flag=0;<br />         cli();<br />         currentcount = 0;<br />         ms_flag=0;<br />         Timer_init();<br />         sei();<br />         while (!ms_flag)<br />         {<br /><br />         }<br />         stop_count=currentcount;<br />        uart_putint(stop_count,10);<br />        uart_puts(&quot;\r\n&quot;);<br /> currdiff = target - stop_count;<br /> // don't look at me, abs() misbehaves<br /> if(currdiff &lt; 0)<br /> currdiff = -currdiff;<br /> if(bestdiff &gt; currdiff)<br /> {<br /> bestdiff = currdiff;<br /> bestTune = currTune;<br /> }<br />      }<br />   uart_puts(&quot;Best Tune:  \r\n&quot;);<br />   uart_putint(bestTune,10);<br />   uart_puts(&quot;\r\n&quot;);<br />   uart_puts(&quot;Best diff:  \r\n&quot;);<br />   uart_putint(bestdiff,10);<br />   uart_puts(&quot;\r\n&quot;);<br />registerWrite(AS3935_TUN_CAP,bestTune);<br />_delay_ms(2);<br />registerWrite(AS3935_DISP_LCO,0);<br />// and now do RCO calibration<br />powerUp();<br />// if error is over 109, we are outside allowed tuning range of +/-3.5%<br />}<br /><br />ISR (INT2_vect)<br />{<br />currentcount++;<br />}<br /><br />ISR(TIMER1_COMPA_vect) //obsluga przerwania (Timer/Counter1 Compare Match A)<br />{<br />ms_flag=1;<br />}[/syntax]<br /><br /><a href="https://obrazkiforum.atnel.pl/2479/c2ab0c0aa9047192eb5e8220a1adf48a.PNG"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/2479/c2ab0c0aa9047192eb5e8220a1adf48a.PNG" alt="Obrazek" /></a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2479">jaca_76</a> — 8 lip 2016, o 21:07</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jaca_76]]></name></author>
<updated>2016-07-07T23:15:31+01:00</updated>
<published>2016-07-07T23:15:31+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163626#p163626</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163626#p163626"/>
<title type="html"><![CDATA[Kalibracja AS3935]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15740&amp;p=163626#p163626"><![CDATA[
Witam<br />Wróciłem do projektu stacji meteo i obecnie pracuje nad dokończeniem kodu do AS3935 .<br />Przerobiłem kod z C++ i wykorzystałem przerwanie INT2 i delay do mierzenia częstotliwości.<br />Wynik powinien być w okolicy 3125 +/- 109 (impulsów w ciągu 100ms).<br />Jak widać otrzymuje większe wartości i się zastanawiam czy może wynika to z niedoskonałości kodu.<br />Czy można to lepiej zrobić?<br /><br />[syntax=c]uint8_t tuneAntena (void)<br />{<br />int target = 3125;<br />int bestdiff = 32767;<br />int currdiff = 0;<br />uint8_t bestTune = 0;<br />uint8_t currTune = 0;<br />// set lco_fdiv divider to 0, which translates to 16<br />// so we are looking for 31250Hz on irq pin<br />// and since we are counting for 100ms that translates to number 3125<br />// each capacitor changes second least significant digit<br />// using this timing so this is probably the best way to go<br />registerWrite(AS3935_LCO_FDIV,0);<br />registerWrite(AS3935_DISP_LCO,1);<br />// tuning is not linear, can't do any shortcuts here<br />// going over all built-in cap values and finding the best<br />   for (currTune = 0; currTune &lt;= 0x0F ; currTune++)<br />      {<br />registerWrite(AS3935_TUN_CAP,currTune);<br />         // wait to settle<br />         _delay_ms(10);<br />         currentcount = 0;<br />         _delay_ms(100);<br />        uart_putint(currentcount,10);<br />        uart_puts(&quot;\r\n&quot;);<br /> currdiff = target - currentcount;<br /><br /> // don't look at me, abs() misbehaves<br /> if(currdiff &lt; 0)<br /> currdiff = -currdiff;<br /> if(bestdiff &gt; currdiff)<br /> {<br /> bestdiff = currdiff;<br /> bestTune = currTune;<br /> }<br />      }<br />   uart_puts(&quot;Best Tune:  \r\n&quot;);<br />   uart_putint(bestTune,10);<br />   uart_puts(&quot;\r\n&quot;);<br />   uart_puts(&quot;Best diff:  \r\n&quot;);<br />   uart_putint(bestdiff,10);<br />   uart_puts(&quot;\r\n&quot;);<br />registerWrite(AS3935_TUN_CAP,bestTune);<br />_delay_ms(2);<br />registerWrite(AS3935_DISP_LCO,0);<br />// and now do RCO calibration<br />powerUp();<br />// if error is over 109, we are outside allowed tuning range of +/-3.5%<br />}<br /><br />ISR (INT2_vect)<br />{<br />currentcount++;<br />}[/syntax]<br /><br /><a href="https://obrazkiforum.atnel.pl/2479/a8fc91b364eb7cf5b4366e23f3b08984.PNG"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/2479/a8fc91b364eb7cf5b4366e23f3b08984.PNG" alt="Obrazek" /></a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2479">jaca_76</a> — 7 lip 2016, o 23:15</p><hr />
]]></content>
</entry>
</feed>