<?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=15652&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2016-06-24T07:09:41+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=15652&amp;mode</id>
<entry>
<author><name><![CDATA[matekogon]]></name></author>
<updated>2016-06-24T07:09:41+01:00</updated>
<published>2016-06-24T07:09:41+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15652&amp;p=162864#p162864</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15652&amp;p=162864#p162864"/>
<title type="html"><![CDATA[Re: Obsługa przerwania w bibliotece]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15652&amp;p=162864#p162864"><![CDATA[
Kolego oczywiście że się da Tworzysz plik np: timer.c i timer.h<br /><br />[syntax=c]plik timer.h<br /><br /><br />extern volatile  uint8_t flaga_1s<br /><br />void timer_init(void);[/syntax]<br /><br /><br /><br />natomiast w pliku timer.c<br /><br />[syntax=c]void timer_init(void){<br /><br />// inicjalizacja timera<br />}<br /><br /><br /><br /><br /><br />ISR(TIMER0_COMPA_vect){<br /><br />flaga_1s=1;<br /><br />}[/syntax]<br /><br /><br />Teraz jak będziesz gdzieś chciał skorzystać z timera to<br />np. plik main.c<br />[syntax=c]#include&quot;timer.h&quot;<br /><br /><br /><br />int main(void){<br /><br />timer_init()// inicjalizacja<br /><br /><br />while(1){<br /><br /><br />if(flaga_1s){<br /><br />// wykona się co 1s<br /><br />flaga_1s=0;<br /><br />}<br />}<br /><br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1380">matekogon</a> — 24 cze 2016, o 07:09</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jaca_76]]></name></author>
<updated>2016-06-23T22:17:19+01:00</updated>
<published>2016-06-23T22:17:19+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15652&amp;p=162859#p162859</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15652&amp;p=162859#p162859"/>
<title type="html"><![CDATA[Obsługa przerwania w bibliotece]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15652&amp;p=162859#p162859"><![CDATA[
Witam<br /><br />Przenoszę bibliotekę z arduino na AVR i mam problem z poniższym kodem, potrzebuję sprawdzić częstotliwość na nóżce .<br />Chciałem zrobić to w następujący sposób uruchomić timer a w pętli liczyć zmianę stanu na nóżce dopóki flaga nie zostanie ustawiona.<br />Flaga byłaby ustawiona w procedurze obsługi przerwania.<br /> Tylko że obsługa timera musiała by być poza main.c , czy jest to możliwe ?<br />[syntax=c]bool AS3935::calibrate()<br />{<br />int target = 3125, currentcount = 0, bestdiff = INT_MAX, currdiff = 0;<br />byte bestTune = 0, currTune = 0;<br />unsigned long setUpTime;<br />int currIrq, prevIrq;<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 />// let it settle<br />delay(2);<br />currentcount = 0;<br />prevIrq = digitalRead(_IRQPin);<br />setUpTime = millis() + 100;<br />while((long)(millis() - setUpTime) &lt; 0)<br />{<br />currIrq = digitalRead(_IRQPin);<br />if (currIrq &gt; prevIrq)<br />{<br />currentcount++;<br />}<br />prevIrq = currIrq;<br />}<br />currdiff = target - currentcount;<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 />registerWrite(AS3935_TUN_CAP,bestTune);<br />delay(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 />return bestdiff &gt; 109?false:true;<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2479">jaca_76</a> — 23 cze 2016, o 22:17</p><hr />
]]></content>
</entry>
</feed>